Accessing your Catalyst config from scripts

2009-02-01 − 🏷 catalyst 🏷 perl

Often, I need to write command line scripts that access my apps' data models. With Catalyst, one way to do this is to to load the actual application, like

use iusethis;

Then I can access my models like iusethis->model('DBIC::Person') . However, all I really need is to get the application configuration, and loading a big application is a lot of overhead. Just using Config::Any isn't a good solution tho, since it does not handle _local files properly, among other thing. However, with Config::JFDI there's a better way.

use Config::JFDI;
my $jfdi = Config::JFDI->new(name => "iusethis");
my $config = $jfdi->get;
my $schema = iusethis::Schema->connect( @{$config->{'Model::DBIC'}->{'connect_info'}})
    or die "Failed to connect to database";