1 package Catalyst::ScriptRole;
3 use MooseX::Types::Moose qw/Str Bool/;
5 use namespace::autoclean;
9 has application_name => (
10 traits => ['NoGetopt'],
20 documentation => q{Display this help and exit},
23 sub _exit_with_usage {
31 $self->_exit_with_usage if $self->help;
36 $self->_run_application;
39 sub _application_args {
43 sub _run_application {
45 my $app = $self->application_name;
46 Class::MOP::load_class($app);
47 $app->run($self->_application_args);
50 # GROSS HACK, temporary until MX::Getopt gets some proper refactoring and unfucking..
51 around '_parse_argv' => sub {
52 my ($orig, $self, @args) = @_;
53 my %data = eval { $self->$orig(@args) };
54 $self->_exit_with_usage($@) if $@;
55 $data{usage} = Catalyst::ScriptRole::Useage->new(code => sub { shift; $self->_exit_with_usage(@_) });
59 # This package is going away.
60 package # Hide from PAUSE
61 Catalyst::ScriptRole::Useage;
63 use namespace::autoclean;
65 has code => ( is => 'ro', required => 1 );
67 sub die { shift->code->(@_) }
73 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
77 package MyApp::Script::Foo;
79 use namespace::autoclean;
81 with 'Catalyst::Script::Role';
83 sub _application_args { ... }
87 Role with the common functionality of Catalyst scripts.
93 The method invoked to run the application.
97 =head2 application_name
99 The name of the application class, e.g. MyApp
109 Catalyst Contributors, see Catalyst.pm
113 This library is free software, you can redistribute it and/or modify
114 it under the same terms as Perl itself.