line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::Commander; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3561
|
use Moo; |
|
1
|
|
|
|
|
9312
|
|
|
1
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1493
|
use Class::Load qw/load_class/; |
|
1
|
|
|
|
|
11701
|
|
|
1
|
|
|
|
|
54
|
|
6
|
1
|
|
|
1
|
|
398
|
use String::CamelSnakeKebab qw/upper_camel_case/; |
|
1
|
|
|
|
|
3662
|
|
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
598
|
use Syntax::Keyword::Junction qw/any/; |
|
1
|
|
|
|
|
7422
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
765
|
use Path::Tiny; |
|
1
|
|
|
|
|
7449
|
|
|
1
|
|
|
|
|
116
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has base_class => (is => 'rw'); |
13
|
|
|
|
|
|
|
has class_prefix => (is => 'rw', default => sub { "Cmd" }); |
14
|
|
|
|
|
|
|
has version => (is => 'lazy'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build_version { |
17
|
0
|
|
|
0
|
|
|
my $self = shift; |
18
|
0
|
|
|
|
|
|
load_class($self->base_class); |
19
|
0
|
|
|
|
|
|
my $program = path($0); |
20
|
0
|
|
|
|
|
|
my $version = $self->base_class . "::VERSION"; |
21
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
291
|
|
22
|
0
|
|
|
|
|
|
print $program->basename . " $${version}\n"; |
23
|
0
|
|
|
|
|
|
exit; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub dispatch { |
27
|
0
|
|
|
0
|
0
|
|
my ($self, %params) = @_; |
28
|
0
|
|
|
|
|
|
my $argv = [@{ $params{argv} }]; # make a copy of the array |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
0
|
|
|
|
(print($self->version->(), "\n") && exit 1) |
|
|
|
0
|
|
|
|
|
31
|
|
|
|
|
|
|
if $argv->[0] |
32
|
|
|
|
|
|
|
&& $argv->[0] eq any(qw/-v --version/); |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
0
|
|
|
|
unshift @$argv, 'help' if $argv->[0] && $argv->[0] eq any(qw/-h --help/); |
35
|
0
|
0
|
|
|
|
|
unshift @$argv, 'help' unless $argv->[0]; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my @args; |
38
|
0
|
|
|
|
|
|
while (my $arg = shift @$argv) { |
39
|
0
|
0
|
|
|
|
|
last if $arg =~ /^--?/; |
40
|
0
|
|
|
|
|
|
push @args, $arg; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $action = upper_camel_case shift @args; |
44
|
0
|
|
|
|
|
|
my $class = $self->base_class . "::" . $self->class_prefix . "::" . $action; |
45
|
0
|
|
|
|
|
|
eval { load_class($class) }; |
|
0
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ($@) { |
47
|
0
|
|
|
|
|
|
eval { |
48
|
0
|
|
|
|
|
|
my $start = $self->base_class . "::" . $self->class_prefix; |
49
|
0
|
|
|
|
|
|
my $class = "${start}::Help"; |
50
|
0
|
|
|
|
|
|
eval { load_class($class) }; |
|
0
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ($@) { |
52
|
0
|
|
|
|
|
|
print "subcommand not found\n"; |
53
|
0
|
|
|
|
|
|
exit 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$class->new(argv => $params{argv})->usage; |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$class->new(argv => $params{argv})->go(@args); |
61
|
0
|
0
|
|
|
|
|
die $@ if $@; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |