line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YA::CLI::ActionRole; |
2
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
3
|
1
|
|
|
1
|
|
9781
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
362
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Action handler role |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
86
|
use YA::CLI::Usage; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
9
|
1
|
|
|
1
|
|
4
|
use Getopt::Long; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
123
|
use List::Util qw(any); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
383
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
requires qw( |
13
|
|
|
|
|
|
|
action |
14
|
|
|
|
|
|
|
run |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub cli_options { |
18
|
3
|
|
|
3
|
1
|
7
|
return; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub usage_pod { |
22
|
2
|
|
|
2
|
1
|
5
|
return; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new_from_args { |
26
|
4
|
|
|
4
|
1
|
5
|
my ($class, $args) = @_; |
27
|
4
|
|
|
|
|
8
|
return $class->new($class->get_opts($args)); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_opts { |
31
|
4
|
|
|
4
|
1
|
5
|
my ($class, $args) = @_; |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
13
|
my $p = Getopt::Long::Parser->new( |
34
|
|
|
|
|
|
|
config => [qw(no_auto_abbrev) ] |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
309
|
my %cli_args; |
38
|
4
|
|
|
|
|
15
|
$p->getoptionsfromarray($args, \%cli_args, $class->cli_options); |
39
|
4
|
|
|
|
|
494
|
return %cli_args; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub has_action { |
43
|
14
|
|
|
14
|
1
|
23
|
my ($self, $action) = @_; |
44
|
14
|
|
|
14
|
|
44
|
return any { $action eq $_ } $self->action; |
|
14
|
|
|
|
|
94
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub as_help { |
48
|
7
|
|
|
7
|
1
|
21
|
my ($self, $rc, $message) = @_; |
49
|
|
|
|
|
|
|
|
50
|
7
|
100
|
100
|
|
|
26
|
return YA::CLI::Usage->new( |
51
|
|
|
|
|
|
|
rc => ($rc // 0), |
52
|
|
|
|
|
|
|
$message ? (message => $message) : (), |
53
|
|
|
|
|
|
|
$self->_get_podfile_for_usage, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub as_manpage { |
58
|
2
|
|
|
2
|
1
|
4
|
my ($self) = @_; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
4
|
return YA::CLI::Usage->new( |
61
|
|
|
|
|
|
|
rc => 0, |
62
|
|
|
|
|
|
|
verbose => 2, |
63
|
|
|
|
|
|
|
$self->_get_podfile_for_usage, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _get_podfile_for_usage { |
69
|
9
|
|
|
9
|
|
10
|
my $self = shift; |
70
|
9
|
|
|
|
|
9
|
my $podfile; |
71
|
9
|
100
|
|
|
|
17
|
if (my $pod = $self->usage_pod) { |
72
|
1
|
50
|
|
|
|
6
|
$podfile = $pod == 1? $self : $pod; |
73
|
|
|
|
|
|
|
} |
74
|
9
|
100
|
|
|
|
193
|
return $podfile ? ( pod_file => $podfile ) : (); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |