Fix two warnings:
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ScriptRole.pm
1 package Catalyst::ScriptRole;
2 use Moose::Role;
3 use MooseX::Types::Moose qw/Str Bool/;
4 use Pod::Usage;
5 use MooseX::Getopt;
6 use namespace::autoclean;
7
8 with 'MooseX::Getopt' => {
9     -excludes => [qw/
10         _getopt_spec_warnings
11         _getopt_spec_exception
12         _getopt_full_usage
13     /],
14 };
15
16 has application_name => (
17     traits   => ['NoGetopt'],
18     isa      => Str,
19     is       => 'ro',
20     required => 1,
21 );
22
23 sub _getopt_spec_exception {}
24
25 sub _getopt_spec_warnings {
26     shift;
27     warn @_;
28 }
29
30 sub _getopt_full_usage {
31     my $self = shift;
32     pod2usage();
33     exit 0;
34 }
35
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;
53
54 =head1 NAME
55
56 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
57
58 =head1 SYNOPSIS
59
60     package MyApp::Script::Foo;
61     use Moose;
62     use namespace::autoclean;
63
64     with 'Catalyst::ScriptRole';
65
66     sub _application_args { ... }
67
68 =head1 DESCRIPTION
69
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>
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