X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;h=3d72db53ee768e7d2d77b7874509b31beba40198;hb=8e7b8bc309b0a08ed4491ddab3179dae28026c7d;hp=6a78bf312d0206d51811ffdd97ec85ad2ad8bb15;hpb=b9e9fff6b976cb138c6d56f10c37ebc20216b74f;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index 6a78bf3..3d72db5 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -65,7 +65,8 @@ sub mk_app { $self->{startperl} = $Config{startperl}; $self->{scriptgen} = $Catalyst::CATALYST_SCRIPT_GEN; $self->{author} = $self->{author} = $ENV{'AUTHOR'} - || eval { @{ [ getpwuid($<) ] }[6] } || 'A clever guy'; + || eval { @{ [ getpwuid($<) ] }[6] } + || 'Catalyst developer'; $self->_mk_dirs; $self->_mk_appclass; $self->_mk_build; @@ -74,7 +75,7 @@ sub mk_app { $self->_mk_changes; $self->_mk_apptest; $self->_mk_cgi; - $self->_mk_fcgi; + $self->_mk_fastcgi; $self->_mk_server; $self->_mk_test; $self->_mk_create; @@ -93,7 +94,8 @@ sub mk_component { my $app = shift; $self->{app} = $app; $self->{author} = $self->{author} = $ENV{'AUTHOR'} - || eval { @{ [ getpwuid($<) ] }[6] } || 'A clever guy'; + || eval { @{ [ getpwuid($<) ] }[6] } + || 'A clever guy'; $self->{base} = File::Spec->catdir( $FindBin::Bin, '..' ); unless ( $_[0] =~ /^model|m|view|v|controller|c\$/i ) { my $helper = shift; @@ -108,7 +110,7 @@ sub mk_component { else { my $type = shift; my $name = shift || "Missing name for model/view/controller"; - my $helper = shift ; + my $helper = shift; my @args = @_; return 0 if $name =~ /[^\w\:]/; $type = 'M' if $type =~ /model|m/i; @@ -307,40 +309,40 @@ sub _mk_apptest { } sub _mk_cgi { - my $self = shift; - my $script = $self->{script}; + my $self = shift; + my $script = $self->{script}; my $appprefix = $self->{appprefix}; $self->render_file( 'cgi', "$script\/$appprefix\_cgi.pl" ); chmod 0700, "$script/$appprefix\_cgi.pl"; } -sub _mk_fcgi { - my $self = shift; - my $script = $self->{script}; +sub _mk_fastcgi { + my $self = shift; + my $script = $self->{script}; my $appprefix = $self->{appprefix}; - $self->render_file( 'fcgi', "$script\/$appprefix\_fcgi.pl" ); - chmod 0700, "$script/$appprefix\_fcgi.pl"; + $self->render_file( 'fastcgi', "$script\/$appprefix\_fastcgi.pl" ); + chmod 0700, "$script/$appprefix\_fastcgi.pl"; } sub _mk_server { - my $self = shift; - my $script = $self->{script}; + my $self = shift; + my $script = $self->{script}; my $appprefix = $self->{appprefix}; $self->render_file( 'server', "$script\/$appprefix\_server.pl" ); chmod 0700, "$script/$appprefix\_server.pl"; } sub _mk_test { - my $self = shift; - my $script = $self->{script}; + my $self = shift; + my $script = $self->{script}; my $appprefix = $self->{appprefix}; $self->render_file( 'test', "$script/$appprefix\_test.pl" ); chmod 0700, "$script/$appprefix\_test.pl"; } sub _mk_create { - my $self = shift; - my $script = $self->{script}; + my $self = shift; + my $script = $self->{script}; my $appprefix = $self->{appprefix}; $self->render_file( 'create', "$script\/$appprefix\_create.pl" ); chmod 0700, "$script/$appprefix\_create.pl"; @@ -414,22 +416,32 @@ our $VERSION = '0.01'; [% name %]->setup; -sub default : Private { - my ( $self, $c ) = @_; - $c->res->output('Congratulations, [% name %] is on Catalyst!'); -} - =head1 NAME -[% name %] - A very nice application +[% name %] - Catalyst based application =head1 SYNOPSIS - Very simple to use + script/[% appprefix %]_server.pl =head1 DESCRIPTION -Very nice application. +Catalyst based application. + +=head1 METHODS + +=over 4 + +=item default + +=cut + +sub default : Private { + my ( $self, $c ) = @_; + $c->res->output('Congratulations, [% name %] is on Catalyst!'); +} + +=back =head1 AUTHOR @@ -443,7 +455,36 @@ it under the same terms as perl itself. =cut 1; +__makefile__ + unless ( eval "use Module::Build::Compat 0.02; 1" ) { + print "This module requires Module::Build to install itself.\n"; + require ExtUtils::MakeMaker; + my $yn = + ExtUtils::MakeMaker::prompt( ' Install Module::Build now from CPAN?', 'y' ); + + unless ( $yn =~ /^y/i ) { + die " *** Cannot install without Module::Build. Exiting ...\n"; + } + + require Cwd; + require File::Spec; + require CPAN; + + # Save this 'cause CPAN will chdir all over the place. + my $cwd = Cwd::cwd(); + my $makefile = File::Spec->rel2abs($0); + + CPAN::Shell->install('Module::Build::Compat') + or die " *** Cannot install without Module::Build. Exiting ...\n"; + + chdir $cwd or die "Cannot chdir() back to $cwd: $!"; + } + eval "use Module::Build::Compat 0.02; 1" or die $@; + use lib '_build/lib'; + Module::Build::Compat->run_build_pl( args => \@ARGV ); + require Module::Build; + Module::Build::Compat->write_makefile( build_class => 'Module::Build' ); __build__ use strict; use Catalyst::Build; @@ -458,22 +499,17 @@ my $build = Catalyst::Build->new( test_files => [ glob('t/*.t'), glob('t/*/*.t') ] ); $build->create_build_script; - __readme__ -Run script/[% apprefix %]_server.pl to test the application. - +Run script/[% appprefix %]_server.pl to test the application. __changes__ This file documents the revision history for Perl extension [% name %]. - 0.01 [% time %] - initial revision, generated by Catalyst - __apptest__ use Test::More tests => 2; use_ok( Catalyst::Test, '[% name %]' ); ok( request('/')->is_success ); - __podtest__ use Test::More; @@ -482,7 +518,6 @@ plan skip_all => 'Test::Pod 1.14 required' if $@; plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; all_pod_files_ok(); - __podcoveragetest__ use Test::More; @@ -491,14 +526,18 @@ plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@; plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; all_pod_coverage_ok(); - __cgi__ [% startperl %] -w -BEGIN { $ENV{CATALYST_ENGINE} = 'CGI' } use strict; use FindBin; -use lib "$FindBin::Bin/../lib"; +use Path::Class; + +BEGIN { + $ENV{CATALYST_ENGINE} ||= 'CGI'; + use lib dir($FindBin::Bin)->parent->subdir('lib')->stringify; +} + use [% name %]; [% name %]->run; @@ -529,15 +568,18 @@ This library is free software. You can redistribute it and/or modify it under the same terms as perl itself. =cut - -__fcgi__ +__fastcgi__ [% startperl %] -w -BEGIN { $ENV{CATALYST_ENGINE} = 'FCGI' } - use strict; use FindBin; -use lib "$FindBin::Bin/../lib"; +use Path::Class; + +BEGIN { + $ENV{CATALYST_ENGINE} ||= 'FastCGI'; + use lib dir($FindBin::Bin)->parent->subdir('lib')->stringify; +} + use [% name %]; [% name %]->run; @@ -546,7 +588,7 @@ use [% name %]; =head1 NAME -fcgi - Catalyst FCGI +fastcgi - Catalyst FastCGI =head1 SYNOPSIS @@ -554,7 +596,7 @@ See L =head1 DESCRIPTION -Run a Catalyst application as fcgi. +Run a Catalyst application as fastcgi. =head1 AUTHOR @@ -568,20 +610,21 @@ This library is free software. You can redistribute it and/or modify it under the same terms as perl itself. =cut - __server__ [% startperl %] -w -BEGIN { - $ENV{CATALYST_ENGINE} = 'HTTP'; - $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %]; -} - use strict; use Getopt::Long; use Pod::Usage; use FindBin; -use lib "$FindBin::Bin/../lib"; +use Path::Class; + +BEGIN { + $ENV{CATALYST_ENGINE} ||= 'HTTP'; + $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %]; + use lib dir($FindBin::Bin)->parent->subdir('lib')->stringify; +} + use [% name %]; my $help = 0; @@ -627,17 +670,20 @@ This library is free software. You can redistribute it and/or modify it under the same terms as perl itself. =cut - __test__ [% startperl %] -w -BEGIN { $ENV{CATALYST_ENGINE} = 'Test' } - use strict; use Getopt::Long; use Pod::Usage; use FindBin; -use lib "$FindBin::Bin/../lib"; +use Path::Class; + +BEGIN { + $ENV{CATALYST_ENGINE} ||= 'Test'; + use lib dir($FindBin::Bin)->parent->subdir('lib')->stringify; +} + use [% name %]; my $help = 0; @@ -685,7 +731,6 @@ This library is free software. You can redistribute it and/or modify it under the same terms as perl itself. =cut - __create__ [% startperl %] -w @@ -724,7 +769,6 @@ create.pl [options] model|view|controller name [helper] [options] create.pl model My::Model create.pl model SomeDB CDBI dbi:SQLite:/tmp/my.db create.pl model AnotherDB CDBI dbi:Pg:dbname=foo root 4321 - create.pl Ajax See also: perldoc Catalyst::Manual @@ -746,32 +790,40 @@ This library is free software. You can redistribute it and/or modify it under the same terms as perl itself. =cut - __compclass__ package [% class %]; use strict; use base 'Catalyst::Base'; -[% IF type == 'C' %] -sub default : Private { - my ( $self, $c ) = @_; - $c->res->output('Congratulations, [% class %] is on Catalyst!'); -} - -[% END %] =head1 NAME -[% class %] - A Component +[% class %] - Catalyst component =head1 SYNOPSIS - Very simple to use +See L<[% app %]> =head1 DESCRIPTION -Very nice component. +Catalyst component. +[% IF type == 'C' %] +=head1 METHODS + +=over 4 + +=item default + +=cut +sub default : Private { + my ( $self, $c ) = @_; + $c->res->output('Congratulations, [% class %] is on Catalyst!'); +} + +=back + +[% END %] =head1 AUTHOR [%author%] @@ -784,7 +836,6 @@ it under the same terms as perl itself. =cut 1; - __comptest__ [% IF type == 'C' %] use Test::More tests => 3;