Back out - what the hell was the unexpected hunk. I fail at today.
[catagits/Catalyst-Devel.git] / lib / Catalyst / Helper.pm
index 6db579f..8ab9ad2 100644 (file)
@@ -48,7 +48,7 @@ sub mk_app {
     # Needs to be here for PAR
     require Catalyst;
 
-    if ( $name =~ /[^\w\:]/ ) {
+    if ( $name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
         warn "Error: Invalid application name.\n";
         return 0;
     }
@@ -58,8 +58,8 @@ sub mk_app {
     $self->{script          } = File::Spec->catdir( $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' 
+    $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;
@@ -516,7 +516,7 @@ All helper classes should be under one of the following namespaces.
     Catalyst::Helper::View::
     Catalyst::Helper::Controller::
 
-=head2 COMMON HELPERS 
+=head2 COMMON HELPERS
 
 =over
 
@@ -540,7 +540,7 @@ L<Catalyst::Helper::Model::Adaptor> - 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
 
@@ -648,7 +648,7 @@ package [% name %];
 use strict;
 use warnings;
 
-use Catalyst::Runtime '5.70';
+use Catalyst::Runtime 5.80;
 
 # Set flags and add plugins for the application
 #
@@ -770,8 +770,9 @@ it under the same terms as Perl itself.
 
 1;
 __makefile__
+[% startperl %]
 # IMPORTANT: if you delete this file your app will not work as
-# expected.  you have been warned
+# expected.  You have been warned.
 use inc::Module::Install;
 
 name '[% dir %]';
@@ -790,8 +791,8 @@ install_script glob('script/*.pl');
 auto_install;
 WriteAll;
 __config__
-# rename this file to [% name %].yml and put a : in front of "name" if
-# you want to use yaml like in old versions of Catalyst
+# rename this file to [% name %].yml and put a ':' in front of 'name' if
+# you want to use YAML like in old versions of Catalyst
 name [% name %]
 __readme__
 Run script/[% appprefix %]_server.pl to test the application.
@@ -801,6 +802,7 @@ This file documents the revision history for Perl extension [% name %].
 0.01  [% time %]
         - initial revision, generated by Catalyst
 __apptest__
+[% startperl %]
 use strict;
 use warnings;
 use Test::More tests => 2;
@@ -809,6 +811,7 @@ BEGIN { use_ok 'Catalyst::Test', '[% name %]' }
 
 ok( request('/')->is_success, 'Request should succeed' );
 __podtest__
+[% startperl %]
 use strict;
 use warnings;
 use Test::More;
@@ -819,6 +822,7 @@ plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
 
 all_pod_files_ok();
 __podcoveragetest__
+[% startperl %]
 use strict;
 use warnings;
 use Test::More;
@@ -900,7 +904,7 @@ pod2usage(1) if $help;
         pidfile => $pidfile,
         manager => $manager,
         detach  => $detach,
-       keep_stderr => $keep_stderr,
+        keep_stderr => $keep_stderr,
     }
 );
 
@@ -969,11 +973,13 @@ my $host              = undef;
 my $port              = $ENV{[% appenv %]_PORT} || $ENV{CATALYST_PORT} || 3000;
 my $keepalive         = 0;
 my $restart           = $ENV{[% appenv %]_RELOAD} || $ENV{CATALYST_RELOAD} || 0;
-my $restart_delay     = 1;
-my $restart_regex     = '(?:/|^)(?!\.#).+(?:\.yml$|\.yaml$|\.conf|\.pm)$';
-my $restart_directory = undef;
-my $follow_symlinks   = 0;
 my $background        = 0;
+my $pidfile           = undef;
+
+my $check_interval;
+my $file_regex;
+my $watch_directory;
+my $follow_symlinks;
 
 my @argv = @ARGV;
 
@@ -985,37 +991,73 @@ GetOptions(
     'port=s'              => \$port,
     'keepalive|k'         => \$keepalive,
     'restart|r'           => \$restart,
-    'restartdelay|rd=s'   => \$restart_delay,
-    'restartregex|rr=s'   => \$restart_regex,
-    'restartdirectory=s@' => \$restart_directory,
+    'restartdelay|rd=s'   => \$check_interval,
+    'restartregex|rr=s'   => \$file_regex,
+    'restartdirectory=s@' => \$watch_directory,
     'followsymlinks'      => \$follow_symlinks,
     'background'          => \$background,
+    'pidfile=s'           => \$pidfile,
 );
 
 pod2usage(1) if $help;
 
-if ( $restart && $ENV{CATALYST_ENGINE} eq 'HTTP' ) {
-    $ENV{CATALYST_ENGINE} = 'HTTP::Restarter';
-}
 if ( $debug ) {
     $ENV{CATALYST_DEBUG} = 1;
 }
 
-# This is require instead of use so that the above environment
-# variables can be set at runtime.
-require [% name %];
-
-[% name %]->run( $port, $host, {
-    argv              => \@argv,
-    'fork'            => $fork,
-    keepalive         => $keepalive,
-    restart           => $restart,
-    restart_delay     => $restart_delay,
-    restart_regex     => qr/$restart_regex/,
-    restart_directory => $restart_directory,
-    follow_symlinks   => $follow_symlinks,
-    background        => $background,
-} );
+# If we load this here, then in the case of a restarter, it does not
+# need to be reloaded for each restart.
+require Catalyst;
+
+# If this isn't done, then the Catalyst::Devel tests for the restarter
+# fail.
+$| = 1 if $ENV{HARNESS_ACTIVE};
+
+my $runner = sub {
+    # This is require instead of use so that the above environment
+    # variables can be set at runtime.
+    require [% name %];
+
+    [% name %]->run(
+        $port, $host,
+        {
+            argv       => \@argv,
+            'fork'     => $fork,
+            keepalive  => $keepalive,
+            background => $background,
+            pidfile    => $pidfile,
+        }
+    );
+};
+
+if ( $restart ) {
+    die "Cannot run in the background and also watch for changed files.\n"
+        if $background;
+
+    require Catalyst::Restarter;
+
+    my $subclass = Catalyst::Restarter->pick_subclass;
+
+    my %args;
+    $args{follow_symlinks} = 1
+        if $follow_symlinks;
+    $args{directories} = $watch_directory
+        if defined $watch_directory;
+    $args{sleep_interval} = $check_interval
+        if defined $check_interval;
+    $args{filter} = qr/$file_regex/
+        if defined $file_regex;
+
+    my $restarter = $subclass->new(
+        %args,
+        start_sub => $runner,
+    );
+
+    $restarter->run_and_watch;
+}
+else {
+    $runner->();
+}
 
 1;
 
@@ -1038,6 +1080,7 @@ require [% name %];
    -r -restart        restart when files get modified
                       (defaults to false)
    -rd -restartdelay  delay between file checks
+                      (ignored if you have Linux::Inotify2 installed)
    -rr -restartregex  regex match files that trigger
                       a restart when modified
                       (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
@@ -1047,6 +1090,8 @@ require [% name %];
    -follow_symlinks   follow symlinks in search directories
                       (defaults to false. this is a no-op on Win32)
    -background        run the process in the background
+   -pidfile           specify filename for pid file
+
  See also:
    perldoc Catalyst::Manual
    perldoc Catalyst::Manual::Intro
@@ -1173,7 +1218,6 @@ 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