[Catalyst-commits] r11298 - in Catalyst-Runtime/5.80/branches/better_scripts: . lib/Catalyst lib/Catalyst/Script

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Wed Sep 2 00:48:55 GMT 2009


Author: t0m
Date: 2009-09-02 00:48:54 +0000 (Wed, 02 Sep 2009)
New Revision: 11298

Added:
   Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRole.pm
Modified:
   Catalyst-Runtime/5.80/branches/better_scripts/
   Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/CGI.pm
   Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Create.pm
   Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/FastCGI.pm
   Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Server.pm
   Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Test.pm
   Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRunner.pm
Log:
 r11291 at t0mlaptop:  t0m | 2009-09-02 01:14:00 +0100
 Factor stuff out into a script role, clean up all the script code



Property changes on: Catalyst-Runtime/5.80/branches/better_scripts
___________________________________________________________________
Name: svk:merge
   - 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/branches/compres:7999
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/branches/context_go:8001
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:8533
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/Catalyst-Test-Updates:8363
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/add_captures_to_visit:9546
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7911
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/trunk:10614
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
6d45476b-5895-46b8-b13a-8b969fa34c98:/local/Catalyst-Runtime-better_scripts:11290
8a9521aa-ff93-41d6-9f87-b05cafcdab40:/local/cat/Catalyst-Runtime/5.80/trunk:8157
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
   + 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/branches/compres:7999
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/branches/context_go:8001
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:8533
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/Catalyst-Test-Updates:8363
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/add_captures_to_visit:9546
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7911
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/trunk:10614
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
6d45476b-5895-46b8-b13a-8b969fa34c98:/local/Catalyst-Runtime-better_scripts:11291
8a9521aa-ff93-41d6-9f87-b05cafcdab40:/local/cat/Catalyst-Runtime/5.80/trunk:8157
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442

Modified: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/CGI.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/CGI.pm	2009-09-02 00:48:47 UTC (rev 11297)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/CGI.pm	2009-09-02 00:48:54 UTC (rev 11298)
@@ -1,39 +1,31 @@
 package Catalyst::Script::CGI;
 use Moose;
-
 BEGIN { $ENV{CATALYST_ENGINE} ||= 'CGI' }
-use FindBin qw/$Bin/;
-use lib "$Bin/../lib";
-use Pod::Usage;
-use Moose;
 use namespace::autoclean;
 
-with 'MooseX::Getopt';
+with 'Catalyst::ScriptRole';
 
-has _app => (
-    reader   => 'app',
-    init_arg => 'app',
-    traits => [qw(NoGetopt)],
-    isa => 'Str',
-    is => 'ro',
-);
+__PACKAGE__->meta->make_immutable;
 
-has help => (
-    traits => [qw(Getopt)],
-    cmd_aliases => 'h',
-    isa => 'Bool',
-    is => 'ro',
-    documentation => qq{ display this help and exits },
-);
+=head1 NAME
 
+Catalyst::Script::CGI - The CGI Catalyst Script
 
-sub run {
-    my $self = shift;
+=head1 SYNOPSIS
 
-    pod2usage() if $self->help;
-    my $app = $self->app;
-    Class::MOP::load_class($app);
-    $app->run;
+See L<Catalyst>.
 
-}
-1;
+=head1 DESCRIPTION
+
+FIXME
+
+=head1 AUTHORS
+
+Catalyst Contributors, see Catalyst.pm
+
+=head1 COPYRIGHT
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut

Modified: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Create.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Create.pm	2009-09-02 00:48:47 UTC (rev 11297)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Create.pm	2009-09-02 00:48:54 UTC (rev 11298)
@@ -1,63 +1,40 @@
 package Catalyst::Script::Create;
 use Moose;
-use Pod::Usage;
 use Catalyst::Helper;
-use MooseX::Types::Moose qw/Str Bool/;
+use MooseX::Types::Moose qw/Bool/;
 use namespace::autoclean;
 
-with "MooseX::Getopt";
-#extends qw(MooseX::App::Cmd);
+with 'Catalyst::ScriptRole';
 
-
-has _app => (
-    reader   => 'app',
-    init_arg => 'app',
-    traits => [qw(NoGetopt)],
-    isa => Str,
-    is => 'ro',
-);
-
 has force => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'nonew',
     isa => Bool,
     is => 'ro',
-    documentation => qq{ force new scripts }
+    documentation => 'Force new scripts',
 );
 
-has help => (
-    traits => [qw(Getopt)],
-    cmd_aliases => 'h',
-    isa => Bool,
-    is => 'ro',
-    documentation => qq{ display this help and exits },
-);
-
 has debug => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'd',
     isa => Bool,
     is => 'ro',
-    documentation => qq{ force debug mode }
+    documentation => 'Force debug mode',
 );
 
 has mechanize => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'mech',
     isa => Bool,
     is => 'ro',
-    documentation => qq{ use WWW::Mechanize },
+    documentation => 'use WWW::Mechanize',
 );
 
 sub run {
     my ($self) = @_;
 
+    $self->_display_help if ( !$ARGV[0] );
 
-    pod2usage(1) if ( $self->help || !$ARGV[0] );
-
     my $helper = Catalyst::Helper->new( { '.newfiles' => !$self->force, mech => $self->mech } );
 
-    pod2usage(1) unless $helper->mk_component( $self->app, @ARGV );
+    $self->_display_help unless $helper->mk_component( $self->app, @ARGV );
 
 }
 
@@ -66,11 +43,11 @@
 
 =head1 NAME
 
-boyosplace_create.pl - Create a new Catalyst Component
+Catalyst::Script::Create - Create a new Catalyst Component
 
 =head1 SYNOPSIS
 
-boyosplace_create.pl [options] model|view|controller name [helper] [options]
+myapp_create.pl [options] model|view|controller name [helper] [options]
 
  Options:
    -force        don't create a .new file where a file to be created exists
@@ -78,16 +55,16 @@
    -help         display this help and exits
 
  Examples:
-   boyosplace_create.pl controller My::Controller
-   boyosplace_create.pl controller My::Controller BindLex
-   boyosplace_create.pl -mechanize controller My::Controller
-   boyosplace_create.pl view My::View
-   boyosplace_create.pl view MyView TT
-   boyosplace_create.pl view TT TT
-   boyosplace_create.pl model My::Model
-   boyosplace_create.pl model SomeDB DBIC::Schema MyApp::Schema create=dynamic\
+   myapp_create.pl controller My::Controller
+   myapp_create.pl controller My::Controller BindLex
+   myapp_create.pl -mechanize controller My::Controller
+   myapp_create.pl view My::View
+   myapp_create.pl view MyView TT
+   myapp_create.pl view TT TT
+   myapp_create.pl model My::Model
+   myapp_create.pl model SomeDB DBIC::Schema MyApp::Schema create=dynamic\
    dbi:SQLite:/tmp/my.db
-   boyosplace_create.pl model AnotherDB DBIC::Schema MyApp::Schema create=static\
+   myapp_create.pl model AnotherDB DBIC::Schema MyApp::Schema create=static\
    dbi:Pg:dbname=foo root 4321
 
  See also:

Modified: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/FastCGI.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/FastCGI.pm	2009-09-02 00:48:47 UTC (rev 11297)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/FastCGI.pm	2009-09-02 00:48:54 UTC (rev 11298)
@@ -1,95 +1,64 @@
 package Catalyst::Script::FastCGI;
 
 BEGIN { $ENV{CATALYST_ENGINE} ||= 'FastCGI' }
-use FindBin qw/$Bin/;
-use lib "$Bin/../lib";
-use Pod::Usage;
 use Moose;
 use MooseX::Types::Moose qw/Str Bool Int/;
 use namespace::autoclean;
 
-with 'MooseX::Getopt';
+with 'Catalyst::ScriptRole';
 
-has help => (
-    traits => [qw(Getopt)],
-    cmd_aliases => 'h',
-    isa => Bool,
-    is => 'ro',
-    documentation => qq{ display this help and exits },
-);
-
 has listen => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'l',
     isa => Int,
     is => 'ro',
-    default => "3000",
-    documentation => qq{ specify a different listening port }
+    documentation => 'Specify a listening port/socket',
 );
 
 has pidfile => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'pid',
     isa => Str,
     is => 'ro',
-    documentation => qq{ specify a pidfile }
+    documentation => 'Specify a pidfile',
 );
 
 has daemon => ( 
     isa => Bool,   
     is => 'ro', 
-    traits => [qw(Getopt)],
     cmd_aliases => 'd', 
-    documentation => qq{ daemonize }
+    documentation => 'Daemonize',
 );
 
 has manager => ( 
     isa => Str,    
     is => 'ro',
-    traits => [qw(Getopt)],
     cmd_aliases => 'm',
-    documentation => qq{ use a different FastCGI manager } 
+    documentation => 'Use a different FastCGI manager', # FIXME
 );
 
 has keep_stderr => ( 
-    traits => [qw(Getopt)],
     cmd_aliases => 'std', 
     isa => Bool,   
     is => 'ro',  
-    documentation => qq{ log STDERR }
+    documentation => 'Log STDERR',
 );
 
 has nproc => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'np',  
     isa => Int,
     is => 'ro',  
-    documentation => qq{ specify an nproc }
+    documentation => 'Specify an nproc', # FIXME
 );
 
 has detach => ( 
-    traits => [qw(Getopt)],
     cmd_aliases => 'det', 
     isa => Bool,   
     is => 'ro',  
-    documentation => qq{ detach this FastCGI process }
+    documentation => 'Detach this FastCGI process',
 );
 
-has _app => (
-    reader   => 'app',
-    init_arg => 'app',
-    traits => [qw(NoGetopt)],
-    isa => Str,
-    is => 'ro',
-);
-
-sub run {
-    my $self = shift;
-
-    pod2usage() if $self->help;
-    my $app = $self->app;
-    Class::MOP::load_class($app);
-    $app->run(
+sub _application_args {
+    my ($self) = shift;
+    return (
         $self->listen,
         {
             nproc   => $self->nproc,
@@ -99,9 +68,29 @@
             keep_stderr => $self->keep_stderr,
         }
     );
-
 }
 
 __PACKAGE__->meta->make_immutable;
 
-1;
+=head1 NAME
+
+Catalyst::Script::FastCGI - The FastCGI Catalyst Script
+
+=head1 SYNOPSIS
+
+See L<Catalyst>.
+
+=head1 DESCRIPTION
+
+FIXME
+
+=head1 AUTHORS
+
+Catalyst Contributors, see Catalyst.pm
+
+=head1 COPYRIGHT
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut

Modified: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Server.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Server.pm	2009-09-02 00:48:47 UTC (rev 11297)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Server.pm	2009-09-02 00:48:54 UTC (rev 11298)
@@ -2,119 +2,88 @@
 
 BEGIN {
     $ENV{CATALYST_ENGINE} ||= 'HTTP';
-    $ENV{CATALYST_SCRIPT_GEN} = 31;
     require Catalyst::Engine::HTTP;
 }
 
-use FindBin qw/$Bin/;
-use lib "$Bin/../lib";
-use Pod::Usage;
 use Moose;
 use Catalyst::Restarter;
-use MooseX::Types::Moose qw/Str Bool Int/;
+use MooseX::Types::Moose qw/ArrayRef Str Bool Int/;
 use namespace::autoclean;
 
-with 'MooseX::Getopt';
-#extends qw(MooseX::App::Cmd);
+with 'Catalyst::ScriptRole';
 
 has debug => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'd',
     isa => Bool,
     is => 'ro',
-    documentation => qq{ force debug mode }
+    documentation => q{Force debug mode},
 );
 
-has help => (
-    traits => [qw(Getopt)],
-    cmd_aliases => 'h',
-    isa => Bool,
-    is => 'ro',
-    documentation => qq{ display this help and exits },
-);
-
 has host => (
     isa => Str,
     is => 'ro',
-    default =>  "localhost",
-    documentation => qq{ specify a host for the server to run on }
+    default => 'localhost',
+    documentation => 'Specify a host for the server to run on',
 );
 
 has fork => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'f',
     isa => Bool,
     is => 'ro',
-    documentation => qq{ fork the server }
+    documentation => 'Fork the server',
 );
 
 has listen => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'l',
     isa => Int,
     is => 'ro',
-    default => "3000",
-    documentation => qq{ specify a different listening port }
+    default => 3000,
+    documentation => 'Specify a different listening port',
 );
 
 has pidfile => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'pid',
     isa => Str,
     is => 'ro',
-    documentation => qq{ specify a pidfile }
+    documentation => 'Specify a pidfile',
 );
 
 has keepalive => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'k',
     isa => Bool,
     is => 'ro',
-    documentation => qq{ server keepalive },
+    documentation => 'Server keepalive',
 
 );
 
 has background => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'bg',
     isa => Bool,
     is => 'ro',
-    documentation => qq{ run in the background }
+    documentation => 'Run in the background',
 );
 
-
-has _app => (
-    reader   => 'app',
-    init_arg => 'app',
-    traits => [qw(NoGetopt)],
-    isa => Str,
-    is => 'ro',
-);
-
 has restart => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'r',
     isa => Bool,
     is => 'ro',
-    documentation => qq{ use Catalyst::Restarter to detect code changes }
+    documentation => 'use Catalyst::Restarter to detect code changes',
 );
 
 has restart_directory => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'rdir',
-    isa => 'ArrayRef[Str]',
+    isa => ArrayRef[Str],
     is  => 'ro',
     predicate => '_has_restart_directory',
-    documentation => qq{ restarter directory to watch }
+    documentation => 'Restarter directory to watch',
 );
 
 has restart_delay => (
-    traits => [qw(Getopt)],
     cmd_aliases => 'rdel',
     isa => Int,
     is => 'ro',
     predicate => '_has_restart_delay',
-    documentation => qq{ set a restart delay }
+    documentation => 'Set a restart delay',
 );
 
 has restart_regex => (
@@ -123,7 +92,7 @@
     isa => Str,
     is => 'ro',
     predicate => '_has_restart_regex',
-    documentation => qq{ restart regex }
+    documentation => 'Restart regex',
 );
 
 has follow_symlinks => (
@@ -132,23 +101,13 @@
     isa => Bool,
     is => 'ro',
     predicate => '_has_follow_symlinks',
-    documentation => qq{ follow symbolic links }
+    documentation => 'Follow symbolic links',
 
 );
 
-sub usage {
-    my ($self) = shift;
-
-    return pod2usage();
-
-}
-
-
 sub run {
     my ($self) = shift;
 
-    $self->usage if $self->help;
-
     if ( $self->debug ) {
         $ENV{CATALYST_DEBUG} = 1;
     }
@@ -188,32 +147,30 @@
         $restarter->run_and_watch;
     }
     else {
-        $self->_run;
+        $self->_run_application;
     }
 
 
 }
 
-sub _run {
+sub _application_args {
     my ($self) = shift;
-
-    my $app = $self->app;
-    Class::MOP::load_class($app);
-
-    $app->run(
-        $self->listen, $self->host,
+    return (
+        $self->listen,
+        $self->host,
         {
-           'fork'            => $self->fork,
-           keepalive         => $self->keepalive,
-           background        => $self->background,
-           pidfile           => $self->pidfile,
-           keepalive         => $self->keepalive,
-           follow_symlinks   => $self->follow_symlinks,
-        }
+           map { $_ => $self->$_ } qw/
+                fork
+                keepalive
+                background
+                pidfile
+                keepalive
+                follow_symlinks
+            /,
+        },
     );
 }
 
-
 __PACKAGE__->meta->make_immutable;
 
 1;

Modified: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Test.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Test.pm	2009-09-02 00:48:47 UTC (rev 11297)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Test.pm	2009-09-02 00:48:54 UTC (rev 11298)
@@ -1,42 +1,41 @@
 package Catalyst::Script::Test;
 use Moose;
-use Pod::Usage;
-use FindBin;
-use lib "$FindBin::Bin/../lib";
-with 'MooseX::Getopt';
-use MooseX::Types::Moose qw/Str Bool/;
 use namespace::autoclean;
 
-#extends qw(MooseX::App::Cmd);
+with 'Catalyst::ScriptRole';
 
-has _app => (
-    reader   => 'app',
-    init_arg => 'app',
-    traits => [qw(NoGetopt)],
-    isa => Str,
-    is => 'ro',
-);
-
-has help => (
-    traits => [qw(Getopt)],
-    cmd_aliases => 'h',
-    isa => Bool,
-    is => 'ro',
-    documentation => qq{ display this help and exits },
-);
-
-
 sub run {
     my $self = shift;
 
     Class::MOP::load_class("Catalyst::Test");
     Catalyst::Test->import($self->app);
 
-    pod2usage(1) if ( $self->help || !$ARGV[1] );
     print request($ARGV[1])->content  . "\n";
 
 }
 
 
 __PACKAGE__->meta->make_immutable;
-1;
+
+=head1 NAME
+
+Catalyst::Script::Test - Test Catalyst application on the command line
+
+=head1 SYNOPSIS
+
+See L<Catalyst>.
+
+=head1 DESCRIPTION
+
+FIXME
+
+=head1 AUTHORS
+
+Catalyst Contributors, see Catalyst.pm
+
+=head1 COPYRIGHT
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut

Added: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRole.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRole.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRole.pm	2009-09-02 00:48:54 UTC (rev 11298)
@@ -0,0 +1,53 @@
+package Catalyst::ScriptRole;
+use Moose::Role;
+use MooseX::Types::Moose qw/Str Bool/;
+use Pod::Usage;
+use namespace::autoclean;
+
+requires 'run';
+
+with 'MooseX::Getopt';
+
+has application_name => (
+    traits => ['NoGetopt'],
+    isa => Str,
+    is => 'ro',
+    required => 1,
+);
+
+has help => (
+    traits => ['Getopt'],
+    cmd_aliases => 'h',
+    isa => Bool,
+    is => 'ro',
+    documentation => q{Display this help and exit},
+);
+
+sub _display_help {
+    my $self = shift;
+    pod2usage();
+    exit 0;
+}
+
+before run => sub {
+    my $self = shift;
+    $self->_display_help if $self->help;
+};
+
+sub run {
+    my $self = shift;
+    $self->_run_application;
+}
+
+sub _application_args {
+    ()
+}
+
+sub _run_application {
+    my $self = shift;
+    my $app = $self->application_name;
+    Class::MOP::load_class($app);
+    $app->run($self->_application_args);
+}
+
+1;

Modified: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRunner.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRunner.pm	2009-09-02 00:48:47 UTC (rev 11297)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRunner.pm	2009-09-02 00:48:54 UTC (rev 11298)
@@ -1,18 +1,43 @@
 package Catalyst::ScriptRunner;
 use Moose;
-#extends qw(MooseX::App::Cmd::Command);
+use namespace::autoclean;
 
-
 sub run {
     my ($self, $class, $scriptclass) = @_;
     my $classtoload = "${class}::Script::$scriptclass";
 
     # FIXME - Error handling / reporting
     if ( eval { Class::MOP::load_class($classtoload) } ) {
-    } else {
+    }
+    else {
         $classtoload = "Catalyst::Script::$scriptclass";
         Class::MOP::load_class($classtoload);
     }
     $classtoload->new_with_options( app => $class )->run;
 }
-1;
+
+__PACKAGE__->meta->make_immutable;
+
+=head1 NAME
+
+Catalyst::ScriptRunner - The Catalyst Framework Script runner
+
+=head1 SYNOPSIS
+
+See L<Catalyst>.
+
+=head1 DESCRIPTION
+
+This class is responsible for running scripts, either in the application specific namespace
+(e.g. C<MyApp::Script::Server>), or the Catalyst namespace (e.g. C<Catalyst::Script::Server>)
+
+=head1 AUTHORS
+
+Catalyst Contributors, see Catalyst.pm
+
+=head1 COPYRIGHT
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut




More information about the Catalyst-commits mailing list