| 1 | package Jig::CLI; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Getopt::Long qw/GetOptionsFromArray :config require_order/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | our @EXPORT = qw/cli/; | |||||||||
| 7 | |||||||||||
| 8 | sub _process { | ||||||||||
| 9 | 14 | ▶ | my ($flags, $subs, $args, $cmd, $opts) = @_; | ||||||||
|
Subroutine
_process: called CC=7 SCAR=19.5
| |||||||||||
| 10 | 14 | ▶ | my $ignored = GetOptionsFromArray($args, $opts, @{ $flags || [] }); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | |||||||||||
| 12 | 14 | ▶ | if (@$args) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 10 | for my $sub (keys %$subs) { | |||||||||
| 14 | 8 | ▶ | next unless $sub eq $args->[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 8 | push @$cmd, $args->[0]; shift @$args; | |||||||||
| 16 | 8 | ▶ | my ($new_flags, %subs) = @{ $subs->{$sub} || [] }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 8 | ▶ | return _process([@$flags, @{$new_flags || []}], \%subs, $args, $cmd, $opts); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | } | ||||||||||
| 19 | } | ||||||||||
| 20 | 6 | return; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | sub cli { | ||||||||||
| 24 | 6 | ▶ | my ($spec, @args) = @_; | ||||||||
|
Subroutine
cli: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 25 | 6 | my ($flags, %subs) = @$spec; | |||||||||
| 26 | 6 | ▶ | @args = @ARGV if @_ == 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 6 | my (%opts, @cmd); | |||||||||
| 29 | 6 | _process($flags, \%subs, \@args, \@cmd, \%opts); | |||||||||
| 30 | 6 | join(' ', @cmd), \%opts, \@args; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 1 | 1; | |||||||||