1 package Catalyst::ScriptRole;
3 use MooseX::Types::Moose qw/Str Bool/;
5 use namespace::autoclean;
9 has application_name => (
10 traits => ['NoGetopt'],
21 documentation => q{Display this help and exit},
24 sub _exit_with_usage {
32 $self->_exit_with_usage if $self->help;
37 $self->_run_application;
40 sub _application_args {
44 sub _run_application {
46 my $app = $self->application_name;
47 Class::MOP::load_class($app);
48 $app->run($self->_application_args);
51 # GROSS HACK, temporary until MX::Getopt gets some proper refactoring and unfucking..
52 around '_parse_argv' => sub {
53 my ($orig, $self, @args) = @_;
54 my %data = eval { $self->$orig(@args) };
55 $self->_exit_with_usage($@) if $@;
56 $data{usage} = Catalyst::ScriptRole::Useage->new(code => sub { shift; $self->_exit_with_usage(@_) });
60 # This package is going away.
61 package # Hide from PAUSE
62 Catalyst::ScriptRole::Useage;
64 use namespace::autoclean;
66 has code => ( is => 'ro', required => 1 );
68 sub die { shift->code->(@_) }
74 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
86 Catalyst Contributors, see Catalyst.pm
90 This library is free software, you can redistribute it and/or modify
91 it under the same terms as Perl itself.