[Dbix-class] CDBICompat sth_to_objects
Dave Howorth
dhoworth at mrc-lmb.cam.ac.uk
Mon Nov 17 15:41:04 GMT 2008
The implementation of sth_to_objects in DBIx/Class/CDBICompat/ImaDBI.pm
doesn't seem to be fully compatible with that in Class/DBI.pm
Specifically, the method in Class::DBI is context aware and returns an
iterator in scalar context. The CDBICompat version isn't context aware
and so returns a row count!
I see there is DBIx::Class::CDBICompat::Iterator which says "See
DBIx::Class::CDBICompat for directions for use" but I can see no mention
of the word "iterator" in the DBIx::Class::CDBICompat POD. So I don't
know whether CLass::DBI's array vs iterator feature is supposed to work
in CDBICompat or not. If it isn't, it should die rather than return
faulty data, IMHO.
Cheers, Dave
PS OT but I'm also confused by this code in Class::DBI
sub _ids_to_objects {
my ($class, $data) = @_;
return $#$data + 1 unless defined wantarray;
return map $class->construct($_), @$data if wantarray;
return $class->_my_iterator->new($class => $data);
}
I think 'defined wantarray' only returns undefined in void context, so I
don't understand why it's returning the record count?
More information about the DBIx-Class
mailing list