[Catalyst] Re: Subsessions?

John Napiorkowski jjn1056 at yahoo.com
Thu Oct 4 13:18:10 GMT 2007


--- Rainer Clasen <bj at zuto.de> wrote:

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

Since we need to keep this working for backwards
compatibility, it might be easier to create an object
that overloads array/hash context to automatically do
what you want.  But that would certainly add overhead
and I haven't had my coffee this morning yet, so I'm
not sure about that idea.

>  
> 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
> 
Hi,

I don't think it's a bad idea, just we'd need to
figure out how to make it play nice with actions using
'regular' array based captures since you might have a
mix of the two.  

BTW, it's easy to add custom subroutine attributes in
order to make some things nicer in your code.  There's
a good example of this at:
http://use.perl.org/~LTjake/journal/31738 (which BTW
shows how to set your action attributes in
configuration, which can make things even more clean)

--john


      ____________________________________________________________________________________
Catch up on fall's hot new shows on Yahoo! TV. Watch previews, get listings, and more!
http://tv.yahoo.com/collections/3658 



More information about the Catalyst mailing list