[Catalyst] Accessing a Controller from ~/script
Dermot
paikkos at googlemail.com
Thu Feb 19 12:58:18 GMT 2009
2009/2/19 Kieren Diment <kieren at diment.org>:
>
> On 19/02/2009, at 9:52 PM, Dermot wrote:
>
>> 2009/2/19 Kieren Diment <diment at gmail.com>:
yapp/MyStandaloneModel.pm) that you can use the bulk of the code in the
>>>
>
> arg MyApp/lib/MyStandaloneModel.pm
>>> controller and the script. Use Catalyst::Model::Adaptor and ACCEPT
>>> context
>>> to get the logic of this standalone model out of the controller and into
>>> the
>>> catalyst model.
>>
>> Great thanx. I'll get straight to work on it. I might have a question
>> or two later about the config.
>
> Check the 2008 advent calendar for ACCEPT_CONTEXT usage:
> http://dev.catalystframework.org/wiki/adventcalendararticles
Wow! that works but I am not sure where ACCEPT_CONTEXT comes into it.
###### MyApp/lib/Importer.pm ########
package Importer;
use strict;
use warnings;
use Moose;
sub hello { 'Hello World'}
1;
##### MyApp/lib/Model/Adaptor.pm ####
package MyApp::Model::Adaptor;
use strict;
use warnings;
use base 'Catalyst::Model::Adaptor';
__PACKAGE__->config( class => 'Importer');
1;
#### MyApp/lib/Controller/MyController.pm ####
sub dosomework : Local {
my ( $self, $c ) = @_;
my $word = $c->model('Adaptor');
$c->log->debug('The word is '.$word->hello);
}
[debug] The word is Hello World
So I am not sure why I need the ACCEPT_CONTEXT sub from that article
or where to put it.
I am assuming that MyApp/script/import.pl will, with a bit of help
from FindBin, use Importer;
Thanx,
Dp.
More information about the Catalyst
mailing list