line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jig::CLI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1407
|
use Getopt::Long qw/GetOptionsFromArray :config require_order/; |
|
1
|
|
|
|
|
10443
|
|
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
192
|
use base 'Exporter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
307
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw/cli/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _process { |
9
|
14
|
|
|
14
|
|
25
|
my ($flags, $subs, $args, $cmd, $opts) = @_; |
10
|
14
|
50
|
|
|
|
20
|
my $ignored = GetOptionsFromArray($args, $opts, @{ $flags || [] }); |
|
14
|
|
|
|
|
39
|
|
11
|
|
|
|
|
|
|
|
12
|
14
|
100
|
|
|
|
2051
|
if (@$args) { |
13
|
10
|
|
|
|
|
27
|
for my $sub (keys %$subs) { |
14
|
8
|
50
|
|
|
|
17
|
next unless $sub eq $args->[0]; |
15
|
8
|
|
|
|
|
16
|
push @$cmd, $args->[0]; shift @$args; |
|
8
|
|
|
|
|
10
|
|
16
|
8
|
100
|
|
|
|
12
|
my ($new_flags, %subs) = @{ $subs->{$sub} || [] }; |
|
8
|
|
|
|
|
31
|
|
17
|
8
|
100
|
|
|
|
13
|
return _process([@$flags, @{$new_flags || []}], \%subs, $args, $cmd, $opts); |
|
8
|
|
|
|
|
35
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
6
|
|
|
|
|
15
|
return; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub cli { |
24
|
6
|
|
|
6
|
0
|
41283
|
my ($spec, @args) = @_; |
25
|
6
|
|
|
|
|
14
|
my ($flags, %subs) = @$spec; |
26
|
6
|
100
|
|
|
|
17
|
@args = @ARGV if @_ == 1; |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
9
|
my (%opts, @cmd); |
29
|
6
|
|
|
|
|
18
|
_process($flags, \%subs, \@args, \@cmd, \%opts); |
30
|
6
|
|
|
|
|
40
|
join(' ', @cmd), \%opts, \@args; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |