[Catalyst] Controller methods

Matt S Trout dbix-class at trout.me.uk
Mon Jan 16 23:35:05 CET 2006


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.

> 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().

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list