Nilson Santos Figueiredo Junior wrote:
Lately I've been using chained actions a lot, since it ends up making
everything look cleaner and more organized.

I tend to structure things in a way that I've got some Catalyst
actions that load some items from the database   which are the root of
the chain and then I've got another set of Catalyst actions that
actually do things with those loaded items (e.g. /item/12/view,
/item/12/edit, and so on).

Sometimes, those items also have subitems and those might even have
another set of subitems. In these cases, when using Catalyst and
DBIx::Class it can be useful to prefetch stuff for performance
reasons. But, using my setup it's not currently possible to do that,
so I end up issuing lots of queries to the database since the initial
root item didn't prefetch anything, because it couldn't know in
advance what would be needed by the chained actions.

Most of the item loading code I've previously mentioned looks like
this (simplified):

 sub load : Chained('/item') PathPart('') CaptureArgs(1) {
   my ($self, $c, $id) = @_;
     my $pre = $c->stash->{prefetches} = {};
$c->stash->{item} = Scalar::Defer::lazy { $c->model('DB')->search(undef, $pre)->find($id) };
 }

:)

--
     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/ +

_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to