1 package Catalyst::ScriptRole;
3 use MooseX::Types::Moose qw/Str Bool/;
6 use namespace::autoclean;
8 with 'MooseX::Getopt' => {
11 _getopt_spec_exception
15 has application_name => (
16 traits => ['NoGetopt'],
26 documentation => q{Display this help and exit},
29 sub _getopt_spec_exception {}
31 sub _getopt_spec_warnings {
36 sub _exit_with_usage {
44 $self->_exit_with_usage if $self->help;
49 $self->_run_application;
52 sub _application_args {
56 sub _run_application {
58 my $app = $self->application_name;
59 Class::MOP::load_class($app);
60 $app->run($self->_application_args);
63 # GROSS HACK, temporary until MX::Getopt gets some proper refactoring and unfucking..
64 around '_parse_argv' => sub {
65 my ($orig, $self, @args) = @_;
66 my %data = eval { $self->$orig(@args) };
67 $self->_exit_with_usage($@) if $@;
68 $data{usage} = Catalyst::ScriptRole::Useage->new(code => sub { shift; $self->_exit_with_usage(@_) });
72 # This package is going away.
73 package # Hide from PAUSE
74 Catalyst::ScriptRole::Useage;
76 use namespace::autoclean;
78 has code => ( is => 'ro', required => 1 );
80 sub die { shift->code->(@_) }
86 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
90 package MyApp::Script::Foo;
92 use namespace::autoclean;
94 with 'Catalyst::Script::Role';
96 sub _application_args { ... }
100 Role with the common functionality of Catalyst scripts.
106 The method invoked to run the application.
110 =head2 application_name
112 The name of the application class, e.g. MyApp
122 Catalyst Contributors, see Catalyst.pm
126 This library is free software, you can redistribute it and/or modify
127 it under the same terms as Perl itself.