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.
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.
Thanks,
Brian
_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/