<div dir="ltr">Not sure if that's the best way to do it or if it's a good approach, but I have a trait which is applied to all result classes.<div><br></div><div><div>TraitFor::Result::ForceNULL;</div><div>use strict;</div><div>use warnings;</div><div><br></div><div>my $null = undef;</div><div><br></div><div>sub insert</div><div>{</div><div> my $self = shift;</div><div><br></div><div> for my $col ($self->columns) {</div><div> next unless defined $self->$col;</div><div> next unless $self->$col eq "";</div><div><br></div><div> my $info = $self->result_source->column_info($col);</div><div> $self->$col($null) if $info->{is_nullable};</div><div> }</div><div> return $self->next::method(@_);</div><div>}</div><div><br></div><div>sub update</div><div>{</div><div> my $self = shift;</div><div> my %to_update = $self->get_dirty_columns;</div><div><br></div><div> return $self->next::method(@_) unless keys %to_update;</div><div><br></div><div> for my $col (keys %to_update) {</div><div> next unless $to_update{$col} eq "";</div><div> my $info = $self->result_source->column_info($col);</div><div> $self->{_column_data}{$col} = $null if $info->{is_nullable};</div><div> }</div><div> return $self->next::method(@_);</div><div>}</div><div><br></div><div>1;</div></div><div><br></div><div>Best regards</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 2, 2017 at 5:14 PM, Rajesh Kumar Mallah <span dir="ltr"><<a href="mailto:mallah@redgrape.tech" target="_blank">mallah@redgrape.tech</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
By empty i mean string with length 0 ie ''<br>
<br>
__CODE__<br>
<br>
<br>
I am posting to rest endpoint Automagically generated via<br>
Catalyst::Controller::DBIC::<wbr>API there is no explicit code hand<br>
written by me.And that is why looking for a global filter.<br>
<br>
There are three great virtues of a programmer; Laziness, Impatience and<br>
Hubris -- Larry Wall.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
> Just curious: when you say "prefilled with nothing", you mean the field is<br>
> empty, or the field is filled with one or more white spaces (like " "), or<br>
> the field is a <select> with the first <option> having the attribute<br>
> "value" equals to ""? Or something else?<br>
><br>
> gil<br>
><br>
> On Thu, Mar 02, 2017 at 10:25:27AM -0500, Rajesh Kumar Mallah wrote:<br>
>><br>
>> Hi ,<br>
>><br>
>> I want to transform request parameters in GET & POST requests<br>
>> so that any thing which is empty (string) gets converted/replaced<br>
>> my perl's undef (and DBIC's NULL).<br>
>><br>
>> Why i need that:<br>
>> ====================<br>
>> I have edit form in my web app and some fields in the edit form<br>
>> are prefilled with nothing. On submission the DB raises an exception<br>
>> that an empty string is being inserted to a integer field.<br>
>><br>
>> Hence I feel like having a global filter that turns all blanks to<br>
>> undef.<br>
>><br>
>> The question is where to put this global filter.<br>
>><br>
>> Regds<br>
>> mallah.<br>
>><br>
>><br>
>><br>
>><br>
>> ______________________________<wbr>_________________<br>
>> List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
>> Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" rel="noreferrer" target="_blank">http://lists.scsys.co.uk/cgi-<wbr>bin/mailman/listinfo/catalyst</a><br>
>> Searchable archive:<br>
>> <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" rel="noreferrer" target="_blank">http://www.mail-archive.com/<wbr>catalyst@lists.scsys.co.uk/</a><br>
>> Dev site: <a href="http://dev.catalyst.perl.org/" rel="noreferrer" target="_blank">http://dev.catalyst.perl.org/</a><br>
><br>
> ______________________________<wbr>_________________<br>
> List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
> Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" rel="noreferrer" target="_blank">http://lists.scsys.co.uk/cgi-<wbr>bin/mailman/listinfo/catalyst</a><br>
> Searchable archive:<br>
> <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" rel="noreferrer" target="_blank">http://www.mail-archive.com/<wbr>catalyst@lists.scsys.co.uk/</a><br>
> Dev site: <a href="http://dev.catalyst.perl.org/" rel="noreferrer" target="_blank">http://dev.catalyst.perl.org/</a><br>
><br>
<br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" rel="noreferrer" target="_blank">http://lists.scsys.co.uk/cgi-<wbr>bin/mailman/listinfo/catalyst</a><br>
Searchable archive: <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" rel="noreferrer" target="_blank">http://www.mail-archive.com/<wbr>catalyst@lists.scsys.co.uk/</a><br>
Dev site: <a href="http://dev.catalyst.perl.org/" rel="noreferrer" target="_blank">http://dev.catalyst.perl.org/</a><br>
</div></div></blockquote></div><br></div>