[Catalyst] Cascading action dispatching
Ash Berlin
ash_cpan at firemirror.com
Sun Oct 21 15:39:52 GMT 2007
Matthew Pitts wrote:
> On Fri, 2007-10-19 at 17:16 -0400, Matthew Pitts wrote:
>> I'm trying to figure out a way to have my Cat app dispatch in a way
>> that
>> would allow multiple actions in the same namespace and have them
>> called
>> in succession until one of them actually handles the request.
>>
>> I have a client that really likes base-level URLs, like
>> "/shoppingmallxyz", and wants to use them for landing pages that are
>> functionally different. In some of these cases the base-level URL
>> paths
>> are really just monikers for things that are retrieved from the DB and
>> if it exists, then a page is rendered.
>
> I guess another, maybe more elegant, way to accomplish this same effect
> would be to override register_actions in the Controllers where I want to
> do this and have a call to a register_dynamic_actions method like so:
>
> package MyApp::Controller::Center;
>
> sub register_actions {
> my $self = shift;
> my ( $c ) = @_;
>
> $self->register_dynamic_actions($c);
>
> return $self->SUPER::register_actions(@_); # or NEXT?
> }
>
> sub register_dynamic_actions {
> my $self = shift;
> my ( $c ) = @_;
>
> my $centers = $c->model('Center')->all;
>
> while ( my $center = $centers->next ) {
> my $action = $self->create_action(...);
> $c->dispatcher->register($c, $action);
> }
> }
>
> 1;
>
> An obvious side-effect (AFAIK) of doing it this way is that the app has
> to be restarted for new dynamic actions to take affect. The benefit,
> however, is that the root-level pseudo-actions I was trying to achieve
> with on-the-fly DB lookups are now first class actions and would not
> require a DB call on each request.
>
> I may be crazy... anybody got any thoughts on this?
>
Have you looked at Chained actions?
They will give you dispatch trees like
/foo/*/bar
(Where * is any non '/' character)
http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7011/lib/Catalyst/DispatchType/Chained.pm#USAGE
>From a quick skim of you message, it sounds like Chained actions will do
what you want.
More information about the Catalyst
mailing list