X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FScriptRunner.pm;h=de3c8bb5669f1b490ff8663f8a9d9ed3c9508160;hb=1beae7ed73fa0e91a39ab4b1b8b181aee4039535;hp=b20faf5b1c1c9720df10d2f256cef3c32547a9c5;hpb=c1c59374b654a94651794b9f83be6fe596a3af25;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/ScriptRunner.pm b/lib/Catalyst/ScriptRunner.pm index b20faf5..de3c8bb 100644 --- a/lib/Catalyst/ScriptRunner.pm +++ b/lib/Catalyst/ScriptRunner.pm @@ -1,16 +1,59 @@ package Catalyst::ScriptRunner; use Moose; +use FindBin; +use lib; +use File::Spec; +use namespace::autoclean; sub run { my ($self, $class, $scriptclass) = @_; my $classtoload = "${class}::Script::$scriptclass"; + lib->import(File::Spec->catdir($FindBin::Bin, '..', 'lib')); + + warn("load $classtoload or Catalyst::Script::$scriptclass"); + # FIXME - Error handling / reporting - if ( eval { Class::MOP::load_class($classtoload) } ) { - } else { + unless ( eval { Class::MOP::load_class($classtoload) } ) { + warn("Could not load $classtoload - falling back to Catalyst::Script::$scriptclass : $@\n") + if $@ !~ /Can't locate/; $classtoload = "Catalyst::Script::$scriptclass"; Class::MOP::load_class($classtoload); } - $classtoload->new_with_options( app => $class )->run; + $classtoload->new_with_options( application_name => $class )->run; } -1; + +__PACKAGE__->meta->make_immutable; + +=head1 NAME + +Catalyst::ScriptRunner - The Catalyst Framework script runner + +=head1 SYNOPSIS + + # Will run MyApp::Script::Server if it exists, otherwise + # will run Catalyst::Script::Server. + Catalyst::ScriptRunner->run('MyApp', 'Server'); + +=head1 DESCRIPTION + +This class is responsible for running scripts, either in the application specific namespace +(e.g. C), or the Catalyst namespace (e.g. C) + +=head1 METHODS + +=head2 run ($application_class, $scriptclass) + +Called with two parameters, the application classs (e.g. MyApp) +and the script class, (i.e. one of Server/FastCGI/CGI/Create/Test) + +=head1 AUTHORS + +Catalyst Contributors, see Catalyst.pm + +=head1 COPYRIGHT + +This library is free software. You can redistribute it and/or modify it under +the same terms as Perl itself. + +=cut