| 1 | package MOP4Import::Base::CLI_Opts; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | use MOP4Import::Base::CLI -as_base | |||||||||||||||||||||||||||||||||||||||||
| 5 | # , [extend => FieldSpec => qw/type alias/] | ||||||||||||||||||||||||||||||||||||||||||
| 6 | , [fields => qw/_cmd __cmd/] | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use MOP4Import::Opts; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use constant DEBUG => $ENV{DEBUG_MOP4IMPORT}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | use MOP4Import::Types::Extend | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | FieldSpec => [[fields => qw/type alias command real_name required for_subcmd/]]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | print STDERR "FieldSpec = ", FieldSpec, "\n" if DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | my MY $self = fields::new(shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | my $pre = {}; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | $self->configure_for_cli_opts($pre, @_); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | $self->after_new; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | sub invoke { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | my ( $self, $cmd, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
invoke: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | $self->{_cmd} = $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | if ( my $subref = $self->can("cmd_$cmd") ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | $self->configure_for_cli_opts({for_subcmd => 1}, @args); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | $subref->($self, @args); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | Carp::croak("Cmd `$cmd` is not implemented.\n"); | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | ▶ | use MOP4Import::Opts qw/Opts m4i_args m4i_opts/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | use MOP4Import::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | sub import { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 15 | ▶ | my ($myPack, @decls) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 15 | m4i_log_start() if DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 15 | ▶ | if ( (grep { $_ eq '-as_base' } @decls) && not (grep { $_ eq 'options' } map { ref($_) ? @$_ : $_ } @decls) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
grep {$_ eq "-as_base";} @decls and not grep({$_ eq "options";} map({ref $_ ? @$_ : $_;} @decls))
MC/DC100%2/2
grep {$_ eq "-as_base";} @decls and not grep({$_ eq "options";} map({ref $_ ? @$_ : $_;} @decls))
grep {$_ eq "-as_base";} @decls
not grep({$_ eq "options";} map({ref $_ ? @$_ : $_;} @decls))
Truth table100%3/3
A and not(B)
A= grep {$_ eq "-as_base";} @declsB= not grep({$_ eq "options";} map({ref $_ ? @$_ : $_;} @decls))
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | DEBUG && print STDERR "Because of no 'options', we set 'help' and 'version' automatically.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | push @decls, [ | |||||||||||||||||||||||||||||||||||||||||
| 51 | options => | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ['help|h', 'command', 'help'], | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ['version', 'command', 'version'], | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 15 | my Opts $opts = m4i_opts([caller]); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 15 | ▶ | @decls = $myPack->default_exports unless @decls; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 15 | $myPack->dispatch_declare($opts, $myPack->always_exports, @decls); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 15 | m4i_log_end($opts->{callpack}) if DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | sub default_options { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | ▶ | help => ['command' => 'help', 'type' => 'flag', 'alias' => 'h'], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_options: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | version => ['command' => 'version', 'type' => 'flag'], | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | sub _default_opt { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 13 | ▶ | my ( $myPack, $decls ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_opt: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 13 | my %auto = $myPack->default_options; | |||||||||||||||||||||||||||||||||||||||||
| 78 | my %rev_alias = map { # aliasの逆リンクをつくる | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 13 | my %pair = @{ $auto{$_} }; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 26 | ▶ | defined $pair{alias} ? ($pair{alias} => $_) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } keys %auto; | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 13 | for my $dec (@$decls) { | |||||||||||||||||||||||||||||||||||||||||
| 84 | 46 | ▶ | if ( $dec->[0] =~ /^([-a-zA-Z0-9]+)(?:\|([a-zA-Z0-9]))?(?:=[is]@?)?$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 46 | my $optname = $1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 46 | ▶ | my $alias = $2 // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$2 // ""
MC/DC100%1/1
$2 // ""
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 46 | for my $k ( $optname, $alias ) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | 92 | my $rev_alias = $rev_alias{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 92 | ▶ | my %opt = @{$auto{$k} || []}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 92 | ▶ | if ( exists $opt{alias} ) { # オプションがユーザー定義されているならaliasも不要 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | delete $auto{$opt{alias}}; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 92 | ▶ | if ( $rev_alias ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | ▶ | my %pair = @{ $auto{$rev_alias} || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 7 | delete $pair{alias}; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 7 | ▶ | $auto{$rev_alias} = [%pair] if exists $auto{$rev_alias}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 92 | delete $auto{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 13 | for my $k ( sort keys %auto ) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 19 | push @$decls, [$k, @{$auto{$k}}]; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | #print "decls:", Dumper($decls); | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | sub declare_options { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 13 | ▶ | (my $myPack, my Opts $opts, my (@decls)) = m4i_args(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
declare_options: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 13 | $myPack->_default_opt(\@decls); | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | $myPack->declare_fields($opts, map { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | ▶ | my $o = ref $_ ? $_ : [$_]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 65 | ▶ | unless ( $o->[0] =~ /([-\w]+)(?:\|([-\w]+))?(?:=([is]@?))?/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | Carp::croak("Invalid option format - " . $o->[0]); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 65 | my ($optline, %pair) = @$o; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 65 | ▶ | if (exists $pair{'for_subcmd'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 12 | ▶ | if ( ref $pair{'for_subcmd'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | $pair{'for_subcmd'} = +{ map { $_ => 1 } @{ $pair{'for_subcmd'} } }; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | elsif ( $pair{'for_subcmd'} ne '1' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | $pair{'for_subcmd'} = { $pair{'for_subcmd'} => 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 12 | @$o = ($optline, %pair); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 65 | my ($name, $alias, $type) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 65 | ▶ | $type ||= 'flag'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$type ||= "flag"
MC/DC100%1/1
$type ||= "flag"
$type
Truth table100%2/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 65 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 135 | print STDERR $name; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | if (defined $alias) {print " - $alias"} | ||||||||||||||||||||||||||||||||||||||||||
| 137 | print STDERR " = $type"; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | print "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 65 | push @$o, real_name => $name; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 65 | $name =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 65 | $o->[0] = $name; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 65 | ▶ | push @$o, alias => $alias if defined $alias; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 65 | push @$o, type => $type; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 65 | $o; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } @decls); | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub parse_opts_for_cli_opts { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 106 | ▶ | my ($class, $list, $result, @rest) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_opts_for_cli_opts: called CC=29 SCAR=33.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 106 | my $fields = MOP4Import::Declare::fields_hash($class); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 106 | print STDERR "fields for $class : ", Data::Dumper->new([$fields])->Dump, "\n" if DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 106 | my %alias; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 106 | my $form = {}; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 106 | ▶ | my $preserve = (ref($result) && scalar(@$result) && $result->[0]) ? shift(@$result) : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
ref $result and scalar @$result and $result->[0]
ref $result and scalar @$result
MC/DC50%1/2
ref $result and scalar @$result and $result->[0]
ref $result
$result->[0]
Truth table66%2/3
A and B
A= ref $resultB= $result->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 106 | unshift @{ $result }, { %$preserve, without_value => {} }; # SUPER::parse_optsで失われると困る情報を保持 | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 106 | foreach my $name (keys %$fields) { | |||||||||||||||||||||||||||||||||||||||||
| 161 | 1021 | my FieldSpec $spec = $fields->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 1021 | ▶ | if ( UNIVERSAL::isa($spec, FieldSpec) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 809 | ▶ | if ( $preserve->{for_subcmd} ) { # at this time, $class is a created object. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 364 | ▶ | next if not $spec->{for_subcmd}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 78 | ▶ | if ( ref $spec->{for_subcmd} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 40 | ▶ | next unless $spec->{for_subcmd}->{ $class->{_cmd} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | elsif ( $spec->{for_subcmd} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 87 | next; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 413 | ▶ | $form->{ $name } = $spec if $spec->{type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 413 | ▶ | if ( $spec->{alias} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 303 | $alias{$spec->{alias}} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 303 | $form->{ $spec->{alias} } = $form->{ $name }; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 106 | print STDERR "option format: ", Data::Dumper->new([$form])->Dump, "\n" if DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 106 | my $key = 1; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 106 | my @stack; | |||||||||||||||||||||||||||||||||||||||||
| 184 | my $cmd; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 106 | my $req_value; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 106 | for my $arg ( @$list ) { | |||||||||||||||||||||||||||||||||||||||||
| 187 | 206 | ▶ | if ( $key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 154 | ▶ | if ( $arg =~ /^-([^=]+)=(.+)$/ ) { # -f=foo | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 7 | push @stack, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | elsif ( $arg =~ /^--([^=]+)=(.+)$/ ) { # --foo=baz | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | push @stack, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | ▶ | elsif ( !$cmd && $arg =~ /^-([^-=]+)/ ) { # -fb( value) | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $cmd and $arg =~ /^-([^-=]+)/
MC/DC100%2/2
not $cmd and $arg =~ /^-([^-=]+)/
not $cmd
$arg =~ /^-([^-=]+)/
Truth table100%3/3
not(A) and B
A= not $cmdB= $arg =~ /^-([^-=]+)/
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 38 | my $myaby_opts = $1; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 38 | for my $s (split//, $myaby_opts) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | 50 | ▶ | if ( not defined $form->{$s} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | Carp::croak("Invalid option format - " . $arg); | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 47 | ▶ | if ( $form->{$s}->{type} ne 'flag' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 26 | push @stack, '-' . $s; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 26 | $key = 0; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 26 | ▶ | if (not $req_value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 26 | $req_value = $myaby_opts; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 21 | push @stack, '-' . $s; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ▶ | elsif ( !$cmd && $arg =~ /^--([^=]+)/ ) { # --bar( value) | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $cmd and $arg =~ /^--([^=]+)/
MC/DC100%2/2
not $cmd and $arg =~ /^--([^=]+)/
not $cmd
$arg =~ /^--([^=]+)/
Truth table100%3/3
not(A) and B
A= not $cmdB= $arg =~ /^--([^=]+)/
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 38 | ▶ | if ( not defined $form->{_hyphen2underscore($1)} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | Carp::croak("Invalid option format - " . $arg); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 37 | ▶ | if ( $form->{_hyphen2underscore($1)}->{type} ne 'flag' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 28 | push @stack, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 28 | $key = 0; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 28 | ▶ | if (not $req_value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 28 | $req_value = _hyphen2underscore($1); | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 9 | push @stack, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | else { # perhaps this is command! | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 71 | $cmd = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 71 | push @stack, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | else { # change to Base::CLI aware format | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 52 | $stack[-1] .= '=' . $arg; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 52 | $key = 1; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 52 | $req_value = ''; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | #print Dumper($list); | ||||||||||||||||||||||||||||||||||||||||||
| 239 | #print Dumper(\@stack); | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 102 | @$list = @stack; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 102 | ▶ | if ($req_value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | $result->[0]->{without_value}->{ $req_value } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 102 | $class->parse_opts($list, $result, \%alias, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | sub configure_for_cli_opts { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 107 | ▶ | my ( $self, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure_for_cli_opts: called CC=27 SCAR=33.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 107 | my $fields = MOP4Import::Declare::fields_hash($self); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 107 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 254 | my %map; | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 107 | my $command; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 107 | my $preserved = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 107 | my (%required, %default); | |||||||||||||||||||||||||||||||||||||||||
| 260 | 107 | for my $spec ( values %$fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 261 | 1031 | ▶ | next unless UNIVERSAL::isa($spec, FieldSpec); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 817 | ▶ | next if ( $preserved->{for_subcmd} and not $spec->{for_subcmd} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$preserved->{"for_subcmd"} and not $spec->{"for_subcmd"}
MC/DC100%2/2
$preserved->{"for_subcmd"} and not $spec->{"for_subcmd"}
$preserved->{"for_subcmd"}
not $spec->{"for_subcmd"}
Truth table100%3/3
A and not(B)
A= $preserved->{"for_subcmd"}B= not $spec->{"for_subcmd"}
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 527 | ▶ | next if ( not $preserved->{for_subcmd} and $spec->{for_subcmd} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $preserved->{"for_subcmd"} and $spec->{"for_subcmd"}
MC/DC100%2/2
not $preserved->{"for_subcmd"} and $spec->{"for_subcmd"}
not $preserved->{"for_subcmd"}
$spec->{"for_subcmd"}
Truth table100%3/3
not(A) and B
A= not $preserved->{"for_subcmd"}B= $spec->{"for_subcmd"}
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 429 | ▶ | if ( $preserved->{for_subcmd} and ref($spec->{for_subcmd}) and not $spec->{for_subcmd}->{ $self->{_cmd} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$preserved->{"for_subcmd"} and ref $spec->{"for_subcmd"} and not $spec->{"for_subcmd"}{$self->{"_cmd"}}
$preserved->{"for_subcmd"} and ref $spec->{"for_subcmd"}
MC/DC100%3/3
$preserved->{"for_subcmd"} and ref $spec->{"for_subcmd"} and not $spec->{"for_subcmd"}{$self->{"_cmd"}}
$preserved->{"for_subcmd"}
ref $spec->{"for_subcmd"}
not $spec->{"for_subcmd"}{$self->{"_cmd"}}
Truth table100%4/4
A and B and not(C)
A= $preserved->{"for_subcmd"}B= ref $spec->{"for_subcmd"}C= not $spec->{"for_subcmd"}{$self->{"_cmd"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 24 | next; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 405 | ▶ | $required{ $spec->{name} } = $spec->{required} if exists $spec->{required}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 405 | ▶ | $default{ $spec->{name} } = $spec->{default} if exists $spec->{default}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 405 | ▶ | if ( $spec->{alias} && exists $preserved->{without_value}->{ $spec->{alias} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$spec->{"alias"} and exists $preserved->{"without_value"}{$spec->{"alias"}}
MC/DC100%2/2
$spec->{"alias"} and exists $preserved->{"without_value"}{$spec->{"alias"}}
$spec->{"alias"}
exists $preserved->{"without_value"}{$spec->{"alias"}}
Truth table100%3/3
A and B
A= $spec->{"alias"}B= exists $preserved->{"without_value"}{$spec->{"alias"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | $preserved->{without_value}->{ $spec->{name} } = $preserved->{without_value}->{ $spec->{alias} }; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | delete $preserved->{without_value}->{ $spec->{alias} }; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 107 | ▶ | while ( defined(my $name = shift @args) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 94 | ▶ | my $type = $fields->{$name}->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fields->{$name}{"type"} // ""
MC/DC0%0/1
$fields->{$name}{"type"} // ""
$fields->{$name}{"type"}
Truth table50%1/2
A
A= $fields->{$name}{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 94 | my $val = shift(@args); | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 94 | ▶ | if ( $type =~ /(.)@/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 10 | ▶ | if ( $1 eq 'i' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | ▶ | if ( $val !~ /^[0-9]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | Carp::croak("option `$name` takes integer."); | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 9 | ▶ | if (not exists $map{$name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 5 | push @res, $name; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 5 | push @res, [$val]; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 5 | $map{$name} = $#res; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | push @{ $res[ $map{$name} ] }, $val; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 9 | next; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | elsif ( $type eq 'i' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 22 | ▶ | if ( $val !~ /^[0-9]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | Carp::croak("option `$name` takes integer."); | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 81 | ▶ | if ( $fields->{$name}->{command} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 15 | ▶ | if ( defined $command ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | Carp::croak("command invoking option was already called before `$name`."); | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 14 | $command = $fields->{$name}->{command}; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 14 | $self->{__cmd} = [$command, $val]; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 14 | next; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 66 | ▶ | delete $required{$name} if not exists $preserved->{without_value}->{ $name }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 66 | delete $default{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 66 | push @res, $name; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 66 | push @res, $val; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 102 | for my $key (keys %default) { | |||||||||||||||||||||||||||||||||||||||||
| 319 | 60 | push @res, $key, $default{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 60 | delete $required{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 102 | ▶ | if (%required) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 7 | my $opt = (sort keys %required)[0]; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 7 | Carp::croak("$opt is required."); | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | #print Dumper([@res]); | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 95 | $self->configure(@res); | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | ▶ | sub cmd_default { } | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_default: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | sub cmd_version { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | my $v = shift->VERSION // '0.0'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_version: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/2
(shift())->VERSION // "0.0"
MC/DC0%0/1
(shift())->VERSION // "0.0"
(shift())->VERSION
Truth table0%0/2
A
A= (shift())->VERSION
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | print "$v\n"; | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | sub cmd_help { # From MOP4Import::Base::CLI, original cmd_help do 'die' | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_help: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | my $pack = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my $fields = MOP4Import::Declare::fields_hash($self); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $names = MOP4Import::Declare::fields_array($self); | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | require MOP4Import::Util::FindMethods; | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | my @methods = MOP4Import::Util::FindMethods::FindMethods($pack, sub {s/^cmd_//}); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | print join("\n", <<END); | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | Usage: @{[File::Basename::basename($0)]} [--opt=value].. <command> [--opt=value].. ARGS... | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | Commands: | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | @{[join("\n ", @methods)]} | |||||||||||||||||||||||||||||||||||||||||
| 353 | END | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $max_len = 0; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | for my $name ( grep {/^[a-z]/} @$names ) { | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my FieldSpec $fs = $fields->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my $cmds = ['__common__']; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $str; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if (ref $fs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | $str = | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | do{ ' --' . (UNIVERSAL::isa($fs, FieldSpec) ? ($fs->{real_name} // '') : $name) } . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$fs->{"real_name"} // ""
MC/DC0%0/1
$fs->{"real_name"} // ""
$fs->{"real_name"}
Truth table0%0/2
A
A= $fs->{"real_name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | do{ UNIVERSAL::isa($fs, FieldSpec) and $fs->{ alias } ? ', -' . $fs->{ alias } : '' }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if ( exists $fs->{for_subcmd} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if ( ref $fs->{for_subcmd} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $cmds = [ sort keys %{ $fs->{for_subcmd} } ]; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $str = $name; | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | $max_len = length $str if length $str > $max_len; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | next if $str eq ' --'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | for my $name ( @$cmds ) { | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | push @{ $opt{ $name } }, [$str, $fs->{doc} ? $fs->{doc} : '']; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my @opts = [ 'common option', delete $opt{'__common__'} ]; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | push @opts, map { [ 'for ' . $_ => $opt{$_} ] } sort keys %opt; | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | print join("\n", <<END); | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | Options: | ||||||||||||||||||||||||||||||||||||||||||
| 390 | END | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | $max_len += 2; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | for my $optset ( @opts ) { | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my ( $subcmd, $opts ) = @$optset; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | print " [$subcmd]\n"; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | for my $opt (@$opts) { | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | printf( "%-${max_len}s%s\n", @$opt ); | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | exit(); | |||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | sub run { | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 59 | ▶ | my ($class, $arglist) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 59 | my $default_cmd = 'default'; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 59 | my $fields = MOP4Import::Declare::fields_hash($class); | |||||||||||||||||||||||||||||||||||||||||
| 409 | # $arglist を parse し、 $class->new 用のパラメータリストを作る | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 59 | my @opts = $class->parse_opts_for_cli_opts($arglist); | |||||||||||||||||||||||||||||||||||||||||
| 411 | 56 | my MY $obj = fields::new($class); | |||||||||||||||||||||||||||||||||||||||||
| 412 | 56 | $obj->configure_for_cli_opts(@opts); | |||||||||||||||||||||||||||||||||||||||||
| 413 | 47 | $obj->after_new; | |||||||||||||||||||||||||||||||||||||||||
| 414 | # 次の引数を取り出して、サブコマンドとして解釈を試みる | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 47 | ▶ | my $cmd = shift @$arglist || _set_cmd_by_option($obj, $arglist) || $default_cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
shift @$arglist || _set_cmd_by_option($obj, $arglist) || $default_cmd
shift @$arglist or _set_cmd_by_option($obj, $arglist)
MC/DC0%0/3
shift @$arglist || _set_cmd_by_option($obj, $arglist) || $default_cmd
shift @$arglist
_set_cmd_by_option($obj, $arglist)
$default_cmd
Truth table75%3/4
A or B || C
A= shift @$arglistB= _set_cmd_by_option($obj, $arglist)C= $default_cmd
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 47 | $obj->{_cmd} = $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 47 | my $result = [ { for_subcmd => 1 } ]; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 47 | $obj->configure_for_cli_opts(@{ $obj->parse_opts_for_cli_opts($arglist, $result) }); | |||||||||||||||||||||||||||||||||||||||||
| 419 | # サブコマンド毎の処理を行う | ||||||||||||||||||||||||||||||||||||||||||
| 420 | # 結果を何らかの形式で出力する | ||||||||||||||||||||||||||||||||||||||||||
| 421 | # 望ましい終了コードを返す(差し当たり、必要ならば各メソッド内で指定する) | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 45 | ▶ | if (my $sub = $obj->can("cmd_$cmd")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 45 | $sub->($obj, @$arglist); | |||||||||||||||||||||||||||||||||||||||||
| 424 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | print STDERR "Cmd `$cmd` is not implemented.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | exit(1); | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | sub _hyphen2underscore { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 103 | ▶ | my ($v) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hyphen2underscore: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 103 | $v =~ tr/-/_/; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 103 | return $v; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | sub _set_cmd_by_option { | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 30 | ▶ | my ($obj, $arglist) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_cmd_by_option: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 30 | ▶ | return unless $obj->{__cmd}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 13 | push @$arglist, $obj->{__cmd}->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 13 | return $obj->{__cmd}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||