<div dir="ltr">It's just a package and I have in <a href="http://make_schema_at.pl">make_schema_at.pl</a> to apply the components that I want to use:<div><br></div><div><div> make_schema_at(</div><div> "My::Schema::${class_name}",</div><div> {</div><div> exclude => qr/_\d+$/,</div><div> dump_directory => "$Bin/../lib",</div><div> components => [ '+My::TraitFor::Result::ForceNULL', '+My::TraitFor::Result::AuditLog' ],</div><div> schema_components => [ 'Schema::RestrictWithObject' ],</div><div> qualify_objects => 1, # prepend dpl/public in the __PACKAGE__->table(...) call<br></div><div> db_schema => $schema,</div></div><div> }</div><div> );</div><div><br></div><div>Cheers</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 3, 2017 at 1:34 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>
<br>
Thanks for that , it looks elegant .<br>
<br>
Could you please send some pointer to docs for Traits<br>
approach.<br>
<br>
regds<br>
<span class="HOEnZb"><font color="#888888">mallah.<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
> Not sure if that's the best way to do it or if it's a good approach, but I<br>
> have a trait which is applied to all result classes.<br>
><br>
> TraitFor::Result::ForceNULL;<br>
> use strict;<br>
> use warnings;<br>
><br>
> my $null = undef;<br>
><br>
> sub insert<br>
> {<br>
> my $self = shift;<br>
><br>
> for my $col ($self->columns) {<br>
> next unless defined $self->$col;<br>
> next unless $self->$col eq "";<br>
><br>
> my $info = $self->result_source->column_<wbr>info($col);<br>
> $self->$col($null) if $info->{is_nullable};<br>
> }<br>
> return $self->next::method(@_);<br>
> }<br>
><br>
> sub update<br>
> {<br>
> my $self = shift;<br>
> my %to_update = $self->get_dirty_columns;<br>
><br>
> return $self->next::method(@_) unless keys %to_update;<br>
><br>
> for my $col (keys %to_update) {<br>
> next unless $to_update{$col} eq "";<br>
> my $info = $self->result_source->column_<wbr>info($col);<br>
> $self->{_column_data}{$col} = $null if $info->{is_nullable};<br>
> }<br>
> return $self->next::method(@_);<br>
> }<br>
><br>
> 1;<br>
><br>
> Best regards<br>
><br>
> On Thu, Mar 2, 2017 at 5:14 PM, Rajesh Kumar Mallah <mallah@redgrape.tech><br>
> wrote:<br>
><br>
>><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>
>><br>
>><br>
>><br>
>> > Just curious: when you say "prefilled with nothing", you mean the<br>
>> field<br>
>> is<br>
>> > empty, or the field is filled with one or more white spaces (like "<br>
>> "),<br>
>> 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/" rel="noreferrer" target="_blank">http://www.mail-archive.com/</a><br>
>> <a href="http://catalyst@lists.scsys.co.uk/" rel="noreferrer" target="_blank">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>