X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;h=e3176e5b9aef7b9d88584c7790e767701e746ebc;hb=9bc8b354901fa65de2f8cdd64f0732df05a1668a;hp=921ca54f0286993547fc828c99a58f347dd6d1da;hpb=902763f23d9d7a9a6fbb5fa188c4a8e51c908170;p=catagits%2FCatalyst-Devel.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index 921ca54..e3176e5 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -1,37 +1,28 @@ package Catalyst::Helper; use strict; +use warnings; 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; 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 @@ -51,12 +42,6 @@ sub get_file { return 0; } -=head3 mk_app - -Create the main application skeleton. - -=cut - sub mk_app { my ( $self, $name ) = @_; @@ -72,8 +57,11 @@ sub mk_app { $self->{dir } =~ s/\:\:/-/g; $self->{script } = File::Spec->catdir( $self->{dir}, 'script' ); $self->{appprefix } = Catalyst::Utils::appprefix($name); - $self->{startperl } = "#!$Config{perlpath} -w"; - $self->{scriptgen } = $Catalyst::CATALYST_SCRIPT_GEN || 4; + $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; $self->{catalyst_version} = $Catalyst::VERSION; $self->{author } = $self->{author} = $ENV{'AUTHOR'} || eval { @{ [ getpwuid($<) ] }[6] } @@ -107,13 +95,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; @@ -142,7 +123,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; @@ -204,12 +185,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 ) { @@ -224,12 +199,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 ) { @@ -256,10 +225,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" } @@ -280,13 +245,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 ||= {}; @@ -373,7 +331,7 @@ sub _mk_config { my $dir = $self->{dir}; my $appprefix = $self->{appprefix}; $self->render_file( 'config', - File::Spec->catfile( $dir, "$appprefix.yml" ) ); + File::Spec->catfile( $dir, "$appprefix.conf" ) ); } sub _mk_readme { @@ -385,7 +343,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 } ); } @@ -493,19 +451,58 @@ 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 -examples. +See L and +L for examples. All helper classes should be under one of the following namespaces. @@ -513,6 +510,78 @@ 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 ($file, $path, $vars) + +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