line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package MooseX::App::Command; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
|
|
|
|
|
|
|
5
|
10
|
|
|
10
|
|
52148
|
use 5.010; |
|
10
|
|
|
|
|
41
|
|
6
|
10
|
|
|
10
|
|
61
|
use utf8; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
69
|
|
7
|
10
|
|
|
10
|
|
579
|
use strict; |
|
10
|
|
|
|
|
34
|
|
|
10
|
|
|
|
|
248
|
|
8
|
10
|
|
|
10
|
|
57
|
use warnings; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
357
|
|
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
62
|
use Moose (); |
|
10
|
|
|
|
|
36
|
|
|
10
|
|
|
|
|
220
|
|
11
|
10
|
|
|
10
|
|
58
|
use MooseX::App::Meta::Role::Attribute::Option; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
443
|
|
12
|
10
|
|
|
10
|
|
66
|
use MooseX::App::Exporter qw(option parameter command_short_description command_long_description command_usage command_strict); |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
93
|
|
13
|
10
|
|
|
10
|
|
72
|
use Moose::Exporter; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
106
|
|
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
|
86353
|
my ($class,%args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
41
|
|
|
|
|
252
|
my $meta = Moose->init_meta( %args ); |
24
|
41
|
|
|
|
|
107203
|
init_class($meta); |
25
|
|
|
|
|
|
|
|
26
|
41
|
|
|
|
|
69004
|
return $meta; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub extends { |
30
|
22
|
|
|
22
|
0
|
100524
|
my $meta = shift; |
31
|
22
|
|
|
|
|
139
|
$meta->superclasses(@_); |
32
|
|
|
|
|
|
|
# Need to re-init meta class, just in case |
33
|
22
|
|
|
|
|
117002
|
init_class($meta); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub init_class { |
37
|
63
|
|
|
63
|
0
|
154
|
my $meta = shift; |
38
|
63
|
|
|
|
|
565
|
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
|
|
|
|
135562
|
unless ($meta->DOES('MooseX::App::Role::Common')) { |
52
|
63
|
|
|
|
|
495
|
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; |