[Catalyst] List/Scalar Context with TT + DBIC

Christopher H. Laco claco at chrislaco.com
Thu Jun 1 14:43:21 CEST 2006


Mark Blythe wrote:
> Thanks for the suggestion, but unfortunately it didn't work.  The
> behavior didn't change at all with the added "cache => 1" attribute.
> Here's the simple test template:
> 
> [% SET results = c.model('DB::Foo').search({ col => $value }, { cache =>
> 1 }) %]
> 
> [% results %]
> 
> This yields:
> 
> ARRAY(0x355f004)
> 
> Indeed, it's an array that I can then loop through and access the
> rows.  I guess I'll have to write some non-template perl code
> somewhere to solve this -- or wait for the search_rs method that
> phaylon mentioned.
> 

Just to illustrate this problem in another way, here's one of the Handel
TT plugins:

http://handelframework.com/source/branches/DBIC-1.0/lib/Template/Plugin/Handel/Cart.pm

Specifically, this method:

> sub items {
>     my ($self, $filter) = @_;
>     my $iterator = $self->SUPER::items($filter);
>     my $count = $iterator->count;
> 
>     return $iterator;
> };

If I comment out the my $count line, TT turns what it sees into an
ARRAYREF. With the count line in, it gets the iterator as expected.

In fact, even something like warn $iterator triggers TT to do the right
thing.

I don't think this is DBICs problem really, but I'm more curious as to
what is really going in in this situation.

-=Chris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060601/7f821352/attachment.pgp 


More information about the Catalyst mailing list