[Catalyst] url parsing and sub controller

Danijel Milicevic Danijel.Milicevic at rawmode.org
Tue Sep 6 07:48:28 CEST 2005

Hi Allen,

First off: sorry for my weird first reply - I could barely understand it
myself after reading it this morning. I blame the tequila and will
supply .diff's in the future if this happens again. ;)

Am Montag, den 05.09.2005, 17:54 -0400 schrieb Allen S. Rout:
> Would it be appropriate to do this in an auto() ? 
> I'm thinking it'd be nice to shove as much of this kind of housekeeping work up
> to the application as possible. 
> Alternately one could
> package MyApp;
> sub Process_Args: Global { ... }

Best practice tells me that you should keep MyApp.pm as simple as
possible - no public (Local/Global/Path/Regex) actions in MyApp.pm.
There are a couple of reasons for this beside the obvious ones
(controller logic belongs to controllers, MVC), but the most important
one to me is, that it's not reusable. We got controller inheritance so
keeping a good MVC-like seperation also gives you the benefit of (more
or less) independent and reuseable controller-code.

> and then explicitly 
> package MyApp::C::Page
> sub default: private 
>  {
>     my ( $self, $c ) = @_;
>     $c->Process_Args($c);
>     [...]
>  }
> or some similar pattern.
> I'm currently working with the latter.  My itch of the instant is that I wish
> I could tell Process_Args that it gets run All The Time at the MyApp level.

"tell Process_Args that it gets run All The Time at the MyApp level",
I'm not too sure what you mean by "MyApp level", but that sounds pretty
much like auto() to me from a control flow POV. So the code would look

package MyApp;

sub default : Private {
   my ( $self, $c, $arg ) = @_;
   $c->forward('page/foo', [qw/$arg/]);

sub auto : Private { ... } # processing you want on *every* request


package MyApp::C::Page;

sub default : Private { ... }

sub foo : Local {
    my ( $self, $c ) = @_;
    my $arg = $c->req->args->[0]; 

> Of course, it's entirely possible that there's a defined and documented method
> to do this, so a whack with a cluestick won't offend.

Since I'm not sure if I even answered your question, there won't be any
whacking with a stick, just some pointers to a direction:

- Intro.pod#FlowControl
- Cookbook.pod#Forwarding with args

Danijel "gabb" Milicevic

More information about the Catalyst mailing list