Hello,

On Fri, Jun 8, 2012 at 11:33 AM, Luis Muñoz <[email protected]> wrote:

>
> On Jun 8, 2012, at 5:04 PM, Tomas Doran wrote:
>
> > Sorry - I'm confused - how does calling into the app to get stuff as
> $self->application_name->model('Foo')->some_method(@stuff)
>
> How does the Model, called like that, would know the details of where it
> is supposed to connect? Things like the DSN, username, password, etc are in
> config files whose reading is triggered "magically" by the Catalyst
> infrastructure. However that is not present when running as a script.
>

I think the basic confusion is in that you are wanting Catalyst to "own"
your Model, Config, and Log and be able to use them from a script when
really what you want is to have those separate from Catalyst but used in
both Catalyst and a script. DBIC is essentially doing this with the Model
already. Checkout Log4perl or something similar for the Log, check out
Config::JFDI for the config.

I rely on an environment variable being set, both for Catalyst and my
scripts.  Here is an example of something at the top of one of my scripts:

my $path = $ENV{MY_FANCY_APP_HOME} || die "Must set env";

use Config::JFDI;
my $config_jfdi = Config::JFDI->new( name => 'my_fancy_app', path => $path
);
my $config = $config_jfdi->get;

use Log::Log4perl;
Log::Log4perl->init_once( $path . '/log.conf' );
my $log = Log::Log4perl->get_logger('MyFancyApp');

use MyFancyApp::Model::DB;
my $model = MyFancyApp::Model::DB->new( $config->{'Model::DB'} );

# Log our foo config item if we have a row in our foo table
$log->info("Foo: " . $config->{foo}) if
$model->resultset('FooTable')->count;


And in your my_fancy_app.yaml config:

foo: 'bar'
'Model::DB':
    schema_class: 'MyFancyApp::Schema'
    connect_info:
        dsn: 'dbi:mysql:dbname=fancyapp'
        user: 'root'
        password: 'secretpass'


Then you have a $log, $config, and $model, all of which should return the
same things as their respective $c context methods ($c->log, $c->config,
and $c->model).

You can, of course, hide all these details from your script if you like but
that should get you there.


> This is the reason for my question.
>
> -lem
>
>
>
> _______________________________________________
> List: [email protected]
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/[email protected]/
> Dev site: http://dev.catalyst.perl.org/
>



-- 
~Tyler
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to