Merge remote branch 'origin/topic/template-remove-critic-violation'
Tomas Doran [Wed, 11 Aug 2010 23:50:10 +0000 (00:50 +0100)]
* origin/topic/template-remove-critic-violation:
  remove eval Perl-Critic doesn't like it

Changes
lib/Catalyst/Helper.pm
t/generated_app.t

diff --git a/Changes b/Changes
index 23124c9..10b90d5 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 This file documents the revision history for Perl extension Catalyst-Devel.
 
+        - Allow catalyst.pl . to work for already created applications
+          when in the application's directory.
         - Note that plugin order is important in the generated skeleton.
         - Don't pollute M::I plugin detector with GetOptions symbol from
           GetOpt::Long
index 3b182ad..5338cd0 100644 (file)
@@ -13,6 +13,7 @@ use Catalyst::Utils;
 use Catalyst::Exception;
 use Path::Class qw/dir file/;
 use File::ShareDir qw/dist_dir/;
+use YAML::Tiny;
 use namespace::autoclean;
 
 with 'MooseX::Emulate::Class::Accessor::Fast';
@@ -78,13 +79,31 @@ sub mk_app {
     # Needs to be here for PAR
     require Catalyst;
 
+    if($name eq '.') {
+        if(!-e 'META.yml') {
+            system perl => 'Makefile.PL'
+                and Catalyst::Exception->throw(message => q(
+                    Failed to run "perl Makefile.PL".
+                ));
+        }
+
+        $name = YAML::Tiny->read('META.yml')->[0]->{'name'};
+        $name =~ s/-/::/g;
+        $self->{dir} = '.';
+    }
+
     if ( $name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
         warn "Error: Invalid application name.\n";
         return 0;
     }
+
+
+    if(!defined $self->{'dir'}) {
+        $self->{dir} = $name;
+        $self->{dir} =~ s/\:\:/-/g;
+    }
+
     $self->{name            } = $name;
-    $self->{dir             } = $name;
-    $self->{dir             } =~ s/\:\:/-/g;
     $self->{script          } = dir( $self->{dir}, 'script' );
     $self->{appprefix       } = Catalyst::Utils::appprefix($name);
     $self->{appenv          } = Catalyst::Utils::class2env($name);
index 51cb3f1..6c7a66b 100644 (file)
@@ -84,8 +84,9 @@ command_ok( [ ($Config{make} || 'make') ] );
 
 run_generated_component_tests();
 
+my $server_script_file = File::Spec->catdir(qw/script testapp_server.pl/);
 my $server_script = do {
-    open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!;
+    open(my $fh, '<', $server_script_file) or fail $!;
     local $/;
     <$fh>;
 };
@@ -95,6 +96,28 @@ ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
     'SCRIPT_GEN found in generated output';
 is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
 
+{
+    open(my $fh, '>', $server_script_file) or fail $!;
+    print $fh "MOO\n";
+}
+my $helper = Catalyst::Helper->new(
+    {
+        '.newfiles' => 0,
+        'makefile'  => 0,
+        'scripts'   => 1,
+        name => '.',
+    }
+);
+$helper->mk_app( '.' ) or fail;
+
+my $server_script_new = do {
+    open(my $fh, '<', $server_script_file) or fail $!;
+    local $/;
+    <$fh>;
+};
+
+is $server_script, $server_script_new;
+
 chdir('/');
 done_testing;