[Catalyst] iterating ResultSet in controller vs. template

Daniel Hulme st at istic.org
Tue Jun 19 20:28:48 GMT 2007


On Tue, Jun 19, 2007 at 03:09:29PM -0400, John Goulah wrote:
> You are correct (and I did explain that as well in my original post that was
> happening).  So the question is , how can I make the same call and access
> the data in both places?  It seems silly that I have to make the call
> without brackets to access in the controller, and with brackets to access in
> the template, so I assume I am accessing the object incorrectly in one place
> or the other, but I would like to be able to use ->next in the controller.

You don't get both the iteratorish and the arrayish behaviour. If you
call it in list context, you get a list, and you can iterate over it
using FOREACH in your template and `for my $alumnus (@$alumni)` in your
Perl code. If you call it in scalar context, you get an iterator, and
you can iterate over it by calling $alumnus->next in your controller and
alumnus.next in your template. If you really want it both ways, the
obvious way is to call the thing twice, once in scalar context and once
in list context, and only put one of them in the stash. Or you could
call it in scalar context and when you iterate over the results in your
controller add them to a list as well and put the arrayref in the stash.
There may be a proper way to convert an iteratorish result into a list:
I suspect the people on the DBIx::Class mailing list would know.

-- 
"Oh, Eeyore, you are wet!" said Piglet, feeling him.
Eeyore shook himself,  and asked somebody to explain to Piglet what hap-
pened when you had been inside a river for a long time.
    A. A. Milne, 'The House at Pooh Corner'    http://surreal.istic.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070619/6c08af0e/attachment.pgp


More information about the Catalyst mailing list