X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;h=6ff9836fde7e4285e8d7605312fb6ffc336bcfbb;hb=55fac4683a99cec46c495490a2f389d27598533e;hp=83e7c83f51539d1ae2347b7f775fa006518dc0af;hpb=068587bd73a1feedfcab20b56e86db93c11b34f7;p=catagits%2FCatalyst-Devel.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index 83e7c83..6ff9836 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -1,7 +1,8 @@ package Catalyst::Helper; -#use Moose; +use Moose; use Config; use File::Spec; +use File::Spec::Unix; use File::Path; use FindBin; use IO::File; @@ -12,7 +13,13 @@ use Catalyst::Utils; use Catalyst::Exception; use Path::Class qw/dir file/; use File::ShareDir qw/dist_dir/; -#use namespace::autoclean; +use YAML::Tiny; +use namespace::autoclean; + +with 'MooseX::Emulate::Class::Accessor::Fast'; + +# Change Catalyst/Devel.pm also +our $VERSION = '1.29'; my %cache; @@ -29,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'; @@ -69,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"; - $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN || 4; + : "#!$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'; @@ -93,33 +121,28 @@ sub mk_app { my $gen_app = ( $self->{scripts} || $self->{makefile} ) ? 0 : 1; if ($gen_app) { - - - $self->_mk_dirs; - $self->_mk_config; - $self->_mk_appclass; - $self->_mk_rootclass; - $self->_mk_readme; - $self->_mk_changes; - $self->_mk_apptest; - $self->_mk_images; - $self->_mk_favicon; + for ( qw/ _mk_dirs _mk_config _mk_appclass _mk_rootclass _mk_readme + _mk_changes _mk_apptest _mk_podtest _mk_podcoveragetest + _mk_images _mk_favicon/ ) { + + $self->$_; + } } if ($gen_makefile) { $self->_mk_makefile; } if ($gen_scripts) { - $self->_mk_cgi; - $self->_mk_fastcgi; - $self->_mk_server; - $self->_mk_dbic_deploy; - $self->_mk_test; - $self->_mk_create; - $self->_mk_information; + for ( qw/ _mk_cgi _mk_fastcgi _mk_server + _mk_test _mk_create _mk_information + / ) { + $self->$_; + } } return $self->{dir}; } +## not much of this can really be changed, mk_compclass must be left for +## backcompat sub mk_component { my $self = shift; my $app = shift; @@ -193,12 +216,16 @@ sub mk_component { 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 @@ -391,14 +418,24 @@ sub _mk_changes { my $self = shift; my $dir = $self->{dir}; my $time = strftime('%Y-%m-%d %H:%M:%S', localtime time); - $self->render_sharedir_file( 'Changes.tt', file($dir, "Changes", { time => $time } ); + $self->render_sharedir_file( 'Changes.tt', file($dir, "Changes"), { time => $time } ); } 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") ); } @@ -476,23 +513,15 @@ sub _mk_favicon { } -sub _mk_dbic_deploy { - my $self = shift; - my $script = $self->{script}; - my $appprefix = $self->{appprefix}; - $self->render_sharedir_file( file('script', 'myapp_deploy_schema.pl.tt'), file($script, "$appprefix\_deploy_schema.pl") ); - chmod 0700, file($script, "$appprefix\_deploy_schema.pl"); -} - sub _deprecate_file { my ( $self, $file ) = @_; if ( -e $file ) { - my $oldcontent; - if ( my $f = IO::File->new("< $file") ) { + my ($f, $oldcontent); + if ( $f = IO::File->new("< $file") ) { $oldcontent = join( '', (<$f>) ); } my $newfile = $file . '.deprecated'; - if ( my $f = IO::File->new("> $newfile") ) { + if ( $f = IO::File->new("> $newfile") ) { binmode $f; print $f $oldcontent; print qq/created "$newfile"\n/; @@ -527,10 +556,6 @@ development stage. The catalyst test server, starts an HTTPD which outputs debugging to the terminal. -=head2 _deploy_dbic.pl - -Deploy a L schema to the database of your choice. - =head2 _test.pl A script for running tests from the command-line. @@ -592,7 +617,8 @@ L - wrap any class into a Catalyst model =head3 NOTE -The helpers will read author name from /etc/passwd by default. + To override, please export the AUTHOR variable. +The helpers will read author name from /etc/passwd by default. +To override, please export the AUTHOR variable. =head1 METHODS @@ -655,7 +681,7 @@ Create the main application skeleton. This is called by L. This method is called by L to make new components for your application. -=head3 mk_dir ($path) +=head2 mk_dir ($path) Surprisingly, this function makes a directory. @@ -688,7 +714,6 @@ Render a template/image file from our share directory =cut - =head1 NOTE The helpers will read author name from /etc/passwd by default. @@ -708,8 +733,6 @@ Catalyst Contributors, see Catalyst.pm This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. -=begin pod_to_ignore - =cut 1;