[Dbix-class] CDBI Compatability Issue: Iterators
Christopher H. Laco
claco at chrislaco.com
Fri Aug 19 16:46:41 CEST 2005
Last week, with a little prodding and help from Matt, I tried converting
Handel from CDBI to the CDBICompat layer in DBIC. After some hurdles
with has_a syntax (assumptions based on the presence or absence of
inflate), it all worked except for iterators.
In CDBI, you can specify the ->iterator_class to be used, which I have
set to Handel::Iterator; which in turn does a use base
'Class::DBI::Iterator'.
Matt suggested that have my Iterator subclass DBIx::Class::Resultset.
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.
This is different from Class::DBI::Iterator; whos next method calls
$self->class->construct($use)
So, how do we fix this? can _row_to_object have and extra paramater
specifying the constructore method?
sub _row_to_object {
my ($class, $cols, $row, $constructor) = @_;
my %vals;
$vals{$cols->[$_]} = $row->[$_] for 0 .. $#$cols;
my $new = $class->$constructor(\%vals);
$new->in_storage(1);
return $new;
}
Then the compat layer when loaded gets the Resultsets->next to do the
right thing?
Thanks,
-=Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3178 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20050819/8befdb00/smime.bin
More information about the Dbix-class
mailing list