[Catalyst] Re: Subsessions?

Rainer Clasen bj at zuto.de
Thu Oct 4 12:32:16 GMT 2007


Matt S Trout wrote:
> On Wed, Oct 03, 2007 at 11:10:50AM +0200, Rainer Clasen wrote:
> > With the input from the list I've ditched the Subsessions and went for
> > Chained because it seems to be the "RightThing" - although Subsessions are
> > a quite comfortable solution: Once setup, they're available everywhere
> > within the application, no need to worry anymore. 
> > 
> > That's quite the opposite of Chained. Nearly all URIs in this project look
> > like /<athlete>/diary/list or /<athlete>/exercise/add. This means all
> > actions have to be setup for chaining manually, CaptureArgs have to be
> > verified on each request, uri_for becomes a hassle to use and last but not
> > least the chance to break the natural URI to Controller namespace mapping
> > is quite likely.
> 
> Not sure I understand "setup for chaining manually".

With Chaining you have to specify where you actually chain to (even if
it's "."). With ":Local" you automgagically end up in the current
namespace, no need to bother making "." available.

> CaptureArgs you verify further up your chain, in a common method that just
> handles the <athlete> bit.

Correct, but it still has to be verified on each Request as it comes from
the user and cannot be trusted (in contrast do what the server keeps in
the session data).

> uri_for($action_object, \@captures, @args
> 
> continues to work perfectly (it supports regex as well, even)

Of course it keeps working. But specifying the right @captures at each and
every place you use uri_for *IS* more hassle than overloading uri_for to
automagically include the subsession ID as query parameter once.

Well, all of these "issues" are by design - and of course they are far
away from show-stoppers. But as Catalyst is the "free choice" MVC
Framework, I was just wondering if there are alternatives. Actually I was
puzzled to see how easy I could implement subsessions on my own (what I
didn't plan to do).


BTW: Right now I'm wondering if one couldn't make uri_for easier to use if
one could pass a hash instead of @captures. An acction attribute could
specify which keys from this hash should be used. This would make changes
to the code / URI layout a lot more flexible and simplifies deriving URIs
from the current one.
 
action declaration:

 sub foo :Chained('.') :NCaptureArgs(year,month,day) {}

uri construction:

 $cap = $c->req->ncaptures; # or something similar stored in stash
 $cap->{day}++;
 uri_for( $foo_action_object, $cap, @args);

This is just an Idea. I don't actually expect you to like/comment/...
this.  :)


Rainer

-- 
KeyID=759975BD fingerprint=887A 4BE3 6AB7 EE3C 4AE0  B0E1 0556 E25A 7599 75BD



More information about the Catalyst mailing list