[Catalyst] Additional scripts accessing the Model and Config?
will trillich
will.trillich at serensoft.com
Fri Jun 8 18:52:13 GMT 2012
Example of pulling the standard catalyst config into a
"command-line-type-usage" script (works nicely from the scripts/ directory):
use FindBin qw($Bin);
use Path::Class;
use lib dir($Bin, '..', 'lib')->stringify; # cross-platform
# Now that we have the local LIB directory in our @INC path, get the module:
use MyApp::Schema::DB;
use Config::General;
use strict;
# Get info from the config file
my $conf =3D new Config::General( file( $Bin, '..', 'myapp.conf' ) );
my %conf =3D $conf->getall;
my $dbi =3D $conf{'Model::MyApp'}{connect_info};
my @dbi =3D map{ $dbi->{$_} } qw/dsn user password/;
# Connect to database
my $schema =3D MyApp::Schema::DB->connect( @dbi );
#...etc
On Fri, Jun 8, 2012 at 1:23 PM, Thomas Klausner <domm at cpan.org> wrote:
> Hi!
>
> On Fri, Jun 08, 2012 at 02:05:31PM -0400, Luis Mu=F1oz wrote:
>
> > But still, I would like to have access to the configuration data (for
> > instance, how to setup the database/ldap/whatever Model, etc). Does
> > that happen as well when using the class method?
>
> We pack our config (which basically is a big hash) in a class. To
> provide the config to Catalyst, we use the class in my_app.pl (which is
> like my_app.(yml|json|ini|...). If we need the config in some other
> scripts, we just use the class there.
>
> The non-Web code lives in classes (eg DBIC) that are used via Models in
> Catalyst, or directly (or some Model-like wrappers, if it needs to be)
> in other contexts.
>
> Greetings,
> domm
>
>
> --
> #!/usr/bin/perl http://domm.plix.at
> for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
>
> _______________________________________________
> 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/
>
-- =
Will Trillich :: 812.454.6431
=93Waiting for perfect is never as smart as making progress.=94 -- Seth Go=
din
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120608/fe2c4=
c75/attachment.htm
More information about the Catalyst
mailing list