Commit | Line | Data |
---|---|---|
d3082fac | 1 | package Catalyst::ScriptRole; |
2 | use Moose::Role; | |
3 | use MooseX::Types::Moose qw/Str Bool/; | |
4 | use Pod::Usage; | |
0e4038c6 | 5 | use MooseX::Getopt; |
d3082fac | 6 | use namespace::autoclean; |
7 | ||
19529022 | 8 | with '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 | |
16 | has application_name => ( | |
ad8b4c91 | 17 | traits => ['NoGetopt'], |
18 | isa => Str, | |
19 | is => 'ro', | |
d3082fac | 20 | required => 1, |
21 | ); | |
22 | ||
19529022 | 23 | sub _getopt_spec_exception {} |
24 | ||
25 | sub _getopt_spec_warnings { | |
26 | shift; | |
27 | warn @_; | |
28 | } | |
29 | ||
2b8d5598 | 30 | sub _getopt_full_usage { |
d3082fac | 31 | my $self = shift; |
32 | pod2usage(); | |
33 | exit 0; | |
34 | } | |
35 | ||
d3082fac | 36 | sub run { |
37 | my $self = shift; | |
38 | $self->_run_application; | |
39 | } | |
40 | ||
41 | sub _application_args { | |
42 | () | |
43 | } | |
44 | ||
45 | sub _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 | ||
52 | 1; | |
1628b022 | 53 | |
54 | =head1 NAME | |
55 | ||
56 | Catalyst::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 | 70 | Role with the common functionality of Catalyst scripts. |
71 | ||
72 | =head1 METHODS | |
73 | ||
74 | =head2 run | |
75 | ||
76 | The method invoked to run the application. | |
77 | ||
78 | =head1 ATTRIBUTES | |
79 | ||
80 | =head2 application_name | |
81 | ||
82 | The name of the application class, e.g. MyApp | |
83 | ||
84 | =head1 SEE ALSO | |
85 | ||
86 | L<Catalyst> | |
87 | ||
88 | L<MooseX::Getopt> | |
1628b022 | 89 | |
90 | =head1 AUTHORS | |
91 | ||
92 | Catalyst Contributors, see Catalyst.pm | |
93 | ||
94 | =head1 COPYRIGHT | |
95 | ||
96 | This library is free software, you can redistribute it and/or modify | |
97 | it under the same terms as Perl itself. | |
98 | ||
99 | =cut |