[Catalyst] Just a hint on using Roles

Ovid publiustemp-catalyst at yahoo.com
Tue Jul 14 10:46:28 GMT 2009


----- Original Message ----
> From: Ian Docherty <catalyst at iandocherty.com>
>
> Hi
> I am looking at creating a generic Breadcrumb module to use with Catalyst. The 
> basic idea being that some controllers will 'reset' a breadcrumb path back to 
> the start (for example when clicking on a main menu) and some controllers will 
> append to the existing breadcrumb.
> 
> e.g.
> Main menu item linking to /users will display a list of all users (reset 
> breadcrumb)
> 
> Clicking on a link on that page to go to /user/123 will append the new URI to 
> the breadcrumb, /user/123/edit appends again. etc.
> 
> I would then be able to create a BreadCrumb Role that could be used with some of 
> my controllers to maintain a breadcrumb structure on the stash that could then 
> be used in my templates?
> 
> ISTM that this is an ideal application of Roles? I would welcome comments if 
> this is a sensible approach and I can research the details further myself.

Tough to be really certain without seeing the actual app, but yeah, this sounds sensible.  Roles are for shared behavior and your reasoning seems solid.  Some people, though, argue that roles should not deal with state, only behavior.  Thus, delegation would be a preferred option.  I've never been entirely convinced by the stateless argument, though.

 
Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://use.perl.org/~Ovid/journal/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



More information about the Catalyst mailing list