Should detect if we're in a checkout. I'm still not happy with this
[catagits/Catalyst-Devel.git] / lib / Catalyst / Helper.pm
index 508e778..c2ef31d 100644 (file)
@@ -28,20 +28,41 @@ Catalyst::Helper - Bootstrap a Catalyst application
 
 =cut
 
+
+
 sub get_sharedir_file {
     my ($self, @filename) = @_;
-    my $file = file( dist_dir('Catalyst-Devel'), @filename);
-    warn $file;
+    my $dist_dir;
+    if (-d "inc/.author") { # Can't use sharedir if we're in a checkout
+                            # this feels horrible, better ideas?
+        $dist_dir = 'share';
+    }
+    else {
+        $dist_dir = dist_dir('Catalyst-Devel');
+    }
+    my $file = file( $dist_dir, @filename);
     my $contents = $file->slurp;
     return $contents;
 }
 
+# Do not touch this method, *EVER*, it is needed for back compat.
 sub get_file {
-    my ( $self, $file ) = @_;
-   
-    return $self->get_sharedir_file($file);
+    my ( $self, $class, $file ) = @_;
+    unless ( $cache{$class} ) {
+        local $/;
+        $cache{$class} = eval "package $class; <DATA>";
+    }
+    my $data = $cache{$class};
+    my @files = split /^__(.+)__\r?\n/m, $data;
+    shift @files;
+    while (@files) {
+        my ( $name, $content ) = splice @files, 0, 2;
+        return $content if $name eq $file;
+    }
+    return 0;
 }
 
+
 sub mk_app {
     my ( $self, $name ) = @_;
 
@@ -246,6 +267,8 @@ sub next_test {
     return File::Spec->catfile( $dir, "$type\_$tname" );
 }
 
+# Do not touch this method, *EVER*, it is needed for back compat.
+
 sub render_file {
     my ( $self, $file, $path, $vars ) = @_;
     $vars ||= {};
@@ -421,7 +444,7 @@ sub _mk_images {
       btn_120x50_powered btn_120x50_powered_shadow btn_88x31_built
       btn_88x31_built_shadow btn_88x31_powered btn_88x31_powered_shadow/;
     for my $name (@images) {
-        my $image = $self->get_file("$name.png");
+        my $image = $self->get_sharedir_file("root", "$name.png");
         $self->mk_file( File::Spec->catfile( $images, "$name.png" ), $image );
     }
 }