Fix Path actions debug screen to display number of arguments
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ScriptRole.pm
CommitLineData
d3082fac 1package Catalyst::ScriptRole;
2use Moose::Role;
3use MooseX::Types::Moose qw/Str Bool/;
4use Pod::Usage;
0e4038c6 5use MooseX::Getopt;
d3082fac 6use namespace::autoclean;
7
19529022 8with 'MooseX::Getopt' => {
2d03a299 9 -excludes => [qw/
19529022 10 _getopt_spec_warnings
11 _getopt_spec_exception
2b8d5598 12 _getopt_full_usage
19529022 13 /],
14};
d3082fac 15
16has application_name => (
ad8b4c91 17 traits => ['NoGetopt'],
18 isa => Str,
19 is => 'ro',
d3082fac 20 required => 1,
21);
22
19529022 23sub _getopt_spec_exception {}
24
25sub _getopt_spec_warnings {
26 shift;
27 warn @_;
28}
29
2b8d5598 30sub _getopt_full_usage {
d3082fac 31 my $self = shift;
32 pod2usage();
33 exit 0;
34}
35
d3082fac 36sub run {
37 my $self = shift;
38 $self->_run_application;
39}
40
41sub _application_args {
42 ()
43}
44
45sub _run_application {
46 my $self = shift;
47 my $app = $self->application_name;
48 Class::MOP::load_class($app);
49 $app->run($self->_application_args);
50}
51
521;
1628b022 53
54=head1 NAME
55
56Catalyst::ScriptRole - Common functionality for Catalyst scripts.
57
58=head1 SYNOPSIS
59
12aa6ca4 60 package MyApp::Script::Foo;
61 use Moose;
62 use namespace::autoclean;
111d3c9a 63
2c298960 64 with 'Catalyst::ScriptRole';
111d3c9a 65
ad8b4c91 66 sub _application_args { ... }
111d3c9a 67
1628b022 68=head1 DESCRIPTION
69
12aa6ca4 70Role with the common functionality of Catalyst scripts.
71
72=head1 METHODS
73
74=head2 run
75
76The method invoked to run the application.
77
78=head1 ATTRIBUTES
79
80=head2 application_name
81
82The name of the application class, e.g. MyApp
83
84=head1 SEE ALSO
85
86L<Catalyst>
87
88L<MooseX::Getopt>
1628b022 89
90=head1 AUTHORS
91
92Catalyst Contributors, see Catalyst.pm
93
94=head1 COPYRIGHT
95
96This library is free software, you can redistribute it and/or modify
97it under the same terms as Perl itself.
98
99=cut