Tests and fixes for conditional inclusion
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ScriptRunner.pm
index 1e8c572..7b80377 100644 (file)
@@ -4,6 +4,7 @@ use FindBin;
 use lib;
 use File::Spec;
 use Class::Load qw/ load_first_existing_class load_optional_class /;
+use Catalyst::Utils;
 use namespace::autoclean -also => 'subclass_with_traits';
 use Try::Tiny;
 
@@ -34,7 +35,9 @@ sub subclass_with_traits {
 sub run {
     my ($self, $appclass, $scriptclass) = @_;
 
-    lib->import(File::Spec->catdir($FindBin::Bin, '..', 'lib'));
+    if (my $home = Catalyst::Utils::find_home_unloaded_in_checkout()) {
+        lib->import(File::Spec->catdir($home, 'lib'));
+    }
 
     my $class = $self->find_script_class($appclass, $scriptclass);
 
@@ -48,6 +51,7 @@ sub run {
 }
 
 __PACKAGE__->meta->make_immutable;
+1;
 
 =head1 NAME
 
@@ -86,6 +90,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