[Dbix-class] in- and deflators

Bernhard Graf dbic at augensalat.de
Thu Mar 2 21:45:13 CET 2006


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.
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).
-- 
Bernhard Graf



More information about the Dbix-class mailing list