X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;h=f2e39c92d394c3e90eba3f76c105add53e1bb3c3;hb=b6d896903dcf3db83957abd9bd160e257b5e14e5;hp=5011e91855c7a5bf2eaa6d4108843aeffec565ad;hpb=fdb9d1d902144d4a2efa8728c15dab2cf7a02258;p=catagits%2FCatalyst-Devel.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index 5011e91..f2e39c9 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -13,8 +13,14 @@ 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'; + +# Change Catalyst/Devel.pm also +our $VERSION = '1.33'; + my %cache; =head1 NAME @@ -30,7 +36,10 @@ Catalyst::Helper - Bootstrap a Catalyst application sub get_sharedir_file { my ($self, @filename) = @_; my $dist_dir; - if (-d "inc/.author" && -f "lib/Catalyst/Helper.pm" + if (exists $ENV{CATALYST_DEVEL_SHAREDIR}) { + $dist_dir = $ENV{CATALYST_DEVEL_SHAREDIR}; + } + elsif (-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'; @@ -70,22 +79,40 @@ 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); $self->{startperl } = -r '/usr/bin/env' ? '#!/usr/bin/env perl' - : "#!$Config{perlpath} -w"; + : "#!$Config{perlpath}"; $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN; $self->{catalyst_version} = $Catalyst::VERSION; - $self->{author } = $self->{author} = $ENV{'AUTHOR'} + $self->{author } ||= $ENV{'AUTHOR'} || eval { @{ [ getpwuid($<) ] }[6] } || 'Catalyst developer'; @@ -95,7 +122,8 @@ sub mk_app { if ($gen_app) { for ( qw/ _mk_dirs _mk_config _mk_appclass _mk_rootclass _mk_readme - _mk_changes _mk_apptest _mk_images _mk_favicon/ ) { + _mk_changes _mk_apptest _mk_podtest _mk_podcoveragetest + _mk_images _mk_favicon/ ) { $self->$_; } @@ -244,7 +272,7 @@ sub mk_file { binmode $f; print $f $content; print qq/created "$file"\n/; - return 1; + return $file; } Catalyst::Exception->throw( message => qq/Couldn't create "$file", "$!"/ ); @@ -275,20 +303,20 @@ sub next_test { ## compatability. otherwise, we'd have no way to pass stuff from __DATA__ sub render_file { - my ( $self, $file, $path, $vars ) = @_; + my ( $self, $file, $path, $vars, $perms ) = @_; my $template = $self->get_file( ( caller(0) )[0], $file ); - $self->render_file_contents($template, $path, $vars); + $self->render_file_contents($template, $path, $vars, $perms); } sub render_sharedir_file { - my ( $self, $file, $path, $vars ) = @_; + my ( $self, $file, $path, $vars, $perms ) = @_; my $template = $self->get_sharedir_file( $file ); die("Cannot get template from $file for $self\n") unless $template; - $self->render_file_contents($template, $path, $vars); + $self->render_file_contents($template, $path, $vars, $perms); } sub render_file_contents { - my ( $self, $template, $path, $vars ) = @_; + my ( $self, $template, $path, $vars, $perms ) = @_; $vars ||= {}; my $t = Template->new; return 0 unless $template; @@ -296,7 +324,8 @@ sub render_file_contents { $t->process( \$template, { %{$self}, %$vars }, \$output ) || Catalyst::Exception->throw( message => qq/Couldn't process "$template", / . $t->error() ); - $self->mk_file( $path, $output ); + my $file = $self->mk_file( $path, $output ); + chmod $perms, file($file) if $perms; } sub _mk_information { @@ -397,7 +426,17 @@ sub _mk_apptest { my $self = shift; my $t = $self->{t}; $self->render_sharedir_file( file('t', '01app.t.tt'), file($t, "01app.t") ); +} + +sub _mk_podtest { + my $self = shift; + my $t = $self->{t}; $self->render_sharedir_file( file('t', '02pod.t.tt'), file($t, "02pod.t") ); +} + +sub _mk_podcoveragetest { + my $self = shift; + my $t = $self->{t}; $self->render_sharedir_file( file('t', '03podcoverage.t.tt'), file($t, "03podcoverage.t") ); } @@ -405,40 +444,40 @@ sub _mk_cgi { my $self = shift; my $script = $self->{script}; my $appprefix = $self->{appprefix}; - $self->render_sharedir_file( file('script', 'myapp_cgi.pl.tt'), file($script,"$appprefix\_cgi.pl") ); - chmod 0700, file($script,"$appprefix\_cgi.pl"); + $self->render_sharedir_file( file('script', 'myapp_cgi.pl.tt'), + file($script,"$appprefix\_cgi.pl"), undef, 0700 ); } sub _mk_fastcgi { my $self = shift; my $script = $self->{script}; my $appprefix = $self->{appprefix}; - $self->render_sharedir_file( file('script', 'myapp_fastcgi.pl.tt'), file($script, "$appprefix\_fastcgi.pl") ); - chmod 0700, file($script, "$appprefix\_fastcgi.pl"); + $self->render_sharedir_file( file('script', 'myapp_fastcgi.pl.tt'), + file($script, "$appprefix\_fastcgi.pl"), undef, 0700 ); } sub _mk_server { my $self = shift; my $script = $self->{script}; my $appprefix = $self->{appprefix}; - $self->render_sharedir_file( file('script', 'myapp_server.pl.tt'), file($script, "$appprefix\_server.pl") ); - chmod 0700, file($script, "$appprefix\_server.pl"); + $self->render_sharedir_file( file('script', 'myapp_server.pl.tt'), + file($script, "$appprefix\_server.pl"), undef, 0700 ); } sub _mk_test { my $self = shift; my $script = $self->{script}; my $appprefix = $self->{appprefix}; - $self->render_sharedir_file( file('script', 'myapp_test.pl.tt'), file($script, "$appprefix\_test.pl") ); - chmod 0700, file($script, "$appprefix\_test.pl"); + $self->render_sharedir_file( file('script', 'myapp_test.pl.tt'), + file($script, "$appprefix\_test.pl"), undef, 0700 ); } sub _mk_create { my $self = shift; my $script = $self->{script}; my $appprefix = $self->{appprefix}; - $self->render_sharedir_file( file('script', 'myapp_create.pl.tt'), file($script, "$appprefix\_create.pl") ); - chmod 0700, file($script, "$appprefix\_create.pl"); + $self->render_sharedir_file( file('script', 'myapp_create.pl.tt'), + file($script, "$appprefix\_create.pl"), undef, 0700 ); } sub _mk_compclass { @@ -620,12 +659,13 @@ There is no fallback for this method. These are the methods that the Helper classes can call on the <$helper> object passed to them. -=head2 render_file ($file, $path, $vars) +=head2 render_file ($file, $path, $vars, $perms) Render and create a file from a template in DATA using Template Toolkit. $file is the relevent chunk of the __DATA__ section, $path is -the path to the file and $vars is the hashref as expected by -L