[Catalyst] Access Catalyst context object from script

Alexander Hartmaier alexander.hartmaier at t-systems.at
Wed Oct 31 12:46:03 GMT 2012


On 2012-10-31 13:30, Anthony Gladdish wrote:
>> -----Original Message-----
>> From: Ian Docherty [mailto:catalyst at iandocherty.com]
>> Sent: 31 October 2012 11:29
>> To: The elegant MVC web framework
>> Subject: Re: [Catalyst] Access Catalyst context object from script
>>
>> On 31 October 2012 10:41, Anthony Gladdish
>> <anthony.gladdish at newcastle.ac.uk> wrote:
>>> Hi,
>>>
>>> Got a lot of code in a controller that should be moved out and
>> into an external script (that's called by a cronjob) which calls
>> stuff from the Model and then emails it.
>>> The script can access the model fine and re-use a
>> Template::Toolkit template already written fine (I'm using
>> MIME::Lite::TT). However, in the template itself there's a lot of
>> calls to the Catalyst context object, in the form of:
>>>         [% Catalyst.uri_for( ... ) %]
>>>
>>> ... which aren't displaying anything. I don't really want to hard
>> code the URIs, so is there a way to get access to the Catalyst
>> context object of a running app, in a separate external script?
>> I can understand the reluctance to hard-code URIs, however i
>> would be
>> reluctant to suggest that you bring in the whole of Catalyst just
>> to
>> satisfy this one requirement.
>>
>> What is the template? I presume it is an email, and that you are
>> putting links to locations within your Catalyst application into the
>> email?
> Correct. It's a bog standard .tt file printing text to be sent as an email,
> containing links to actions within the Cat app.
>
>> What form of uri_for are you using? If it is just to capture the
>> applications root then could you replace it with your own
>> convenience
>> routine that just implemented that aspect of what uri_for is
>> doing
>> without bringing in the whole of Catalyst?
>
> [% Catalyst.uri_for(Catalyst.controller('MyController').action_for('myaction'), [ some_id ] ) %]
>
> Could you offer an example, based on my uri_for example above?
I suggest to load your Catalyst app with a config that doesn't load
unnecessary stuff like the models and views, just the controllers and
use $c->uri_for_action.
Take a look at how Catalyst::Test::ctx_request does it or even use
Catalyst::Test...

>
> Thanks,
> Anthony
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the Catalyst mailing list