line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package MooseX::App::Command; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
|
|
|
|
|
|
|
5
|
10
|
|
|
10
|
|
49322
|
use 5.010; |
|
10
|
|
|
|
|
39
|
|
6
|
10
|
|
|
10
|
|
63
|
use utf8; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
81
|
|
7
|
10
|
|
|
10
|
|
549
|
use strict; |
|
10
|
|
|
|
|
31
|
|
|
10
|
|
|
|
|
227
|
|
8
|
10
|
|
|
10
|
|
81
|
use warnings; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
274
|
|
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
54
|
use Moose (); |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
236
|
|
11
|
10
|
|
|
10
|
|
56
|
use MooseX::App::Meta::Role::Attribute::Option; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
362
|
|
12
|
10
|
|
|
10
|
|
57
|
use MooseX::App::Exporter qw(option parameter command_short_description command_long_description command_usage command_strict); |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
109
|
|
13
|
10
|
|
|
10
|
|
72
|
use Moose::Exporter; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
92
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
16
|
|
|
|
|
|
|
with_meta => [qw(command_short_description command_long_description command_strict command_usage option parameter extends)], |
17
|
|
|
|
|
|
|
also => 'Moose', |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init_meta { |
21
|
41
|
|
|
41
|
0
|
81917
|
my ($class,%args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
41
|
|
|
|
|
240
|
my $meta = Moose->init_meta( %args ); |
24
|
41
|
|
|
|
|
105448
|
init_class($meta); |
25
|
|
|
|
|
|
|
|
26
|
41
|
|
|
|
|
66993
|
return $meta; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub extends { |
30
|
22
|
|
|
22
|
0
|
96943
|
my $meta = shift; |
31
|
22
|
|
|
|
|
142
|
$meta->superclasses(@_); |
32
|
|
|
|
|
|
|
# Need to re-init meta class, just in case |
33
|
22
|
|
|
|
|
109926
|
init_class($meta); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub init_class { |
37
|
63
|
|
|
63
|
0
|
161
|
my $meta = shift; |
38
|
63
|
|
|
|
|
602
|
Moose::Util::MetaRole::apply_metaroles( |
39
|
|
|
|
|
|
|
for => $meta, |
40
|
|
|
|
|
|
|
class_metaroles => { |
41
|
|
|
|
|
|
|
class => [ |
42
|
|
|
|
|
|
|
'MooseX::App::Meta::Role::Class::Documentation', |
43
|
|
|
|
|
|
|
'MooseX::App::Meta::Role::Class::Command' |
44
|
|
|
|
|
|
|
], |
45
|
|
|
|
|
|
|
attribute => [ |
46
|
|
|
|
|
|
|
'MooseX::App::Meta::Role::Attribute::Option' |
47
|
|
|
|
|
|
|
], |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
63
|
50
|
|
|
|
129502
|
unless ($meta->DOES('MooseX::App::Role::Common')) { |
52
|
63
|
|
|
|
|
463
|
Moose::Util::MetaRole::apply_base_class_roles( |
53
|
|
|
|
|
|
|
for => $meta->name, |
54
|
|
|
|
|
|
|
roles => ['MooseX::App::Role::Common'], |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
MooseX::App::Command - Load command class metaclasses |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
package MyApp::SomeCommand; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use MooseX::App::Command; # Also loads Moose |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
option 'testattr' => ( |
76
|
|
|
|
|
|
|
isa => 'rw', |
77
|
|
|
|
|
|
|
cmd_tags => [qw(Important! Nice))], |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
command_short_description 'This is a short description'; |
81
|
|
|
|
|
|
|
command_long_description 'This is a much longer description yadda yadda'; |
82
|
|
|
|
|
|
|
command_usage 'script some_command --testattr 123'; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
By loading this class into your command classes you import all required |
87
|
|
|
|
|
|
|
symbols, and enable all documentation features such as: |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * Parsing command documentation from Pod |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item * Setting the command documentation manually via C<command_short_description> and C<command_long_description> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * Overriding the automated usage header with custom usage from Pod or via C<command_usage> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * Adding the C<cmd_tags>, C<cmd_flag>, C<cmd_aliases> and C<cmd_type> attributes to options |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=back |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 FUNCTIONS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 command_short_description |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Set the short description. If not set this information will be taken from the |
106
|
|
|
|
|
|
|
Pod NAME or ABSTRACT section. Alternative this will be taken from the |
107
|
|
|
|
|
|
|
DistZilla ABSTRACT tag. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 command_long_description |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Set the long description. If not set this information will be taken from the |
112
|
|
|
|
|
|
|
Pod DESCRIPTION or OVERVIEW sections. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 command_usage |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Set custom usage. If not set this will be taken from the Pod SYNOPSIS or |
117
|
|
|
|
|
|
|
USAGE section. If those sections are not available, the usage |
118
|
|
|
|
|
|
|
information will be autogenerated. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 command_strict |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
command_strict(0); # default |
123
|
|
|
|
|
|
|
OR |
124
|
|
|
|
|
|
|
command_strict(1); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
If strict is enabled the program will terminate with an error message if |
127
|
|
|
|
|
|
|
superfluous/unknown positional parameters are supplied. If disabled all |
128
|
|
|
|
|
|
|
extra parameters will be copied to the L<extra_argv> attribute. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
The app_strict function in the app classes allows one to set this option |
131
|
|
|
|
|
|
|
globally. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |