X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;h=c12e994d4faff3036e43dffa4954a33f9b7b0c3d;hb=93159e2580327e21aefb9e65a041e3dfd1073a7c;hp=a6a36e035812cf970d7e33b7a46f4e31b2000567;hpb=9ffb6b831e52a98ed741cf1bfb43fd75f1c44a4f;p=catagits%2FCatalyst-Devel.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index a6a36e0..c12e994 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -6,8 +6,9 @@ use base 'Class::Accessor::Fast'; use Config; use File::Spec; use File::Path; -use IO::File; use FindBin; +use IO::File; +use POSIX 'strftime'; use Template; use Catalyst::Devel; use Catalyst::Utils; @@ -15,25 +16,13 @@ use Catalyst::Exception; my %cache; -our $VERSION = '1.00'; - =head1 NAME Catalyst::Helper - Bootstrap a Catalyst application =head1 SYNOPSIS -See L - -=head1 DESCRIPTION - -Bootstrap a Catalyst application. Autogenerates scripts - -=head2 METHODS - -=head3 get_file - -Slurp file from DATA. + catalyst.pl =cut @@ -53,12 +42,6 @@ sub get_file { return 0; } -=head3 mk_app - -Create the main application skeleton. - -=cut - sub mk_app { my ( $self, $name ) = @_; @@ -74,6 +57,7 @@ sub mk_app { $self->{dir } =~ s/\:\:/-/g; $self->{script } = File::Spec->catdir( $self->{dir}, 'script' ); $self->{appprefix } = Catalyst::Utils::appprefix($name); + $self->{appenv } = Catalyst::Utils::class2env($name); $self->{startperl } = "#!$Config{perlpath} -w"; $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN || 4; $self->{catalyst_version} = $Catalyst::VERSION; @@ -109,13 +93,6 @@ sub mk_app { return $self->{dir}; } -=head3 mk_component - -This method is called by create.pl to make new components -for your application. - -=cut - sub mk_component { my $self = shift; my $app = shift; @@ -144,7 +121,7 @@ sub mk_component { my $name = shift || "Missing name for model/view/controller"; my $helper = shift; my @args = @_; - return 0 if $name =~ /[^\w\:]/; + return 0 if $name =~ /[^\w\:]/; $type = lc $type; $self->{long_type} = ucfirst $type; $type = 'M' if $type =~ /model/i; @@ -206,12 +183,6 @@ sub mk_component { return 1; } -=head3 mk_dir - -Surprisingly, this function makes a directory. - -=cut - sub mk_dir { my ( $self, $dir ) = @_; if ( -d $dir ) { @@ -226,12 +197,6 @@ sub mk_dir { Catalyst::Exception->throw( message => qq/Couldn't create "$dir", "$!"/ ); } -=head3 mk_file - -writes content to a file. - -=cut - sub mk_file { my ( $self, $file, $content ) = @_; if ( -e $file ) { @@ -258,10 +223,6 @@ sub mk_file { Catalyst::Exception->throw( message => qq/Couldn't create "$file", "$!"/ ); } -=head3 next_test - -=cut - sub next_test { my ( $self, $tname ) = @_; if ($tname) { $tname = "$tname.t" } @@ -282,13 +243,6 @@ sub next_test { return File::Spec->catfile( $dir, "$type\_$tname" ); } -=head3 render_file - -Render and create a file from a template in DATA using -Template Toolkit. - -=cut - sub render_file { my ( $self, $file, $path, $vars ) = @_; $vars ||= {}; @@ -387,7 +341,7 @@ sub _mk_readme { sub _mk_changes { my $self = shift; my $dir = $self->{dir}; - my $time = localtime time; + my $time = strftime('%Y-%m-%d %H:%M:%S', localtime time); $self->render_file( 'changes', "$dir\/Changes", { time => $time } ); } @@ -495,15 +449,54 @@ sub _deprecate_file { } } +=head1 DESCRIPTION + +This module is used by B to create a set of scripts for a +new catalyst application. The scripts each contain documentation and +will output help on how to use them if called incorrectly or in some +cases, with no arguments. + +It also provides some useful methods for a Helper module to call when +creating a component. See L. + +=head1 SCRIPTS + +=head2 _create.pl + +Used to create new components for a catalyst application at the +development stage. + +=head2 _server.pl + +The catalyst test server, starts an HTTPD which outputs debugging to +the terminal. + +=head2 _test.pl + +A script for running tests from the command-line. + +=head2 _cgi.pl + +Run your application as a CGI. + +=head2 _fastcgi.pl + +Run the application as a fastcgi app. Either by hand, or call this +from FastCgiServer in your http server config. + =head1 HELPERS +The L script creates application components using Helper +modules. The Catalyst team provides a good number of Helper modules +for you to use. You can also add your own. + Helpers are classes that provide two methods. * mk_compclass - creates the Component class * mk_comptest - creates the Component test -So when you call C, create would try to execute -Catalyst::Helper::View::TT->mk_compclass and +So when you call C, create +will try to execute Catalyst::Helper::View::TT->mk_compclass and Catalyst::Helper::View::TT->mk_comptest. See L and L for @@ -515,6 +508,73 @@ All helper classes should be under one of the following namespaces. Catalyst::Helper::View:: Catalyst::Helper::Controller:: +=head2 mk_compclass + +This method in your Helper module is called with C<$helper> +which is a L object, and whichever other arguments +the user added to the command-line. You can use the $helper to call methods +described below. + +If the Helper module does not contain a C method, it +will fall back to calling L, with an argument of +C. + +=head2 mk_comptest + +This method in your Helper module is called with C<$helper> +which is a L object, and whichever other arguments +the user added to the command-line. You can use the $helper to call methods +described below. + +If the Helper module does not contain a C method, it +will fall back to calling L, with an argument of +C. + +=head2 mk_stuff + +This method is called if the user does not supply any of the usual +component types C, C, C. It is passed the +C<$helper> object (an instance of L), and any other +arguments the user typed. + +There is no fallback for this method. + +=head1 METHODS + +These are the methods that the Helper classes can call on the +<$helper> object passed to them. + +=head2 render_file + +Render and create a file from a template in DATA using +Template Toolkit. + +=head2 get_file + +Fetch file contents from the DATA section. This is used internally by +L. + +=head2 mk_app + +Create the main application skeleton. This is called by L. + +=head2 mk_component + +This method is called by L to make new components +for your application. + +=head3 mk_dir + +Surprisingly, this function makes a directory. + +=head2 mk_file + +Writes content to a file. Called by L. + +=head2 next_test + +Calculates the name of the next numbered test file and returns it. + =head1 NOTE The helpers will read author name from /etc/passwd by default. @@ -549,7 +609,6 @@ use warnings; use Catalyst::Runtime '5.70'; -# # Set flags and add plugins for the application # # -Debug: activates the debug mode for very useful log messages @@ -557,29 +616,25 @@ use Catalyst::Runtime '5.70'; # application's home directory # Static::Simple: will serve static files from the application's root # directory -# -use Catalyst qw/-Debug ConfigLoader Static::Simple/; + +use parent qw/Catalyst/; our $VERSION = '0.01'; -# # Configure the application. # -# Note that settings in [% name %].yml take precedence over -# this when using ConfigLoader. Thus configuration details -# given here can function as a default configuration, with a -# YAML file acting as an override for local deployment. -# +# Note that settings in [% appprefix %].yml (or other external +# configuration file that you set up manually) take precedence +# over this when using ConfigLoader. Thus configuration +# details given here can function as a default configuration, +# with a external configuration file acting as an override for +# local deployment. + __PACKAGE__->config( name => '[% name %]' ); -# # Start the application -# -__PACKAGE__->setup; +__PACKAGE__->setup(qw/-Debug ConfigLoader Static::Simple/); -# -# IMPORTANT: Please look into [% rootname %] for more -# =head1 NAME @@ -591,7 +646,7 @@ __PACKAGE__->setup; =head1 DESCRIPTION -Catalyst based application. +[enter your description here] =head1 SEE ALSO @@ -614,7 +669,7 @@ package [% rootname %]; use strict; use warnings; -use base 'Catalyst::Controller'; +use parent 'Catalyst::Controller'; # # Sets the actions in this controller to be registered with no prefix @@ -624,47 +679,41 @@ __PACKAGE__->config->{namespace} = ''; =head1 NAME -[% rootname %] - Root Controller for this Catalyst based application - -=head1 SYNOPSIS - -See L<[% name %]>. +[% rootname %] - Root Controller for [% name %] =head1 DESCRIPTION -Root Controller for this Catalyst based application. +[enter your description here] =head1 METHODS =cut -=head2 default +=head2 index =cut -# -# Output a friendly welcome message -# -sub default : Private { +sub index : Path Args(0) { my ( $self, $c ) = @_; # Hello World $c->response->body( $c->welcome_message ); } -# -# Uncomment and modify this end action after adding a View component -# -#=head2 end -# -#=cut -# -#sub end : Private { -# my ( $self, $c ) = @_; -# -# # Forward to View unless response body is already defined -# $c->forward( $c->view('') ) unless $c->response->body; -#} +sub default : Path { + my ( $self, $c ) = @_; + $c->response->body( 'Page not found' ); + $c->response->status(404); + +} + +=head2 end + +Attempt to render a view, if needed. + +=cut + +sub end : ActionClass('RenderView') {} =head1 AUTHOR @@ -684,9 +733,13 @@ use inc::Module::Install; name '[% dir %]'; all_from '[% path %]'; -requires Catalyst => '[% catalyst_version %]'; -requires YAML; # This should reflect the config file format you've chosen - # See Catalyst::Plugin::ConfigLoader for supported formats +requires 'Catalyst::Runtime' => '[% catalyst_version %]'; +requires 'Catalyst::Plugin::ConfigLoader'; +requires 'Catalyst::Plugin::Static::Simple'; +requires 'Catalyst::Action::RenderView'; +requires 'parent'; +requires 'YAML'; # This should reflect the config file format you've chosen + # See Catalyst::Plugin::ConfigLoader for supported formats catalyst; install_script glob('script/*.pl'); @@ -755,7 +808,7 @@ See L =head1 DESCRIPTION -Run a Catalyst application as cgi. +Run a Catalyst application as a cgi script. =head1 AUTHOR @@ -763,7 +816,6 @@ Sebastian Riedel, C =head1 COPYRIGHT -Copyright 2004 Sebastian Riedel. All rights reserved. This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. @@ -783,7 +835,7 @@ use lib "$FindBin::Bin/../lib"; use [% name %]; my $help = 0; -my ( $listen, $nproc, $pidfile, $manager, $detach ); +my ( $listen, $nproc, $pidfile, $manager, $detach, $keep_stderr ); GetOptions( 'help|?' => \$help, @@ -792,6 +844,7 @@ GetOptions( 'pidfile|p=s' => \$pidfile, 'manager|M=s' => \$manager, 'daemon|d' => \$detach, + 'keeperr|e' => \$keep_stderr, ); pod2usage(1) if $help; @@ -802,6 +855,7 @@ pod2usage(1) if $help; pidfile => $pidfile, manager => $manager, detach => $detach, + keep_stderr => $keep_stderr, } ); @@ -830,6 +884,8 @@ pod2usage(1) if $help; -M -manager specify alternate process manager (FCGI::ProcManager sub-class) or empty string to disable + -e -keeperr send error messages to STDOUT, not + to the webserver =head1 DESCRIPTION @@ -838,11 +894,10 @@ Run a Catalyst application as fastcgi. =head1 AUTHOR Sebastian Riedel, C +Maintained by the Catalyst Core Team. =head1 COPYRIGHT -Copyright 2004 Sebastian Riedel. All rights reserved. - This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. @@ -853,6 +908,7 @@ __server__ BEGIN { $ENV{CATALYST_ENGINE} ||= 'HTTP'; $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %]; + require Catalyst::Engine::HTTP; } use strict; @@ -866,12 +922,13 @@ my $debug = 0; my $fork = 0; my $help = 0; my $host = undef; -my $port = 3000; +my $port = $ENV{[% appenv %]_PORT} || $ENV{CATALYST_PORT} || 3000; my $keepalive = 0; -my $restart = 0; +my $restart = $ENV{[% appenv %]_RELOAD} || $ENV{CATALYST_RELOAD} || 0; my $restart_delay = 1; -my $restart_regex = '\.yml$|\.yaml$|\.pm$'; +my $restart_regex = '(?:/|^)(?!\.#).+(?:\.yml$|\.yaml$|\.pm)$'; my $restart_directory = undef; +my $follow_symlinks = 0; my @argv = @ARGV; @@ -885,12 +942,13 @@ GetOptions( 'restart|r' => \$restart, 'restartdelay|rd=s' => \$restart_delay, 'restartregex|rr=s' => \$restart_regex, - 'restartdirectory=s' => \$restart_directory, + 'restartdirectory=s@' => \$restart_directory, + 'followsymlinks' => \$follow_symlinks, ); pod2usage(1) if $help; -if ( $restart ) { +if ( $restart && $ENV{CATALYST_ENGINE} eq 'HTTP' ) { $ENV{CATALYST_ENGINE} = 'HTTP::Restarter'; } if ( $debug ) { @@ -909,6 +967,7 @@ require [% name %]; restart_delay => $restart_delay, restart_regex => qr/$restart_regex/, restart_directory => $restart_directory, + follow_symlinks => $follow_symlinks, } ); 1; @@ -929,16 +988,17 @@ require [% name %]; -host host (defaults to all) -p -port port (defaults to 3000) -k -keepalive enable keep-alive connections - -r -restart restart when files got modified + -r -restart restart when files get modified (defaults to false) -rd -restartdelay delay between file checks -rr -restartregex regex match files that trigger a restart when modified (defaults to '\.yml$|\.yaml$|\.pm$') -restartdirectory the directory to search for - modified files - (defaults to '../') - + modified files, can be set mulitple times + (defaults to '[SCRIPT_DIR]/..') + -follow_symlinks follow symlinks in search directories + (defaults to false. this is a no-op on Win32) See also: perldoc Catalyst::Manual perldoc Catalyst::Manual::Intro @@ -950,11 +1010,10 @@ Run a Catalyst Testserver for this application. =head1 AUTHOR Sebastian Riedel, C +Maintained by the Catalyst Core Team. =head1 COPYRIGHT -Copyright 2004 Sebastian Riedel. All rights reserved. - This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. @@ -1006,11 +1065,10 @@ Run a Catalyst action from the command line. =head1 AUTHOR Sebastian Riedel, C +Maintained by the Catalyst Core Team. =head1 COPYRIGHT -Copyright 2004 Sebastian Riedel. All rights reserved. - This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. @@ -1057,13 +1115,16 @@ pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV ); Examples: [% appprefix %]_create.pl controller My::Controller + [% appprefix %]_create.pl controller My::Controller BindLex [% appprefix %]_create.pl -mechanize controller My::Controller [% appprefix %]_create.pl view My::View [% appprefix %]_create.pl view MyView TT [% appprefix %]_create.pl view TT TT [% appprefix %]_create.pl model My::Model - [% appprefix %]_create.pl model SomeDB DBIC::SchemaLoader dbi:SQLite:/tmp/my.db - [% appprefix %]_create.pl model AnotherDB DBIC::SchemaLoader dbi:Pg:dbname=foo root 4321 + [% appprefix %]_create.pl model SomeDB DBIC::Schema MyApp::Schema create=dynamic\ + dbi:SQLite:/tmp/my.db + [% appprefix %]_create.pl model AnotherDB DBIC::Schema MyApp::Schema create=static\ + dbi:Pg:dbname=foo root 4321 See also: perldoc Catalyst::Manual @@ -1080,11 +1141,10 @@ This behavior can be suppressed with the C<-force> option. =head1 AUTHOR Sebastian Riedel, C +Maintained by the Catalyst Core Team. =head1 COPYRIGHT -Copyright 2004 Sebastian Riedel. All rights reserved. - This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. @@ -1094,16 +1154,12 @@ package [% class %]; use strict; use warnings; -use base 'Catalyst::[% long_type %]'; +use parent 'Catalyst::[% long_type %]'; =head1 NAME [% class %] - Catalyst [% long_type %] -=head1 SYNOPSIS - -See L<[% app %]> - =head1 DESCRIPTION Catalyst [% long_type %]. @@ -1112,19 +1168,16 @@ Catalyst [% long_type %]. =cut -# -# Uncomment and modify this or add new actions to fit your needs -# -#=head2 default -# -#=cut -# -#sub default : Private { -# my ( $self, $c ) = @_; -# -# # Hello World -# $c->response->body('[% class %] is on Catalyst!'); -#} + +=head2 index + +=cut + +sub index : Private { + my ( $self, $c ) = @_; + + $c->response->body('Matched [% class %] in [%name%].'); +} [% END %] =head1 AUTHOR