[Catalyst] Accessing action URIs outside of Catalyst app
Brian Kirkbride
brian.kirkbride at deeperbydesign.com
Mon Jan 8 16:59:54 GMT 2007
Matt S Trout wrote:
>
> On 3 Jan 2007, at 20:21, Brian Kirkbride wrote:
>
>> Hello all,
>>
>> Is there a best practice way to maintain a map of URLs used in a
>> Catalyst application. To clarify, I need to map actions to URLs
>> outside of Catalyst (CRON jobs, Emailers, etc) and won't have access
>> to $c->uri_for or the $c->dispatcher.
>
> If you need to do this, your design is broken.
Perhaps, but I ascribe that to it being in transition :)
>
> Step back. Explain what you're trying to achieve.
Automated emails sent out to users need to provide them with a list of different
webapp URLs. These actions are asynchronous from the webapp itself. I have a
number of scripts (a few are legacy dinosaurs) that need webapp URLs as well.
If I choose to change /cancel to /account/cancel later on, I'd like to do it in
one place. I realize that without parsing the controllers' actions I can't
expect the outside code to get those URLs. I would also rather not "use
MyApp.pm" in simple scripts that only need my model logic and a URL, and in some
cases I can't.
My hope was to configure the URL mapping in a config file, which could be
accessed by my webapp and outside scripts. Something like this:
sub cancel : Args(1) : Path($urlmap->{account_cancel}) {
# action
}
This, of course, does not work because attributes do not evaluate their
arguments. Perhaps my solution is to subclass the Dispatcher to allow for:
sub cancel : Args(1) : FromURLMap('account_cancel') {
# action
}
That wouldn't be too hard. Thoughts?
Best,
Brian
More information about the Catalyst
mailing list