Revamped how the restarter stuff works so it's totally separate from
[catagits/Catalyst-Devel.git] / lib / Catalyst / Helper.pm
index d9987e9..2e7b94b 100644 (file)
@@ -58,7 +58,9 @@ 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       } = "#!$Config{perlpath} -w";
+    $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'}
@@ -89,6 +91,7 @@ sub mk_app {
         $self->_mk_server;
         $self->_mk_test;
         $self->_mk_create;
+        $self->_mk_information;
     }
     return $self->{dir};
 }
@@ -256,6 +259,11 @@ sub render_file {
     $self->mk_file( $path, $output );
 }
 
+sub _mk_information {
+    my $self = shift;
+    print qq/Change to application directory and Run "perl Makefile.PL" to make sure your install is complete\n/;
+}
+
 sub _mk_dirs {
     my $self = shift;
     $self->mk_dir( $self->{dir} );
@@ -508,6 +516,34 @@ All helper classes should be under one of the following namespaces.
     Catalyst::Helper::View::
     Catalyst::Helper::Controller::
 
+=head2 COMMON HELPERS 
+
+=over
+
+=item *
+
+L<Catalyst::Helper::Model::DBIC::Schema> - DBIx::Class models
+
+=item *
+
+L<Catalyst::Helper::View::TT> - Template Toolkit view
+
+=item *
+
+L<Catalyst::Helper::Model::LDAP>
+
+=item *
+
+L<Catalyst::Helper::Model::Adaptor> - wrap any class into a Catalyst model
+
+=back
+
+=head3 NOTE
+
+The helpers will read author name from /etc/passwd by default. + To override, please export the AUTHOR variable. 
+
+=head1 METHODS
+
 =head2 mk_compclass
 
 This method in your Helper module is called with C<$helper>
@@ -539,7 +575,7 @@ arguments the user typed.
 
 There is no fallback for this method.
 
-=head1 METHODS
+=head1 INTERNAL METHODS
 
 These are the methods that the Helper classes can call on the
 <$helper> object passed to them.
@@ -596,7 +632,7 @@ Catalyst Contributors, see Catalyst.pm
 
 =head1 LICENSE
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =begin pod_to_ignore
@@ -619,7 +655,7 @@ use Catalyst::Runtime '5.70';
 #         -Debug: activates the debug mode for very useful log messages
 #   ConfigLoader: will load the configuration from a Config::General file in the
 #                 application's home directory
-# Static::Simple: will serve static files from the application's root 
+# Static::Simple: will serve static files from the application's root
 #                 directory
 
 use parent qw/Catalyst/;
@@ -628,13 +664,13 @@ use Catalyst qw/-Debug
                 Static::Simple/;
 our $VERSION = '0.01';
 
-# Configure the application. 
+# Configure the application.
 #
 # Note that settings in [% appprefix %].conf (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
+# with an external configuration file acting as an override for
 # local deployment.
 
 __PACKAGE__->config( name => '[% name %]' );
@@ -665,7 +701,7 @@ L<[% rootname %]>, L<Catalyst>
 
 =head1 LICENSE
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut
@@ -711,14 +747,13 @@ 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 
+=cut
 
 sub end : ActionClass('RenderView') {}
 
@@ -728,7 +763,7 @@ sub end : ActionClass('RenderView') {}
 
 =head1 LICENSE
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut
@@ -827,7 +862,7 @@ Catalyst Contributors, see Catalyst.pm
 =head1 COPYRIGHT
 
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut
@@ -846,7 +881,7 @@ use [% name %];
 
 my $help = 0;
 my ( $listen, $nproc, $pidfile, $manager, $detach, $keep_stderr );
+
 GetOptions(
     'help|?'      => \$help,
     'listen|l=s'  => \$listen,
@@ -859,10 +894,10 @@ GetOptions(
 
 pod2usage(1) if $help;
 
-[% name %]->run( 
-    $listen, 
+[% name %]->run(
+    $listen,
     {   nproc   => $nproc,
-        pidfile => $pidfile, 
+        pidfile => $pidfile,
         manager => $manager,
         detach  => $detach,
        keep_stderr => $keep_stderr,
@@ -878,7 +913,7 @@ pod2usage(1) if $help;
 =head1 SYNOPSIS
 
 [% appprefix %]_fastcgi.pl [options]
+
  Options:
    -? -help      display this help and exits
    -l -listen    Socket path to listen on
@@ -907,18 +942,18 @@ Catalyst Contributors, see Catalyst.pm
 
 =head1 COPYRIGHT
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut
 __server__
 [% startperl %]
 
-BEGIN { 
+BEGIN {
     $ENV{CATALYST_ENGINE} ||= 'HTTP';
     $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %];
     require Catalyst::Engine::HTTP;
-}  
+}
 
 use strict;
 use warnings;
@@ -934,50 +969,74 @@ 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 $check_interval;
+my $file_regex;
+my $watch_directory;
+my $follow_symlinks;
 
 my @argv = @ARGV;
 
 GetOptions(
     'debug|d'             => \$debug,
-    'fork'                => \$fork,
+    'fork|f'              => \$fork,
     'help|?'              => \$help,
     'host=s'              => \$host,
     '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,
 );
 
 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,
-} );
+# If we load this here, then in the case of a restarter, it does not
+# need to be reloaded for each restart.
+require Catalyst;
+
+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,
+        }
+    );
+};
+
+if ( $restart ) {
+    require Catalyst::Restarter;
+
+    my %args;
+    $args{watch_directory} = $watch_directory
+        if defined $watch_directory;
+    $args{check_interval} = $check_interval
+        if defined $check_interval;
+    $args{file_regex} = qr/$file_regex/
+        if defined $file_regex;
+
+    my $restarter = Catalyst::Restarter->new(
+        %args,
+        restart_sub => $runner,
+    );
+
+    $restarter->run_and_watch;
+}
+else {
+    $runner->();
+}
 
 1;
 
@@ -1008,6 +1067,7 @@ require [% name %];
                       (defaults to '[SCRIPT_DIR]/..')
    -follow_symlinks   follow symlinks in search directories
                       (defaults to false. this is a no-op on Win32)
+   -background        run the process in the background
  See also:
    perldoc Catalyst::Manual
    perldoc Catalyst::Manual::Intro
@@ -1022,7 +1082,7 @@ Catalyst Contributors, see Catalyst.pm
 
 =head1 COPYRIGHT
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut
@@ -1076,7 +1136,7 @@ Catalyst Contributors, see Catalyst.pm
 
 =head1 COPYRIGHT
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut
@@ -1087,7 +1147,7 @@ use strict;
 use warnings;
 use Getopt::Long;
 use Pod::Usage;
-eval "use Catalyst::Devel;";
+eval "use Catalyst::Helper;";
 
 if ($@) {
   die <<END;
@@ -1163,7 +1223,7 @@ Catalyst Contributors, see Catalyst.pm
 
 =head1 COPYRIGHT
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut
@@ -1187,7 +1247,7 @@ Catalyst [% long_type %].
 =cut
 
 
-=head2 index 
+=head2 index
 
 =cut
 
@@ -1204,7 +1264,7 @@ sub index :Path :Args(0) {
 
 =head1 LICENSE
 
-This library is free software, you can redistribute it and/or modify
+This library is free software. You can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut