[Dbix-class] Default values

Matt S Trout dbix-class at trout.me.uk
Tue May 8 01:05:07 GMT 2007


On Mon, Apr 30, 2007 at 05:05:00PM -0400, Dan Boger wrote:
>     sub new {
>       my ($self, $attrs) = @_;

WRONG!

        my ($class, $attrs) = @_;

It's not an object yet, it's a class. always say $class in constructor,
because ...

> 
>       $attrs->{unixtime} = time if not $attrs->{unixtime} or $attrs->{unixtime} =~ /\D/;
>       $attrs->{date} = sprintf("%04d-%02d-%02d", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3])
>         unless $attrs->{date} and $attrs->{date} =~ /^\d\d\d\d-\d\d-\d\d$/;
> 
>       $self->next::method($attrs);

Then you won't forget to make this line

        my $self = $class->next::method($attrs);

:)
 
>       return $self;
>     }

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
Shadowcat Systems Ltd.   Contact mst (at) shadowcatsystems.co.uk for a quote
                                          http://www.shadowcatsystems.co.uk/ 



More information about the Dbix-class mailing list