[Catalyst] Accessing action URIs outside of Catalyst app
Matt S Trout
dbix-class at trout.me.uk
Mon Jan 8 17:46:43 GMT 2007
On 8 Jan 2007, at 16:59, Brian Kirkbride wrote:
> 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.
Explain "can't" in a form that doesn't make me feel you've just
completely missed the point of "achieve" and told me what you're
trying (failing) to implement :)
>
> 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?
Yeah, Catalyst already has an implementation for this -
package MyApp::Controller::Foo;
...
sub cancel :Action :Args(1) { ... }
then in myapp.conf
<Controller Foo>
<Action cancel>
Path /cancel
</Action>
</Controller>
You can apply any attribute like that, although setting Args or
similar from the config file might be considered unwise.
--
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for
details.
+ Help us build a better perl ORM: http://dbix-
class.shadowcatsystems.co.uk/ +
More information about the Catalyst
mailing list