Search a list of potential template directories, including the project base.
[catagits/Catalyst-Devel.git] / lib / Catalyst / Helper.pm
index 5df10e6..86ba60f 100644 (file)
@@ -2,6 +2,7 @@ package Catalyst::Helper;
 use Moose;
 use Config;
 use File::Spec;
+use File::Spec::Unix;
 use File::Path;
 use FindBin;
 use IO::File;
@@ -14,6 +15,11 @@ use Path::Class qw/dir file/;
 use File::ShareDir qw/dist_dir/;
 use namespace::autoclean;
 
+with 'MooseX::Emulate::Class::Accessor::Fast';
+
+# Change Catalyst/Devel.pm also
+our $VERSION = '1.23';
+
 my %cache;
 
 =head1 NAME
@@ -28,16 +34,28 @@ Catalyst::Helper - Bootstrap a Catalyst application
 
 sub get_sharedir_file {
     my ($self, @filename) = @_;
-    my $dist_dir;
+
+    my @try_dirs;
+    if (exists $self->{base}) {
+        push @try_dirs, $self->{base};
+    }
+    if (exists $ENV{CATALYST_DEVEL_SHAREDIR}) {
+        push @try_dirs, $ENV{CATALYST_DEVEL_SHAREDIR}
+    }
     if (-d "inc/.author" && -f "lib/Catalyst/Helper.pm"
             ) { # Can't use sharedir if we're in a checkout
                 # this feels horrible, better ideas?
-        $dist_dir = 'share';
+        push @try_dirs, 'share';
     }
     else {
-        $dist_dir = dist_dir('Catalyst-Devel');
+        push @try_dirs, dist_dir('Catalyst-Devel');
+    }
+
+    my $file;
+    foreach my $dist_dir (@try_dirs) {
+      $file = file( $dist_dir, @filename);
+      last if -r $file;
     }
-    my $file = file( $dist_dir, @filename);
     Carp::confess("Cannot find $file") unless -r $file;
     my $contents = $file->slurp;
     return $contents;
@@ -184,17 +202,19 @@ sub mk_component {
                     message => qq/Couldn't load helper "$class", "$@"/ );
             }
 
-            ## must be left for back compat! ###################################
             if ( $class->can('mk_compclass') ) {
                 return 1 unless $class->mk_compclass( $self, @args );
             }
-            else { return 1 unless $self->_mk_compclass }
+            else {
+                return 1 unless $self->_mk_compclass
+            }
 
             if ( $class->can('mk_comptest') ) {
                 $class->mk_comptest( $self, @args );
             }
-            else { $self->_mk_comptest }
-            ####################################################################
+            else {
+                $self->_mk_comptest
+            }
         }
 
         # Fallback
@@ -640,7 +660,7 @@ Create the main application skeleton. This is called by L<catalyst.pl>.
 This method is called by L<create.pl> to make new components
 for your application.
 
-=head3 mk_dir ($path)
+=head2 mk_dir ($path)
 
 Surprisingly, this function makes a directory.