[Catalyst] Quesion about Chaining usage

John Napiorkowski jjn1056 at yahoo.com
Tue Sep 5 16:03:21 CEST 2006


Another thing great about using this chaining is that
it plays really nice with DBIx.  I can create a base
resultset and then keep adding conditions down through
the chain until the endpoint before running a query. 
So it makes the controller code look quite nice and
very modular, not too much repeating myelf.

You can do this sort of with forwarding, but it's hard
to do something like (forgive this psuedocode)

sub members :Chained 
{
   my $members :Stashed = $c->model;
]

sub all_members :Chained('members') PathPart('all')
{
   ## just forward to the template
}

sub new_members :Chained('members') PathPart('new')
{
  ## add a condtion to the $members resultset to
  ## sort by membership date and only return the top
  ## ten newest entries.  Then just forward on like
  ## all_members (can even use the same template
}

Without a bunch of redundant code.  At least I can't
think of one.  This way I think it is easier for the
programmer to follow later on.

--john


--- Matt S Trout <dbix-class at trout.me.uk> wrote:

> Lee Standen wrote:
> > I've been out of Cat development for a while, so
> take this with a grain 
> > of salt.
> > 
> > I always found you could do that by doing
> something like:
> > 
> > myapp/C/Feedrolls.pm:
> > 
> > sub default : Private {
> >     my ($self,$c) = @_;
> >    
> >     my($feedroll_id,$feed_id, at others) =
> @{$c->req->args};
> > }
> > 
> > Then you can do whatever you need to do with them.
> 
> Sure. But it's ugly, fragile, and you'll eventually
> end up with half an 
> implementation of Chained hacked-up as a one-off for
> each of a dozen apps.
> 
> Which is what I ended up with, so I gave up and
> wrote Chained to save me the 
> trouble ;)
> 
> -- 
>       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: Catalyst at lists.rawmode.org
> Listinfo:
> http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Catalyst mailing list