X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FScriptRunner.pm;h=b9a60f860f96c92d8595893564249a7b71184f67;hp=1e9626ea249215f2eb4abf4641214058b157787b;hb=d2d007f49d5e9b06f0d1a6f38fc9ac8ac3306183;hpb=383c5be6711391bd114674e2dfb0b9e84a100a38 diff --git a/lib/Catalyst/ScriptRunner.pm b/lib/Catalyst/ScriptRunner.pm index 1e9626e..b9a60f8 100644 --- a/lib/Catalyst/ScriptRunner.pm +++ b/lib/Catalyst/ScriptRunner.pm @@ -4,8 +4,9 @@ use FindBin; use lib; use File::Spec; use Class::Load qw/ load_first_existing_class load_optional_class /; -use namespace::autoclean -also => 'subclass_with_traits'; +use Catalyst::Utils; use Try::Tiny; +use namespace::clean -except => [ 'meta' ]; sub find_script_class { my ($self, $app, $script) = @_; @@ -18,6 +19,7 @@ sub find_script_traits { return grep { load_optional_class($_) } @try; } +no namespace::clean; sub subclass_with_traits { my ($base, @traits) = @_; @@ -30,11 +32,14 @@ sub subclass_with_traits { return $meta->name; } +use namespace::clean; sub run { my ($self, $appclass, $scriptclass) = @_; - lib->import(File::Spec->catdir($FindBin::Bin, '..', 'lib')); + if (grep { -f File::Spec->catfile($FindBin::Bin, '..', $_) } Catalyst::Utils::dist_indicator_file_list()) { + lib->import(File::Spec->catdir($FindBin::Bin, '..', 'lib')); + } my $class = $self->find_script_class($appclass, $scriptclass); @@ -48,6 +53,7 @@ sub run { } __PACKAGE__->meta->make_immutable; +1; =head1 NAME @@ -61,7 +67,8 @@ Catalyst::ScriptRunner - The Catalyst Framework script runner =head1 DESCRIPTION -This class is responsible for loading and running scripts, either in the application specific namespace +This class is responsible for loading and running scripts, either in the +application specific namespace (e.g. C), or the Catalyst namespace (e.g. C). If your application contains a custom script, then it will be used in preference to the generic @@ -69,7 +76,8 @@ script, and is expected to sub-class the standard script. =head1 TRAIT LOADING -Catalyst will automatically load and apply roles to the scripts in your appliction. +Catalyst will automatically load and apply roles to the scripts in your +application. C will be loaded if present, and will be applied to B scripts. @@ -84,6 +92,16 @@ individually. Called with two parameters, the application class (e.g. MyApp) and the script class, (i.e. one of Server/FastCGI/CGI/Create/Test) +=head2 find_script_class ($appname, $script_name) + +Finds and loads the class for the script, trying the application specific +script first, and falling back to the generic script. Returns the script +which was loaded. + +=head2 find_script_traits ($appname, @try) + +Finds and loads a set of traits. Returns the list of traits which were loaded. + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm