RE: [Catalyst] Access Catalyst context object from script

2012-11-01 Thread Anthony Gladdish
>From: Bill Moseley [mailto:mose...@hank.org] 
>Sent: 01 November 2012 14:14
>To: The elegant MVC web framework
>Subject: Re: [Catalyst] Access Catalyst context object from script
>
>
>On Wed, Oct 31, 2012 at 6:10 AM, Anthony Gladdish 
> wrote:
>
>Great - this worked, thanks. I used:
>
>        use Catalyst::Test 'MyApp';
>        my($res, $c) = ctx_request('/');
>
>How does uri_for() know what host:port and script path to use to build correct 
>URLs to your site?

Got a front-end proxy setup, so not worried about host:port as I can just 
replace "localhost" with whatever my web server is using at the time, in the 
template. A bit hacky I know, but at least I've got the correctly generated 
path without hard coding it in.

Unless, you know of an alternate way/better way of tricking context object or 
Catalyst::Test in using a specific host:port?

Anthony

___
List: Catalyst@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/


Re: [Catalyst] Access Catalyst context object from script

2012-11-01 Thread Bill Moseley
On Wed, Oct 31, 2012 at 6:10 AM, Anthony Gladdish <
anthony.gladd...@newcastle.ac.uk> wrote:

>
> Great - this worked, thanks. I used:
>
> use Catalyst::Test 'MyApp';
> my($res, $c) = ctx_request('/');
>

How does uri_for() know what host:port and script path to use to build
correct URLs to your site?


-- 
Bill Moseley
mose...@hank.org
___
List: Catalyst@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/


RE: [Catalyst] Access Catalyst context object from script

2012-10-31 Thread Anthony Gladdish
>-Original Message-
>From: Alexander Hartmaier [mailto:alexander.hartmaier@t-
>systems.at]
>Sent: 31 October 2012 12:46
>To: catalyst@lists.scsys.co.uk
>Subject: Re: [Catalyst] Access Catalyst context object from script

>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...

Great - this worked, thanks. I used:

use Catalyst::Test 'MyApp';
my($res, $c) = ctx_request('/');

... then I just pass $c into the layer I use for the TT/mailing bit:

$params{Catalyst} = $c;

# New MIME::Lite::TT object:
my $msg = MIME::Lite::TT->new(
From=>  $from,
To  =>  $to,
Subject =>  $subject,
Template=>  $template_path,
TmplOptions =>  \%options,
TmplParams  =>  \%params,
);
 
Thanks for your help,

Anthony

___
List: Catalyst@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/


Re: [Catalyst] Access Catalyst context object from script

2012-10-31 Thread Alexander Hartmaier
On 2012-10-31 13:30, Anthony Gladdish wrote:
>> -Original Message-
>> From: Ian Docherty [mailto:catal...@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
>>  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@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.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

___
List: Catalyst@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/


RE: [Catalyst] Access Catalyst context object from script

2012-10-31 Thread Anthony Gladdish
>From: Dimitar Petrov [mailto:mita...@gmail.com] 
>Sent: 31 October 2012 11:18
>To: The elegant MVC web framework
>Subject: Re: [Catalyst] Access Catalyst context object from script
>
>Hello Anthony,
>
>I think the catalyst object is not called Catalyst but c, this you need [% 
>c.uri_for(...) %] or you can use [% c.uri_for_action(...) %] to point to 
>particular action.
>You could change that setting the CATALYST_VAR into your view configuration 
>(as shown here https://metacpan.org/module/Catalyst::View::TT), however I 
>think "c" is shorter and >better default.
>
>Cheers 

That's not the issue here; I can use CATALYST_VAR to rename it to whatever I 
want, it still doesn't give me access to the Catalyst's context object outside 
of a catalyst app - which is what I'm after here.

I'm trying to get an external script run by a cronjob, to re-use an existing 
Catalyst template containing [% c.uri_for() %] statements that point to actions 
within the cat app itself, instead of having to hard code URIs.

Regards,
Anthony
___
List: Catalyst@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/


RE: [Catalyst] Access Catalyst context object from script

2012-10-31 Thread Anthony Gladdish
>-Original Message-
>From: Ian Docherty [mailto:catal...@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
> 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?

Thanks,
Anthony

___
List: Catalyst@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/


Re: [Catalyst] Access Catalyst context object from script

2012-10-31 Thread Ian Docherty
On 31 October 2012 10:41, Anthony Gladdish
 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?

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?

Regards
Ian

___
List: Catalyst@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/


Re: [Catalyst] Access Catalyst context object from script

2012-10-31 Thread Rob Brown
Your script is not running under Catalyst, so $c, or the Catalyst 
context, is not available.


$c manages HTTP requests and responses.

It sounds like your approach/design may be slightly flawed.  Perhaps 
explain what you're trying to achieve - what are you doing with these 
templates?  where are they going?  why do they have URLs to your 
Catalyst app in them?


Cheers,
Robsco



On 10/31/2012 11:18 AM, Dimitar Petrov wrote:

Hello Anthony,

I think the catalyst object is not called Catalyst but c, this you need
[% c.uri_for(...) %] or you can use [% c.uri_for_action(...) %] to point
to particular action.
You could change that setting the CATALYST_VAR into your view
configuration (as shown here
https://metacpan.org/module/Catalyst::View::TT), however I think "c" is
shorter and better default.

Cheers


On Wed, Oct 31, 2012 at 11:41 AM, Anthony Gladdish
mailto:anthony.gladd...@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?

Regards,

Anthony Gladdish

___
List: Catalyst@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/




___
List: Catalyst@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/


--
IntelCompute
Web Design & Online Marketing Experts

http://www.intelcompute.com

___
List: Catalyst@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/


Re: [Catalyst] Access Catalyst context object from script

2012-10-31 Thread Dimitar Petrov
Hello Anthony,

I think the catalyst object is not called Catalyst but c, this you need [%
c.uri_for(...) %] or you can use [% c.uri_for_action(...) %] to point to
particular action.
You could change that setting the CATALYST_VAR into your view configuration
(as shown here https://metacpan.org/module/Catalyst::View::TT), however I
think "c" is shorter and better default.

Cheers


On Wed, Oct 31, 2012 at 11:41 AM, Anthony Gladdish <
anthony.gladd...@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?
>
> Regards,
>
> Anthony Gladdish
>
> ___
> List: Catalyst@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/
>
___
List: Catalyst@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/


[Catalyst] Access Catalyst context object from script

2012-10-31 Thread Anthony Gladdish
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?

Regards,

Anthony Gladdish

___
List: Catalyst@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/