[Catalyst] Accessing action URIs outside of Catalyst app
Matt S Trout
dbix-class at trout.me.uk
Mon Jan 8 19:11:52 GMT 2007
On 8 Jan 2007, at 18:12, Brian Kirkbride wrote:
> Matt S Trout wrote:
>> 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 :)
>
> I'd like to routinely send an email to a user telling them to pay
> for something, including a link to a page in my webapp allowing
> them to do so.
I just use Catalyst::Engine::JobQueue::POE (or in older apps a script
that's the moral equivalent) and uri_for for that.
>
>>>
>>> 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.
>
> Perfect, I had missed that this type of URL to action mapping was
> possible with the :Action attribute. I have no interest in placing
> Args or other attributes in the config. This should work fine for me.
:Action isn't -required-, you just need at least one
attribute. :Action is the long-standing traditional no-op attribute
(:Private isn't valid with any other attrs) so I tend to add it to
all of them so if I delete the :Args for whatever reason or don't
have one in the first place things don't go batshit on me :)
--
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