[Catalyst] URL mapping relative to Controller name space.
samwyse
samwyse at gmail.com
Sun Jul 31 17:52:43 CEST 2005
On 7/30/05, Bill Moseley <moseley at hank.org> wrote:
> On Sat, Jul 30, 2005 at 01:46:05PM -0400, David Storrs wrote:
> > Would this do what you want? (untested):
> >
> > package App::C::<WHATEVER>;
> >
> > sub table_dispatcher : Regex('^admin/crud/([\w/]*)') {
>
> Yes and no. Maybe I'm stuck on thinking about Local too much.
> But, your example is kind of what I was trying to avoid -- having code
> inside the controller know anything about where it's located.
>
> I'm trying to write a controller that's based on where it's placed in
> the lib/App/C hierarchy and doesn't require any changes to the
> controller if it's moved.
>
> mv C/Admin/Crud.pm C/Other/Foo/Bar/Bla.pm
>
> and now the URLs been remapped. (Except the "package" needs to be
> updated -- too bad that's even needed as we can infer the package name
> from where the file is located.)
>
> "Local" actions solve this, although then I've got an extra path
> segment that doesn't convey any information. Well, that's not true if
> I move to the common method of listing the actions before the table
> name.
>
> I guess I'll just have to conform. ;)
This is untested, but have you tried something like this:
package App::C::<WHATEVER>;
sub table_dispatcher : Regex('/crud/([\w/]*)') {
Although Manual::Intro says that you need to anchor the regex to the
start of the path, I suspect that it's "more what you'd call
guidelines than actual rules." In this case, the '/crud/' servers to
anchor the regex to a relative location. And if for some strange
reason it doesn't seem to work, then try this:
package App::C::<WHATEVER>;
sub table_dispatcher : Regex('^.*/crud/([\w/]*)') {
More information about the Catalyst
mailing list