[Catalyst] Additional scripts accessing the Model and Config?

Luis Muñoz luisemunoz at gmail.com
Thu Jun 7 22:17:15 GMT 2012

Hi there,

During the last couple of days I've been trying various ways to do this, but it all seems more complicated than it should be.

I have a Catalyst app that implements a number of controllers that modify data through a model. Let's say it's a DBIC model for simplicity. I need to write various sets of scripts to be run from the command line, that will access the data and produce reports that are to be fed to other processes.

What I would like is to have a simple construct where the body of the script would be something like this


  use strict;
  use warnings;

  use Catalyst::ScriptRunner;
  Catalyst::ScriptRunner->run('My::Fancy::App', 'Dump');

  exit 0;

And then in My::Fancy::App::Script::Dump.pm I would have the main body of the script, in a way similar to what the _create.pl et al scripts operate.

The part that's stumping me is how to go within Dump.pm about obtaining a $c that allows me to get to the configuration (taken from the same place where the web application takes it) and the model. 

My current (simplified) contents of the Dump.pm file are as follows:

  package My::Fancy::App::Script::Dump;
  use Moose;
  use MooseX::Types::Moose qw/Bool Str/;
  use namespace::autoclean;

  has output => (
      traits        => [qw(Getopt)],
      cmd_aliases   => 'o',
      isa           => Str,
      is            => 'ro',
      documentation => 'Output name for the generated file(s)',

  sub run {
      my ($self) = @_;

      printf ( "some_custom_data=%s\n", $self->my_custom_db_config ( 'custom.data' ));

      die ( "Error: Must specify things to process using --thing\n" ) 
          unless $self->tld;
      $self->_getopt_full_usage if !$self->ARGV->[0];
      $self->_getopt_full_usage ();


Where ->my_custom_db_config is a method that fetches process-specific configuration from the Schema. I would like to access things like ->log, ->model and the utility methods that I use in the Controllers from within the script. And of course, I would like to use the same configuration file.

Has anybody dealt with a similar problem before? Or am I on my own :-)

Best regards


More information about the Catalyst mailing list