[Catalyst] URL mapping relative to Controller name space.

Danijel Milicevic Danijel.Milicevic at rawmode.org
Sat Jul 30 09:22:42 CEST 2005


Hi Bill,

Am Freitag, den 29.07.2005, 21:07 -0700 schrieb Bill Moseley:
> I'm trying to write controllers that don't need to know where they are
> located.
> 
> I want a single controller to handle a number of tables (say, it's a
> general CRUD handler for a collection of tables) with paths like:
> 
>     http://localhost:3000/admin/crud/<table>/list
>     http://localhost:3000/admin/crud/<table>/edit/<id>
>     http://localhost:3000/admin/crud/<table>/do_edit/<id>
> 
> I'd like the code in the controller to be relocatable -- that is, if I
> move it to a new location in (in URL space) the code doesn't need to
> be updated.  I like using "Local" actions in general, but seems that's
> not a good choice in this case due to the <table> variable before the
> action.

Sounds to me like a perfect example to use a a Regex action. Write a
proper Regex, something better than this:

sub match : Regex('([^/]*)/([^/]*)$') {
    my ( $self, $c ) = @_;
    my ( $table, $action ) = $c->req->snippets;
    ...
}

This should work as long as you have always a tablename as well as an
action in your path. Better solution would probably be using a keyword
(like you do with crud?) and match the tablename and action after the
occurance of your keyword.

Regards,
Danijel Milicevic




More information about the Catalyst mailing list