[Dbix-class] in- and deflators

Matt S Trout dbix-class at trout.me.uk
Fri Mar 3 00:05:27 CET 2006


On Thu, Mar 02, 2006 at 09:45:13PM +0100, Bernhard Graf wrote:
> Matt S Trout wrote:
> 
> > On Thu, Mar 02, 2006 at 08:54:26PM +0100, Bernhard Graf wrote:
> > > One more question:
> > >
> > > It looks like in- and deflators are only called it the column value
> > > is defined.
> > >
> > > Is this intended?
> >
> > Yes. undef indicates an SQL NULL, so this behaviour is the most
> > logical in context.
> 
> Not agreed! Perl's undef is translated into NULL as a convention, that 
> one might want to change.
> undef is regarded as false in Perl.

Since inflate/deflate always produces/accepts an object, an undefined value
on set wouldn't be expected to produce anything except undef IMO.

> You might want to deflate any false value to something other than NULL, 
> e.g.:
> (My)SQL:
>    visible enum('N','Y') NOT NULL default 'Y'
> 
> Perl:
>   __PACKAGE__->inflate_column('visible', {
>     inflate => sub { shift eq 'Y' },		# inflate enum to boolean
>     deflate => sub { shift() ? 'Y' : 'N' },	# deflate boolean to enum
>   };
> 
>   $table->visible(undef);
> 
> will set visible='Y' (because it is declared as default in SQL).

Won't work since it needs to be an object. There's been some discussion on
IRC today about adding a FilterColumn component, but this isn't the way
InflateColumn works and is never going to be - you're expecting it to be
something that it simply conceptually isn't.

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list