[Catalyst] Controller methods

Will Hawes info at whawes.co.uk
Tue Jan 17 09:53:25 CET 2006


Matt S Trout wrote:
> On Mon, Jan 16, 2006 at 09:36:31PM +0000, Will Hawes wrote:
>> I tracked down an error in my code today that was caused by accidentally 
>> returning an objectref (a DBIx::Class::ResultSet, but the type is 
>> probably unimportant) from one of my controller methods. The offending 
>> code was something along the lines of
>>
>> sub myaction : Local {
>>   ...
>>   $self->fetch_objects( $c );
>>   # return 1; # <- this fixed it..
>> }
>>
>> where fetch_objects() is the action I use to run all my CDBI/DBIC searches.
>>
>> First, what are valid things to return for a controller action? IMO it 
>> would be very useful if Catalyst could warn()/die() if it gets something 
>> unexpected. This type of error would become much easier to debug.
> 
> Arbitrary things should normally be acceptable return values so that they
> can be returned by ->forward.

Does this mean completely arbitrary things, or just Catalyst components 
(which could be checked for)? Sorry if that's a dumb question but I'm 
trying to think of other types of object that are used with forward().

> 
>> Second, despite having used Carp::confess() to get an idea, I'm still a 
>> bit unclear about exactly what was happening to the 
>> DBIx::Class::ResultSet returned by my action. Its count() method seemed 
>> to be getting called from inside Catalyst. But why???
> 
> As I explained on IRC, Catalyst does a numeric test on the return value
> (normally used for short-circuits in auto etc.) which causes the resultset
> to be numified, which is overloaded to return the count().
> 

Ah, ok. I missed your IRC reply (lost my connection), thanks for repeating.



More information about the Catalyst mailing list