[Dbix-class] Filtering module
jackal
me at jackal.in
Fri Oct 24 13:59:22 BST 2008
On Friday 24 October 2008 16:32:07 jackal wrote:
> There's example of using module with InflateColumn:
>
> package DB::Test;
> use URI;
> __PACKAGE__->inflate_column('homepage', {
> inflate => sub { URI->new($_[0]) },
> deflate => sub { shift->as_string }
> });
> __PACKAGE__->modify_column('homepage', {
> inflate => sub { $_[0] }, # as is
> deflate => sub { shift->canonical } # normalize
> });
>
> in a script:
>
> # it will be deflated into canonical version by ModifyColumn, then deflated
> into scalar by InflateColumn
> $r = $schema->resultset('Test')->create({homepage =>
> URI->new('HTTP://WWW.perl.com:80')}); # deflated into DB
> as 'http://www.perl.com/'
>
> # it will be inflated into URI object by InflateColumn, then it can be
> modified by ModifyColumn (vice-versa)
> $r->homepage->as_string; # inflated as 'http://www.perl.com/' (as is)
Above example demonstrates inflate/deflate, regardless of how you access the
data via DBIC. Todd Rinardo is right.
Ofcourse, you can do it without InflateColumn:
package DB::Test;
use URI;
__PACKAGE__->modify_column('homepage', {
inflate => sub { URI->new($_[0]) }, # inflate into URI object
deflate => sub { shift->canonical->as_string } # normalize and deflate
into scalar
});
TIMTOWTDI :)
But you can't do it without ModifyColumn.
--
Kind regards, Eugeny.
More information about the DBIx-Class
mailing list