[Dbix-class] CDBI Compatability Issue: Iterators

Matt S Trout dbix-class at trout.me.uk
Fri Aug 19 22:42:11 CEST 2005


On Fri, Aug 19, 2005 at 03:43:54PM -0400, Christopher H. Laco wrote:
> Matt S Trout wrote:
> >On Fri, Aug 19, 2005 at 10:46:41AM -0400, Christopher H. Laco wrote:
> >
> >>That also worked but brought up another problem.
> >>
> >>DBIx::Class::Resultset->next calls
> >>DBIx::Class::Row->_row_to_object($self->{cols}, \@row)
> >>
> >>DBIx::Class::Row->_row_to_object calls
> >>$class->new(\%vals) on the child object class to be created, which in my 
> >>case has it's own custom ->new() method.
> >
> >
> >The thing being, ->create calls ->new so unless your ->new is compatible
> >you're still going to have problems.
> >
> >
> >>This is different from Class::DBI::Iterator; whos next method calls 
> >>$self->class->construct($use)
> >
> >
> >Yep. I should really add a "sub construct { shift->new(@_); }" to emulate
> >this.
> > 
> >
> >>So, how do we fix this? can _row_to_object have and extra paramater 
> >>specifying the constructore method?
> >
> >
> >Providing a single constructor method with the standard name for said
> >is critical to allow people to override/tweak/whatever object construction
> >in a standard way. Your problem as I see it is that Class::DBI behaves
> >non-standardly in terms of object construction and you've mistakenly 
> >assumed
> >whatever other libraries you use will make the same design error :)
> >
> 
> I'll freely admit that I may be doing something strange with respect to 
> new vs construct. With that said, and with a deign error in CDBI or not, 
> the CDBICompat layer needs to be just that: compatable.
> 
> Even if I didn't have a new() in my child class, CDBIs iterator still 
> calls construct; and thus the CDBICompat layer should do the same IMHO. 
> Otherwise, what's the point of a compatibility layer if it isn't 
> compatable to whatever bad choice its target may have made?

As I say, I think making construct alias to new for the compatibility
layer is a good idea.

However the primary DBIx-Class constructor should still be new(), and
"doesn't have a new" isn't a Class::DBI feature; it's merely a factor of
how Class::DBI implements its features - otherwise reductio ad absurdum
would say that we shouldn't use any method name not in Class::DBI in case
somebody uses that in their subclass :)

-- 
     Matt S Trout           Website: http://www.shadowcatsystems.co.uk
  Technical Director        E-mail:  mst (at) shadowcatsystems.co.uk
Shadowcat Systems Ltd.

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



More information about the Dbix-class mailing list