Simple.pm

filter: Statementstmt 72.3% 369 / 510 Branchbran 53.8% 113 / 210 Conditioncond 41.2% 89 / 216 MC/DCmcdc 21.0% 28 / 133 Subroutinesub 78.1% 50 / 64 Podpod 62.5% 10 / 16 totaltotal 57.3% 659 / 1149 CC 198 SCAR 46.4
CC
198
Cov
61%
init_logger
348.5
new
180.3
use_log4perl
135.5
CRAP 103.4
↑ Summary Simple/Scaffold.pm »
1 package CLI::Simple;
2 # a Simple, Fast & Easy way to create scripts
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use CLI::Simple::Constants qw(:booleans :chars :log-levels @VALID_OPTIONS @DEFAULT_HELP_SECTIONS :color-config);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use CLI::Simple::Utils qw(normalize_options slurp dmp choose);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use CLI::Simple::DumpSpec qw(_cmd_dump_spec);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use CLI::Simple::Migrate qw(_cmd_migrate);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use CLI::Simple::Scaffold qw(_cmd_scaffold);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use CLI::Simple::Helpers qw(_is_class_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use CLI::Simple::Shell;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶use FindBin qw($RealBin $RealScript);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use File::Which qw(which);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶use Getopt::Long qw(:config no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶use IO::Interactive;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶use List::Util qw(none pairs any);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 8 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 8 our $VERSION = '2.3.1';
27  
28 8 our $GETOPT_EXIT_ON_ERROR = $TRUE;
29 8 our $GETOPT_STATUS;
30 8 our $GETOPT_ERROR_MESSAGE;
31  
32 8 my %GENERATED_ACCESSOR; # tracks accessors mk_accessors itself created, per class
33  
34 8 __PACKAGE__->follow_best_practice;
35 8 __PACKAGE__->mk_accessors(
36 qw(
37 _validate_command
38 _command
39 _command_args
40 _commands
41 _program
42 _abbreviations
43 )
44 );
45  
46 8 our $USE_LOGGER = $FALSE;
47 8 our $AUTO_DEFAULT = $FALSE;
48 8 our $AUTO_HELP = $FALSE;
49 8 our $PAGER = $TRUE;
50  
51 8 our %INTERNAL_COMMANDS = (
52 '-generate-completion' => \&_cmd_generate_completion,
53 '-migrate' => \&_cmd_migrate,
54 '-dump-spec' => \&_cmd_dump_spec,
55 '-scaffold' => \&_cmd_scaffold,
56 );
57  
58 8 our @EXPORT_OK = qw($AUTO_HELP $AUTO_DEFAULT $PAGER $USE_LOGGER);
59  
60 8 ▶use parent qw(Exporter Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 # CLI::Simple 2.0.0 additions
63  
64 8 our $MANIFEST; # package-level, per-consumer class
65  
66 8 ▶caller or exit __PACKAGE__->main();
Branch: 1 branch
BranchTrueFalseTotal
caller or exit __PACKAGE__->main 8 0 8
67  
68 ########################################################################
69 11 ▶sub import {
Subroutine import: called CC=7 SCAR=32.4
70 ########################################################################
71 11 my ( $class, @args ) = @_;
72  
73 11 ▶ if ( any { $_ eq ':roles' } @args ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq ":roles"; } , @args)) 0 11 11
74 0 my $caller = caller;
75  
76 0 ▶ if ( !${^COMPILING} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (${^COMPILING}) 0 0 0
77 0 ( my $dist = $caller ) =~ s/::/-/gxsm;
78 0 my $yaml_file = lc($dist) . '.yml';
79  
80 0 require File::ShareDir;
81 0 my $path = eval { File::ShareDir::dist_file( $dist, $yaml_file ) };
82 0 ▶ undef $path if $path && !-e $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path and not -e $path 0 0 0
Condition0%0/3
$path and not -e $path
!ll&&!rl&&r
000
MC/DC0%0/2
$path and not -e $path
$path not -e $path
Truth table0%0/3
A and not(B)
A= $pathB= not -e $path
ABresult
0X0
100
111
83  
84 0 ▶ $class->_load_manifest( $caller, $path ) if $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path 0 0 0
85 }
86 }
87  
88 # preserve existing Exporter behaviour
89 11 ▶ $class->export_to_level( 1, $class, grep { $_ ne ':roles' && !/[.]ya?ml\z/xsm } @args );
Condition33%1/3
$_ ne ':roles' && !/[.]ya?ml\z/msx
!ll&&!rl&&r
004
MC/DC0%0/2
$_ ne ':roles' && !/[.]ya?ml\z/msx
$_ ne ':roles' !/[.]ya?ml\z/msx
Truth table33%1/3
A && not(B)
A= $_ ne ':roles'B= !/[.]ya?ml\z/msx
ABresult
0X0
100
111
90  
91 11 return;
92 }
93  
94 ########################################################################
95 14 ▶sub _load_manifest {
Subroutine _load_manifest: called CC=9 SCAR=22.0
96 ########################################################################
97 14 my ( $class, $target, $yaml_file ) = @_;
98  
99 14 require YAML::Tiny;
100  
101 14 ▶ my $manifest = YAML::Tiny::LoadFile($yaml_file)
Branch: 1 branch
BranchTrueFalseTotal
my $manifest = YAML::Tiny::LoadFile($yaml_file) or die "ERROR: could not load manifest: $yaml_file\n" 14 0 14
102 or die "ERROR: could not load manifest: $yaml_file\n";
103  
104 14 ▶ my $commands = $manifest->{commands} // {};
Condition100%2/2
$manifest->{"commands"} // {}
l!l
59
MC/DC100%1/1
$manifest->{"commands"} // {}
$manifest->{"commands"}
Truth table100%2/2
A
A= $manifest->{"commands"}
Aresult
11
00
105 14 ▶ my $roles = $manifest->{roles} // {};
Condition100%2/2
$manifest->{"roles"} // {}
l!l
113
MC/DC100%1/1
$manifest->{"roles"} // {}
$manifest->{"roles"}
Truth table100%2/2
A
A= $manifest->{"roles"}
Aresult
11
00
106  
107 14 foreach my $cmd ( keys %{$roles} ) {
108 die sprintf "ERROR: command '%s' is defined in both commands and roles\n", $cmd
109 13 ▶ if exists $commands->{$cmd};
Branch: 1 branch
BranchTrueFalseTotal
if exists $commands->{$cmd} 2 11 13
110 }
111  
112 12 my %selective_roles;
113  
114 12 foreach my $cmd ( keys %{$roles} ) {
115 11 my $value = $roles->{$cmd};
116  
117 11 ▶ my @roles = choose {
Subroutine __ANON__: called CC=4 SCAR=13.9
118 11 ▶ return @{$value}
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and builtin::reftype($value) eq "ARRAY" 2 9 11
Condition100%3/3
ref $value and builtin::reftype($value) eq "ARRAY"
!ll&&!rl&&r
722
MC/DC100%2/2
ref $value and builtin::reftype($value) eq "ARRAY"
ref $value builtin::reftype($value) eq "ARRAY"
Truth table100%3/3
A and B
A= ref $valueB= builtin::reftype($value) eq "ARRAY"
ABresult
0X0
100
111
119 if ref $value && reftype($value) eq 'ARRAY';
120  
121 9 ▶ return ($value)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 7 2 9
122 if !ref $value;
123  
124 2 die sprintf "ERROR: invalid roles specification for command '%s'\n", $cmd;
125 11 };
126  
127 9 foreach my $role (@roles) {
128 11 ▶ die sprintf "ERROR: invalid role '%s' for command '%s'\n", $role, $cmd
Branch: 1 branch
BranchTrueFalseTotal
unless _is_class_name($role) 1 10 11
129 if !_is_class_name($role);
130 }
131  
132 8 $selective_roles{$cmd} = \@roles;
133 }
134  
135 9 $manifest->{_commands} = $commands;
136 9 $manifest->{_roles} = \%selective_roles;
137  
138 # store on the target class
139 8 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
140 9 ${"${target}::_CLI_MANIFEST"} = $manifest;
141  
142 9 return;
143 }
144  
145 ########################################################################
146 10 ▶sub _manifest {
Subroutine _manifest: called CC=1 SCAR=0.0
147 ########################################################################
148 10 my ($class) = @_;
149  
150 8 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
151 10 return ${"${class}::_CLI_MANIFEST"};
152 }
153  
154 ########################################################################
155 6 ▶sub main {
Subroutine main: called CC=16 SCAR=34.8
Pod documented
156 ########################################################################
157 6 my ($class) = @_;
158  
159 6 my $manifest = $class->_manifest;
160  
161 my $cli = $class->new(
162 option_specs => $manifest ? ( $manifest->{options} // [] ) : [],
163 alias => $manifest ? ( $manifest->{alias} // {} ) : {},
164 default_options => $manifest ? ( $manifest->{default_options} // {} ) : {},
165 extra_options => $manifest ? ( $manifest->{extra_options} // [] ) : [],
166 commands => $manifest ? {} : { default => \&usage },
167 manifest_commands => $manifest ? ( $manifest->{_commands} // {} ) : {},
168 command_roles => $manifest ? ( $manifest->{_roles} // {} ) : {},
169 6 ▶ abbreviations => $manifest ? ( $manifest->{abbreviations} // $FALSE ) : $FALSE,
Branch: 8 branches
BranchTrueFalseTotal
$manifest ? : 6 0 6
$manifest ? : 6 0 6
$manifest ? : 6 0 6
$manifest ? : 6 0 6
$manifest ? : 6 0 6
$manifest ? : 6 0 6
$manifest ? : 6 0 6
$manifest ? : 6 0 6
Condition60%9/15
$manifest->{"options"} // []
l!l
06
$manifest->{"alias"} // {}
l!l
15
$manifest->{"default_options"} // {}
l!l
06
$manifest->{"extra_options"} // []
l!l
06
$manifest->{"_commands"} // {}
l!l
60
$manifest->{"_roles"} // {}
l!l
60
$manifest->{"abbreviations"} // $CLI::Simple::FALSE
l!l&&r!l&&!r
105
MC/DC0%0/1
$manifest->{"options"} // []
$manifest->{"options"}
MC/DC100%1/1
$manifest->{"alias"} // {}
$manifest->{"alias"}
MC/DC0%0/1
$manifest->{"default_options"} // {}
$manifest->{"default_options"}
MC/DC0%0/1
$manifest->{"extra_options"} // []
$manifest->{"extra_options"}
MC/DC0%0/1
$manifest->{"_commands"} // {}
$manifest->{"_commands"}
MC/DC0%0/1
$manifest->{"_roles"} // {}
$manifest->{"_roles"}
MC/DC50%1/2
$manifest->{"abbreviations"} // $CLI::Simple::FALSE
$manifest->{"abbreviations"} $CLI::Simple::FALSE
Truth table50%1/2
A
A= $manifest->{"options"}
Aresult
11
00
Truth table100%2/2
A
A= $manifest->{"alias"}
Aresult
11
00
Truth table50%1/2
A
A= $manifest->{"default_options"}
Aresult
11
00
Truth table50%1/2
A
A= $manifest->{"extra_options"}
Aresult
11
00
Truth table50%1/2
A
A= $manifest->{"_commands"}
Aresult
11
00
Truth table50%1/2
A
A= $manifest->{"_roles"}
Aresult
11
00
Truth table66%2/3
A // B
A= $manifest->{"abbreviations"}B= $CLI::Simple::FALSE
ABresult
1X1
011
000
170 );
171  
172 5 return $cli->run;
173 }
174  
175 ########################################################################
176 46 ▶sub _use_logger {
Subroutine _use_logger: called CC=1 SCAR=0.0
177 ########################################################################
178 46 return $USE_LOGGER;
179 }
180  
181 ########################################################################
182 0 ▶sub use_log4perl {
Subroutine use_log4perl: not called CC=12 SCAR=49.1
Pod documented
183 ########################################################################
184 0 my ( $self, %args ) = @_;
185  
186 0 my @valid_options = qw(
187 log_level
188 level
189 loglevel
190 log-level
191 config
192 color
193 debug_color
194 info_color
195 warn_color
196 error_color
197 trace_color
198 fatal_color
199 );
200  
201 0 foreach my $o ( keys %args ) {
202 die "ERROR: unknown argument ($o)\n"
203 0 ▶ if none { $o eq $_ } @valid_options;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $o eq $_; } , @valid_options) 0 0 0
204 }
205  
206 0 ▶ eval { require Log::Log4perl; 1; }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Log::Log4perl; 1 } } or die "use_log4perl() requires Log::Log4perl, which is not installed.\nIt is an opt-in feature, so CLI::Simple does not depend on it.\nIf your app calls use_log4perl(), add 'Log::Log4perl' to your requires/cpanfile.\n" 0 0 0
207 or die "use_log4perl() requires Log::Log4perl, which is not installed.\n"
208 . "It is an opt-in feature, so CLI::Simple does not depend on it.\n"
209 . "If your app calls use_log4perl(), add 'Log::Log4perl' to your requires/cpanfile.\n";
210  
211 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
212  
213 die "ERROR: color and config are mutually exclusive - color uses CLI::Simple's built-in colorized config\n"
214 0 ▶ if $args{color} && $args{config};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"color"} and $args{"config"} 0 0 0
Condition0%0/3
$args{"color"} and $args{"config"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"color"} and $args{"config"}
$args{"color"} $args{"config"}
Truth table0%0/3
A and B
A= $args{"color"}B= $args{"config"}
ABresult
0X0
100
111
215  
216 0 my ($level) = grep {defined} @args{qw(log_level log-level loglevel level)};
217 0 ▶ $level //= 'error';
Condition0%0/2
$level //= "error"
l!l
00
MC/DC0%0/1
$level //= "error"
$level
Truth table0%0/2
A
A= $level
Aresult
11
00
218  
219 0 my $log4perl_conf = $args{config};
220  
221 0 ▶ if ( $args{color} && !$log4perl_conf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"color"} and not $log4perl_conf) 0 0 0
Condition0%0/3
$args{"color"} and not $log4perl_conf
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"color"} and not $log4perl_conf
$args{"color"} not $log4perl_conf
Truth table0%0/3
A and not(B)
A= $args{"color"}B= not $log4perl_conf
ABresult
0X0
100
111
222 0 $log4perl_conf = $self->_set_color_config(%args);
223 }
224  
225 {
226 0 $USE_LOGGER = $TRUE;
227  
228 8 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
229 0 ▶ *{"${class}::get_log4perl_conf"} = sub { return $log4perl_conf };
Subroutine __ANON__: not called CC=1 SCAR=6.9
230 0 ▶ *{"${class}::set_log4perl_conf"} = sub { $log4perl_conf = $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
231 0 ▶ *{"${class}::get_log4perl_level"} = sub { return $level };
Subroutine __ANON__: not called CC=1 SCAR=6.9
232 }
233  
234 0 ▶ if ( !$self->can('set_logger') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->can("set_logger")) 0 0 0
235 0 $self->mk_accessors('logger');
236 0 $GENERATED_ACCESSOR{$class}{logger} = $TRUE;
237 }
238  
239 0 ▶ if ( !$self->can('set_log_level') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->can("set_log_level")) 0 0 0
240 0 $self->mk_accessors('log_level');
241 0 $GENERATED_ACCESSOR{$class}{log_level} = $TRUE;
242 }
243  
244 0 return $self;
245 }
246  
247 ########################################################################
248 27 ▶sub new {
Subroutine new: called CC=87 SCAR=51.9
Pod documented
249 ########################################################################
250 27 my ( $class, @params ) = @_;
251  
252 27 my $t0 = time;
253  
254 27 ▶ my %args = ref $params[0] ? %{ $params[0] } : @params;
Branch: 1 branch
BranchTrueFalseTotal
ref $params[0] ? : 0 27 27
255  
256 27 foreach my $o ( keys %args ) {
257 die "ERROR: unknown option '$o'\n"
258 98 ▶ if none { $o eq $_ } @VALID_OPTIONS;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $o eq $_; } , @CLI::Simple::VALID_OPTIONS) 1 97 98
259 }
260  
261 my (
262 $default_options, $option_specs, $commands, $command_roles, $manifest_commands, $extra_options,
263 $abbreviations, $error_handler, $alias, $validate_command, $help_sections
264 )
265 = @args{
266 26 qw(default_options option_specs commands command_roles manifest_commands extra_options abbreviations error_handler alias validate_command help_sections)
267 };
268  
269 26 ▶ $validate_command //= $TRUE;
Condition33%1/3
$validate_command //= $CLI::Simple::TRUE
l!l&&r!l&&!r
0260
MC/DC0%0/2
$validate_command //= $CLI::Simple::TRUE
$validate_command $CLI::Simple::TRUE
Truth table33%1/3
A //= B
A= $validate_commandB= $CLI::Simple::TRUE
ABresult
1X1
011
000
270  
271 8 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
272  
273 26 my $stash = \%{ $class . $DOUBLE_COLON };
274  
275 26 local *alias = *alias; ## no critic ProhibitLocalVars
276  
277 8 ▶ use vars qw($DEFAULT_OPTIONS $EXTRA_OPTIONS $OPTION_SPECS $COMMANDS $LOGGING);
Subroutine BEGIN: called CC=1 SCAR=0.0
278  
279 26 ▶ *DEFAULT_OPTIONS = $stash->{DEFAULT_OPTIONS} // $EMPTY;
Condition66%2/3
$stash->{"DEFAULT_OPTIONS"} // $CLI::Simple::EMPTY
l!l&&r!l&&!r
16010
MC/DC50%1/2
$stash->{"DEFAULT_OPTIONS"} // $CLI::Simple::EMPTY
$stash->{"DEFAULT_OPTIONS"} $CLI::Simple::EMPTY
Truth table66%2/3
A // B
A= $stash->{"DEFAULT_OPTIONS"}B= $CLI::Simple::EMPTY
ABresult
1X1
011
000
280 26 ▶ *EXTRA_OPTIONS = $stash->{EXTRA_OPTIONS} // $EMPTY;
Condition66%2/3
$stash->{"EXTRA_OPTIONS"} // $CLI::Simple::EMPTY
l!l&&r!l&&!r
16010
MC/DC50%1/2
$stash->{"EXTRA_OPTIONS"} // $CLI::Simple::EMPTY
$stash->{"EXTRA_OPTIONS"} $CLI::Simple::EMPTY
Truth table66%2/3
A // B
A= $stash->{"EXTRA_OPTIONS"}B= $CLI::Simple::EMPTY
ABresult
1X1
011
000
281 26 ▶ *OPTION_SPECS = $stash->{OPTION_SPECS} // $EMPTY;
Condition66%2/3
$stash->{"OPTION_SPECS"} // $CLI::Simple::EMPTY
l!l&&r!l&&!r
16010
MC/DC50%1/2
$stash->{"OPTION_SPECS"} // $CLI::Simple::EMPTY
$stash->{"OPTION_SPECS"} $CLI::Simple::EMPTY
Truth table66%2/3
A // B
A= $stash->{"OPTION_SPECS"}B= $CLI::Simple::EMPTY
ABresult
1X1
011
000
282 26 ▶ *COMMANDS = $stash->{COMMANDS} // $EMPTY;
Condition66%2/3
$stash->{"COMMANDS"} // $CLI::Simple::EMPTY
l!l&&r!l&&!r
16010
MC/DC50%1/2
$stash->{"COMMANDS"} // $CLI::Simple::EMPTY
$stash->{"COMMANDS"} $CLI::Simple::EMPTY
Truth table66%2/3
A // B
A= $stash->{"COMMANDS"}B= $CLI::Simple::EMPTY
ABresult
1X1
011
000
283  
284 26 ▶ $default_options //= $DEFAULT_OPTIONS;
Condition66%2/3
$default_options //= $CLI::Simple::DEFAULT_OPTIONS
l!l&&r!l&&!r
6020
MC/DC50%1/2
$default_options //= $CLI::Simple::DEFAULT_OPTIONS
$default_options $CLI::Simple::DEFAULT_OPTIONS
Truth table66%2/3
A //= B
A= $default_optionsB= $CLI::Simple::DEFAULT_OPTIONS
ABresult
1X1
011
000
285 26 ▶ $extra_options //= $EXTRA_OPTIONS;
Condition66%2/3
$extra_options //= $CLI::Simple::EXTRA_OPTIONS
l!l&&r!l&&!r
6020
MC/DC50%1/2
$extra_options //= $CLI::Simple::EXTRA_OPTIONS
$extra_options $CLI::Simple::EXTRA_OPTIONS
Truth table66%2/3
A //= B
A= $extra_optionsB= $CLI::Simple::EXTRA_OPTIONS
ABresult
1X1
011
000
286 26 ▶ $option_specs //= $OPTION_SPECS;
Condition66%2/3
$option_specs //= $CLI::Simple::OPTION_SPECS
l!l&&r!l&&!r
2303
MC/DC50%1/2
$option_specs //= $CLI::Simple::OPTION_SPECS
$option_specs $CLI::Simple::OPTION_SPECS
Truth table66%2/3
A //= B
A= $option_specsB= $CLI::Simple::OPTION_SPECS
ABresult
1X1
011
000
287 26 ▶ $commands //= $COMMANDS;
Condition33%1/3
$commands //= $CLI::Simple::COMMANDS
l!l&&r!l&&!r
2600
MC/DC0%0/2
$commands //= $CLI::Simple::COMMANDS
$commands $CLI::Simple::COMMANDS
Truth table33%1/3
A //= B
A= $commandsB= $CLI::Simple::COMMANDS
ABresult
1X1
011
000
288  
289 26 ▶ $option_specs //= [];
Condition100%2/2
$option_specs //= []
l!l
233
MC/DC100%1/1
$option_specs //= []
$option_specs
Truth table100%2/2
A
A= $option_specs
Aresult
11
00
290 26 ▶ $commands //= {};
Condition50%1/2
$commands //= {}
l!l
260
MC/DC0%0/1
$commands //= {}
$commands
Truth table50%1/2
A
A= $commands
Aresult
11
00
291 26 ▶ $manifest_commands //= {};
Condition100%2/2
$manifest_commands //= {}
l!l
620
MC/DC100%1/1
$manifest_commands //= {}
$manifest_commands
Truth table100%2/2
A
A= $manifest_commands
Aresult
11
00
292 26 ▶ $command_roles //= {};
Condition100%2/2
$command_roles //= {}
l!l
620
MC/DC100%1/1
$command_roles //= {}
$command_roles
Truth table100%2/2
A
A= $command_roles
Aresult
11
00
293  
294 26 foreach my $command ( keys %{$manifest_commands}, keys %{$command_roles} ) {
295 8 ▶ $commands->{$command} //= sub { die "not implemented\n" };
Subroutine __ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$commands->{$command} //= sub { die "not implemented\n"; }
l!l&&r!l&&!r
080
MC/DC0%0/2
$commands->{$command} //= sub { die "not implemented\n"; }
$commands->{$command} sub { die "not implemented\n"; }
Truth table33%1/3
A //= B
A= $commands->{$command}B= sub { die "not implemented\n"; }
ABresult
1X1
011
000
296 }
297  
298 26 ▶ croak sprintf "ERROR: 'commands' is required\nusage: %s->new( option_specs => specs, commands => commands);\n", __PACKAGE__
Branch: 1 branch
BranchTrueFalseTotal
unless $option_specs and $commands 0 26 26
Condition33%1/3
$option_specs and $commands
!ll&&!rl&&r
0026
MC/DC0%0/2
$option_specs and $commands
$option_specs $commands
Truth table33%1/3
A and B
A= $option_specsB= $commands
ABresult
0X0
100
111
299 if !$option_specs || !$commands;
300  
301 26 my %command_target = map { $_ => $_ } keys %{$commands};
302  
303 26 ▶ $default_options //= {};
Condition100%2/2
$default_options //= {}
l!l
620
MC/DC100%1/1
$default_options //= {}
$default_options
Truth table100%2/2
A
A= $default_options
Aresult
11
00
304  
305 26 my $options = { %{$default_options} };
306  
307 26 ▶ if ( $class->_use_logger && none { $_ eq 'log-level' } @{$option_specs} ) {
Subroutine __ANON__: not called CC=1 SCAR=2.2
Branch: 1 branch
BranchTrueFalseTotal
if ($class->_use_logger and &none(sub { $_ eq "log-level"; } , @{$option_specs;})) 0 26 26
Condition33%1/3
$class->_use_logger and &none(sub { $_ eq "log-level"; } , @{$option_specs;})
!ll&&!rl&&r
2600
MC/DC0%0/2
$class->_use_logger and &none(sub { $_ eq "log-level"; } , @{$option_specs;})
$class->_use_logger &none(sub { $_ eq "log-level"; } , @{$option_specs;})
Truth table33%1/3
A and B
A= $class->_use_loggerB= &none(sub { $_ eq "log-level"; } , @{$option_specs;})
ABresult
0X0
100
111
308 0 push @{$option_specs}, 'log-level=s';
309 }
310  
311 # if we have an option alias, make sure the option alias spec is set too
312 26 ▶ if ( $alias && ref $alias && $alias->{options} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias and ref $alias and $alias->{"options"}) 7 19 26
Condition83%5/6
$alias and ref $alias and $alias->{"options"}
!ll&&!rl&&r
1367
$alias and ref $alias
!ll&&!rl&&r
13013
MC/DC66%2/3
$alias and ref $alias and $alias->{"options"}
$alias ref $alias $alias->{"options"}
Truth table75%3/4
A and B and C
A= $aliasB= ref $aliasC= $alias->{"options"}
ABCresult
0XX0
10X0
1100
1111
313 7 foreach my $p ( pairs %{ $alias->{options} } ) {
314 7 my ( $aka, $name ) = @{$p};
315  
316 # Does an option named $aka already exist (with or without a spec)?
317 7 ▶ my $aka_exists = any {/^\Q$aka\E(?:[^\w-].*)?$/xsm} @{$option_specs};
Subroutine __ANON__: called CC=1 SCAR=0.0
318  
319 7 ▶ if ( !$aka_exists ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($aka_exists) 2 5 7
320  
321 # Find the canonical spec for $name
322 2 my ($spec) = grep {/^\Q$name\E(?:[^\w-].*)?$/xsm} @{$option_specs};
323 2 ▶ croak sprintf 'ERROR: no such option defined: %s', $name if !$spec;
Branch: 1 branch
BranchTrueFalseTotal
unless $spec 0 2 2
324  
325 # Pull just the specifier part (e.g., '=s', ':i', '!', '+', etc.)
326 2 my ($spec_part) = $spec =~ /^\Q$name\E(?:[|].)?([^\w-].*)?$/xsm;
327  
328 2 ▶ $spec_part ||= q{};
Condition50%1/2
$spec_part ||= ""
l!l
20
MC/DC0%0/1
$spec_part ||= ""
$spec_part
Truth table50%1/2
A
A= $spec_part
Aresult
11
00
329  
330 2 push @{$option_specs}, $aka . $spec_part;
331 }
332 }
333 }
334  
335 26 ▶ if ( @ARGV && $ARGV[0] =~ /^-[[:alpha:]]/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV and $ARGV[0] =~ /^-[[:alpha:]]/msx) 0 26 26
Condition66%2/3
@ARGV and $ARGV[0] =~ /^-[[:alpha:]]/msx
!ll&&!rl&&r
6200
MC/DC0%0/2
@ARGV and $ARGV[0] =~ /^-[[:alpha:]]/msx
@ARGV $ARGV[0] =~ /^-[[:alpha:]]/msx
Truth table66%2/3
A and B
A= @ARGVB= $ARGV[0] =~ /^-[[:alpha:]]/msx
ABresult
0X0
100
111
336 0 ▶ if ( my $handler = $INTERNAL_COMMANDS{ $ARGV[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $CLI::Simple::INTERNAL_COMMANDS{$ARGV[0]}) 0 0 0
337 0 exit $handler->( $class, $commands, $option_specs );
338 }
339 }
340  
341 26 ▶ $GETOPT_STATUS = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
342 26 ▶ local $SIG{__WARN__} = sub { $GETOPT_ERROR_MESSAGE = shift; return; };
Subroutine __ANON__: called CC=1 SCAR=0.0
343  
344 26 return GetOptions( $options, @{$option_specs} );
345 }
346 26 ->();
347  
348 26 normalize_options($options);
349  
350 26 my %cli_options;
351  
352 my @accessors
353 26 ▶ = ( @{ $extra_options || [] }, map { ( split /[^\w\-]/xsm )[0] } @{$option_specs} );
Condition100%2/2
$extra_options || []
l!l
620
MC/DC100%1/1
$extra_options || []
$extra_options
Truth table100%2/2
A
A= $extra_options
Aresult
11
00
354  
355 26 foreach (@accessors) {
356 28 ▶ die "ERROR: accessor must be a scalar\n" # somebody did @extra_options = [qw( a b c )] ???
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 0 28 28
357 if ref $_;
358  
359 28 s/\-/_/xsmg;
360  
361 # can() can't tell "a human hand-wrote this method" apart from
362 # "mk_accessors already generated this on an earlier ->new() call
363 # for this same class" -- both look identical. Only the latter is
364 # fine (constructing multiple instances of the same class within
365 # one process is completely normal); only the former is the
366 # genuine naming collision this check exists to catch. Track what
367 # this class has already generated, per class, so a repeat
368 # construction doesn't get mistaken for a hand-written conflict.
369 28 ▶ if ( !$GENERATED_ACCESSOR{$class}{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($GENERATED_ACCESSOR{$class}{$_}) 7 21 28
370 7 ▶ die "ERROR: accessor for $_ already exists!\n"
Branch: 1 branch
BranchTrueFalseTotal
if $class->can('get_' . $_) or $class->can('set_' . $_) 0 7 7
Condition33%1/3
$class->can('get_' . $_) or $class->can('set_' . $_)
l!l&&r!l&&!r
007
MC/DC0%0/2
$class->can('get_' . $_) or $class->can('set_' . $_)
$class->can('get_' . $_) $class->can('set_' . $_)
Truth table33%1/3
A or B
A= $class->can('get_' . $_)B= $class->can('set_' . $_)
ABresult
1X1
011
000
371 if $class->can( 'get_' . $_ ) || $class->can( 'set_' . $_ );
372  
373 7 $class->mk_accessors($_);
374  
375 7 $GENERATED_ACCESSOR{$class}{$_} = $TRUE;
376 }
377  
378 28 $cli_options{$_} = $options->{$_};
379 }
380  
381 26 ▶ if ( !$error_handler && !$GETOPT_STATUS ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $error_handler || $CLI::Simple::GETOPT_STATUS) { } 2 24 26
elsif (not $CLI::Simple::GETOPT_STATUS) { } 0 24 24
Condition66%2/3
$error_handler || $CLI::Simple::GETOPT_STATUS
l!l&&r!l&&!r
0242
MC/DC50%1/2
$error_handler || $CLI::Simple::GETOPT_STATUS
$error_handler $CLI::Simple::GETOPT_STATUS
Truth table66%2/3
A || B
A= $error_handlerB= $CLI::Simple::GETOPT_STATUS
ABresult
1X1
011
000
382 2 print {*STDERR} $GETOPT_ERROR_MESSAGE;
383 2 ▶ if ($GETOPT_EXIT_ON_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CLI::Simple::GETOPT_EXIT_ON_ERROR) 2 0 2
384 2 _leave($FAILURE);
385 }
386 }
387 elsif ( !$GETOPT_STATUS ) {
388 0 ▶ if ( !$error_handler->($GETOPT_ERROR_MESSAGE) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$error_handler($CLI::Simple::GETOPT_ERROR_MESSAGE)) 0 0 0
389 0 _leave($FAILURE);
390 }
391 }
392  
393 24 ▶ croak "ERROR: alias must be a hash ref with keys 'options' or 'commands'\n"
Branch: 1 branch
BranchTrueFalseTotal
if $alias and not ref $alias 0 24 24
Condition66%2/3
$alias and not ref $alias
!ll&&!rl&&r
11130
MC/DC0%0/2
$alias and not ref $alias
$alias not ref $alias
Truth table66%2/3
A and not(B)
A= $aliasB= not ref $alias
ABresult
0X0
100
111
394 if $alias && !ref $alias;
395  
396 24 ▶ if ($alias) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) 13 11 24
397 13 ▶ if ( $alias->{options} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias->{"options"}) 7 6 13
398 7 foreach my $p ( pairs %{ $alias->{options} } ) {
399 7 my ( $aka, $name ) = @{$p};
400 7 $aka =~ s/[-]/_/gxsm;
401 7 $name =~ s/[-]/_/gxsm;
402  
403 7 ▶ if ( defined $cli_options{$name} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $cli_options{$name}) { } 6 1 7
elsif (defined $cli_options{$aka}) { } 1 0 1
404 6 $cli_options{$aka} = $cli_options{$name};
405 }
406 elsif ( defined $cli_options{$aka} ) {
407 1 $cli_options{$name} = $cli_options{$aka};
408 }
409 }
410 }
411  
412 # command aliases are a convenience so someone doesn't have to add
413 # to $commands manually
414  
415 13 ▶ if ( $alias->{commands} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias->{"commands"}) 2 11 13
416 2 foreach my $p ( pairs %{ $alias->{commands} } ) {
417 2 my ( $aka, $name ) = @{$p};
418  
419 croak sprintf "ERROR: no command: %s\n", $name
420 2 ▶ if !$commands->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $commands->{$name} 0 2 2
421  
422 2 $commands->{$aka} = $commands->{$name};
423 2 $command_target{$aka} = $name;
424 }
425 }
426 }
427  
428 24 my $self = $class->SUPER::new( \%cli_options );
429  
430 24 ▶ if ( !$self->can('get_help_sections') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->can('get_help_sections')) { } 13 11 24
431 13 $self->mk_accessors('help_sections');
432 13 $GENERATED_ACCESSOR{$class}{help_sections} = $TRUE;
433 }
434 else {
435 11 ▶ $help_sections //= $self->get_help_sections;
Condition33%1/3
$help_sections //= $self->get_help_sections
l!l&&r!l&&!r
0011
MC/DC0%0/2
$help_sections //= $self->get_help_sections
$help_sections $self->get_help_sections
Truth table33%1/3
A //= B
A= $help_sectionsB= $self->get_help_sections
ABresult
1X1
011
000
436 }
437  
438 24 ▶ $help_sections //= [@DEFAULT_HELP_SECTIONS];
Condition50%1/2
$help_sections //= [@CLI::Simple::DEFAULT_HELP_SECTIONS]
l!l
024
MC/DC0%0/1
$help_sections //= [@CLI::Simple::DEFAULT_HELP_SECTIONS]
$help_sections
Truth table50%1/2
A
A= $help_sections
Aresult
11
00
439  
440 24 $self->set_help_sections($help_sections);
441  
442 # AUTO_DEFAULT uses the only command as the default
443 24 ▶ if ( $AUTO_DEFAULT && scalar keys %{$commands} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CLI::Simple::AUTO_DEFAULT and scalar keys %{$commands;} == 1) 2 22 24
Condition100%3/3
$CLI::Simple::AUTO_DEFAULT and scalar keys %{$commands;} == 1
!ll&&!rl&&r
2112
MC/DC100%2/2
$CLI::Simple::AUTO_DEFAULT and scalar keys %{$commands;} == 1
$CLI::Simple::AUTO_DEFAULT scalar keys %{$commands;} == 1
Truth table100%3/3
A and B
A= $CLI::Simple::AUTO_DEFAULTB= scalar keys %{$commands;} == 1
ABresult
0X0
100
111
444 2 my ($command) = keys %{$commands};
445  
446 2 ▶ if ( @ARGV && $ARGV[0] ne $command ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@ARGV and $ARGV[0] ne $command) { } 1 1 2
elsif (not @ARGV) { } 1 0 1
Condition66%2/3
@ARGV and $ARGV[0] ne $command
!ll&&!rl&&r
101
MC/DC50%1/2
@ARGV and $ARGV[0] ne $command
@ARGV $ARGV[0] ne $command
Truth table66%2/3
A and B
A= @ARGVB= $ARGV[0] ne $command
ABresult
0X0
100
111
447 1 unshift @ARGV, $command;
448 }
449 elsif ( !@ARGV ) {
450 1 unshift @ARGV, $command;
451 }
452 }
453  
454 24 ▶ my $command = shift @ARGV // $EMPTY;
Condition66%2/3
shift @ARGV // $CLI::Simple::EMPTY
l!l&&r!l&&!r
1905
MC/DC50%1/2
shift @ARGV // $CLI::Simple::EMPTY
shift @ARGV $CLI::Simple::EMPTY
Truth table66%2/3
A // B
A= shift @ARGVB= $CLI::Simple::EMPTY
ABresult
1X1
011
000
455  
456 24 ▶ if ( !$command ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($command) 5 19 24
457 5 ▶ if ( $commands->{default} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($commands->{'default'}) { } 0 5 5
elsif ($CLI::Simple::AUTO_HELP) { } 1 4 5
458 0 ▶ $command = ref $commands->{default} ? 'default' : $commands->{default};
Branch: 1 branch
BranchTrueFalseTotal
ref $commands->{'default'} ? : 0 0 0
459 }
460 elsif ($AUTO_HELP) {
461 1 $command = 'help';
462 }
463 }
464  
465 24 $self->set__validate_command($validate_command);
466  
467 24 $self->set__command($command);
468  
469 24 $self->set__command_args( [@ARGV] );
470  
471 24 $self->set__commands($commands);
472  
473 24 $self->set__program("$RealBin/$RealScript");
474  
475 24 ▶ if ( $command eq 'help' || ( $self->can('get_help') && $self->get_help ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "help" or $self->can("get_help") and $self->get_help) 1 23 24
Condition50%3/6
$command eq "help" or $self->can("get_help") and $self->get_help
l!l&&r!l&&!r
1023
$self->can("get_help") and $self->get_help
!ll&&!rl&&r
2300
MC/DC33%1/3
$command eq "help" or $self->can("get_help") and $self->get_help
$command eq "help" $self->can("get_help") $self->get_help
Truth table50%2/4
A or B and C
A= $command eq "help"B= $self->can("get_help")C= $self->get_help
ABCresult
1XX1
0111
00X0
0100
476 # custom help function?
477  
478 1 my $help = $commands->{help};
479  
480 1 ▶ if ( !$help ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($help) 1 0 1
481 1 $self->usage;
482 }
483  
484 0 ▶ if ( ref $help && reftype($help) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $help and builtin::reftype($help) eq 'ARRAY') { } 0 0 0
Condition0%0/3
ref $help and builtin::reftype($help) eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $help and builtin::reftype($help) eq "ARRAY"
ref $help builtin::reftype($help) eq "ARRAY"
Truth table0%0/3
A and B
A= ref $helpB= builtin::reftype($help) eq "ARRAY"
ABresult
0X0
100
111
485 0 $help->[0]->( $self, $TRUE );
486 }
487 else {
488 0 $help->( $self, $TRUE );
489 }
490 }
491  
492 23 ▶ $self->set__abbreviations( $abbreviations // $FALSE );
Condition66%2/3
$abbreviations // $CLI::Simple::FALSE
l!l&&r!l&&!r
8015
MC/DC50%1/2
$abbreviations // $CLI::Simple::FALSE
$abbreviations $CLI::Simple::FALSE
Truth table66%2/3
A // B
A= $abbreviationsB= $CLI::Simple::FALSE
ABresult
1X1
011
000
493  
494 23 $self->validate_command;
495 21 $command = $self->command;
496  
497 21 ▶ if ($command) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command) 17 4 21
498 17 ▶ my $target_command = $command_target{$command} // $command;
Condition33%1/3
$command_target{$command} // $command
l!l&&r!l&&!r
1700
MC/DC0%0/2
$command_target{$command} // $command
$command_target{$command} $command
Truth table33%1/3
A // B
A= $command_target{$command}B= $command
ABresult
1X1
011
000
499  
500 17 ▶ if ( exists $command_roles->{$target_command} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $command_roles->{$target_command}) { } 5 12 17
elsif (exists $manifest_commands->{$target_command}) { } 1 11 12
501 5 my $roles = $command_roles->{$target_command};
502  
503 5 require Role::Tiny;
504 5 Role::Tiny->apply_roles_to_package( $class, @{$roles} );
505  
506 5 ( my $method = "cmd_$target_command" ) =~ s/-/_/gxsm;
507  
508 5 ▶ die sprintf "ERROR: roles for command '%s' do not implement %s\n", $target_command, $method
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can($method) 1 4 5
509 if !$class->can($method);
510  
511 4 my $handler = $class->can($method);
512  
513 4 $commands->{$target_command} = $handler;
514 4 $commands->{$command} = $handler;
515 }
516 elsif ( exists $manifest_commands->{$target_command} ) {
517  
518 #
519 # Legacy semantics: selecting ONE legacy command opts into
520 # composition of the entire legacy role set.
521 #
522  
523 1 my %seen;
524 1 ▶ my @roles = grep { !$seen{$_}++ && _is_class_name($_) } values %{$manifest_commands};
Condition33%1/3
!$seen{$_}++ && _is_class_name($_)
!ll&&!rl&&r
002
MC/DC0%0/2
!$seen{$_}++ && _is_class_name($_)
!$seen{$_}++ _is_class_name($_)
Truth table33%1/3
not(A) && B
A= !$seen{$_}++B= _is_class_name($_)
ABresult
0X0
100
111
525  
526 1 require Role::Tiny;
527 1 Role::Tiny->apply_roles_to_package( $class, @roles );
528  
529 1 foreach my $cmd ( keys %{$manifest_commands} ) {
530 2 my $value = $manifest_commands->{$cmd};
531  
532 2 ▶ my $method = choose {
Subroutine __ANON__: called CC=2 SCAR=7.1
533 2 ▶ return $value
Branch: 1 branch
BranchTrueFalseTotal
unless _is_class_name($value) 0 2 2
534 if !_is_class_name($value);
535  
536 2 ( my $m = "cmd_$cmd" ) =~ s/-/_/gxsm;
537 2 return $m;
538 2 };
539  
540 2 ▶ die sprintf "ERROR: %s does not implement %s\n", $value, $method
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can($method) 0 2 2
541 if !$class->can($method);
542  
543 2 $commands->{$cmd} = $class->can($method);
544 }
545  
546 #
547 # Restore aliases now that the placeholder handlers have
548 # been replaced by the real legacy dispatch handlers.
549 #
550  
551 1 foreach my $aka ( keys %command_target ) {
552 2 my $target = $command_target{$aka};
553  
554 next
555 2 ▶ if $aka eq $target;
Branch: 1 branch
BranchTrueFalseTotal
if $aka eq $target 2 0 2
556  
557 $commands->{$aka} = $commands->{$target}
558 0 ▶ if exists $commands->{$target};
Branch: 1 branch
BranchTrueFalseTotal
if exists $commands->{$target} 0 0 0
559 }
560 }
561 }
562  
563 20 $self->init_logger;
564  
565 20 ▶ $self->can('init') && $self->init();
Branch: 1 branch
BranchTrueFalseTotal
$self->can("init") and $self->init 0 20 20
566  
567 20 return $self;
568 }
569  
570 ########################################################################
571 4 ▶sub _pod_has_section {
Subroutine _pod_has_section: called CC=4 SCAR=13.9
572 ########################################################################
573 4 my ( $filename, $section ) = @_;
574  
575 4 ▶ open my $fh, '<', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or return $CLI::Simple::FALSE 4 0 4
576 or return $FALSE;
577  
578 4 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 163 1 164
579 163 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A=head1\s+\Q$section\E\s*\z/msx 3 160 163
580 if $line =~ /\A=head1\s+\Q$section\E\s*\z/xsm;
581 }
582  
583 1 return $FALSE;
584 }
585  
586 ########################################################################
587 5 ▶sub _get_help_sections {
Subroutine _get_help_sections: called CC=5 SCAR=16.1
588 ########################################################################
589 5 my ( $self, $input ) = @_;
590  
591 5 my $sections = $self->get_help_sections;
592  
593 return $sections
594 5 ▶ if @{$sections} != @DEFAULT_HELP_SECTIONS;
Branch: 1 branch
BranchTrueFalseTotal
if @{$sections;} != @CLI::Simple::DEFAULT_HELP_SECTIONS 1 4 5
595  
596 4 for my $idx ( 0 .. $#DEFAULT_HELP_SECTIONS ) {
597 20 ▶ return $sections
Branch: 1 branch
BranchTrueFalseTotal
if $sections->[$idx] ne $CLI::Simple::DEFAULT_HELP_SECTIONS[$idx] 0 20 20
598 if $sections->[$idx] ne $DEFAULT_HELP_SECTIONS[$idx];
599 }
600  
601 4 ▶ return [ _pod_has_section( $input, 'USAGE' )
Branch: 1 branch
BranchTrueFalseTotal
_pod_has_section($input, 'USAGE') ? : 3 1 4
602 ? 'USAGE'
603 : 'SYNOPSIS',
604 'DESCRIPTION/Commands', 'DESCRIPTION/Options', 'OPTIONS', ];
605 }
606  
607 ########################################################################
608 7 ▶sub _leave {
Subroutine _leave: called CC=2 SCAR=7.1
609 ########################################################################
610 7 my (@args) = @_;
611  
612 7 ▶ my ($exit_code) = ref $args[0] ? $args[1] : $args[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 0 7 7
613  
614 7 exit $exit_code;
615 }
616  
617 ########################################################################
618 0 ▶sub _set_color_config {
Subroutine _set_color_config: not called CC=7 SCAR=40.3
619 ########################################################################
620 0 my ( $self, %args ) = @_;
621  
622 return sprintf $LOG4PERL_CONF,
623 $args{debug_color} // $LOG4PERL_COLOR_DEBUG,
624 $args{info_color} // $LOG4PERL_COLOR_INFO,
625 $args{warn_color} // $LOG4PERL_COLOR_WARN,
626 $args{error_color} // $LOG4PERL_COLOR_ERROR,
627 $args{fatal_color} // $LOG4PERL_COLOR_FATAL,
628 0 ▶ $args{trace_color} // $LOG4PERL_COLOR_TRACE;
Condition0%0/18
$args{"debug_color"} // $CLI::Simple::LOG4PERL_COLOR_DEBUG
l!l&&r!l&&!r
000
$args{"info_color"} // $CLI::Simple::LOG4PERL_COLOR_INFO
l!l&&r!l&&!r
000
$args{"warn_color"} // $CLI::Simple::LOG4PERL_COLOR_WARN
l!l&&r!l&&!r
000
$args{"error_color"} // $CLI::Simple::LOG4PERL_COLOR_ERROR
l!l&&r!l&&!r
000
$args{"fatal_color"} // $CLI::Simple::LOG4PERL_COLOR_FATAL
l!l&&r!l&&!r
000
$args{"trace_color"} // $CLI::Simple::LOG4PERL_COLOR_TRACE
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"debug_color"} // $CLI::Simple::LOG4PERL_COLOR_DEBUG
$args{"debug_color"} $CLI::Simple::LOG4PERL_COLOR_DEBUG
MC/DC0%0/2
$args{"info_color"} // $CLI::Simple::LOG4PERL_COLOR_INFO
$args{"info_color"} $CLI::Simple::LOG4PERL_COLOR_INFO
MC/DC0%0/2
$args{"warn_color"} // $CLI::Simple::LOG4PERL_COLOR_WARN
$args{"warn_color"} $CLI::Simple::LOG4PERL_COLOR_WARN
MC/DC0%0/2
$args{"error_color"} // $CLI::Simple::LOG4PERL_COLOR_ERROR
$args{"error_color"} $CLI::Simple::LOG4PERL_COLOR_ERROR
MC/DC0%0/2
$args{"fatal_color"} // $CLI::Simple::LOG4PERL_COLOR_FATAL
$args{"fatal_color"} $CLI::Simple::LOG4PERL_COLOR_FATAL
MC/DC0%0/2
$args{"trace_color"} // $CLI::Simple::LOG4PERL_COLOR_TRACE
$args{"trace_color"} $CLI::Simple::LOG4PERL_COLOR_TRACE
Truth table0%0/3
A // B
A= $args{"debug_color"}B= $CLI::Simple::LOG4PERL_COLOR_DEBUG
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"info_color"}B= $CLI::Simple::LOG4PERL_COLOR_INFO
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"warn_color"}B= $CLI::Simple::LOG4PERL_COLOR_WARN
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"error_color"}B= $CLI::Simple::LOG4PERL_COLOR_ERROR
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"fatal_color"}B= $CLI::Simple::LOG4PERL_COLOR_FATAL
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"trace_color"}B= $CLI::Simple::LOG4PERL_COLOR_TRACE
ABresult
1X1
011
000
629 }
630  
631 ########################################################################
632 20 ▶sub init_logger {
Subroutine init_logger: called CC=23 SCAR=58.5
Pod undocumented
633 ########################################################################
634 20 my ($self) = @_;
635  
636 20 ▶ if ( $self->_use_logger && $self->can('get_log4perl_conf') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_use_logger and $self->can("get_log4perl_conf")) 0 20 20
Condition33%1/3
$self->_use_logger and $self->can("get_log4perl_conf")
!ll&&!rl&&r
2000
MC/DC0%0/2
$self->_use_logger and $self->can("get_log4perl_conf")
$self->_use_logger $self->can("get_log4perl_conf")
Truth table33%1/3
A and B
A= $self->_use_loggerB= $self->can("get_log4perl_conf")
ABresult
0X0
100
111
637  
638 0 my $config = $self->get_log4perl_conf;
639  
640 0 ▶ my $color = $self->can('get_color') && defined $self->get_color ? $self->get_color : $config && $config eq $LOG4PERL_CONF;
Branch: 1 branch
BranchTrueFalseTotal
$self->can('get_color') && defined $self->get_color ? : 0 0 0
Condition0%0/6
$self->can("get_color") and defined $self->get_color
!ll&&!rl&&r
000
$config and $config eq $CLI::Simple::LOG4PERL_CONF
!ll&&!rl&&r
000
MC/DC0%0/2
$self->can("get_color") and defined $self->get_color
$self->can("get_color") defined $self->get_color
MC/DC0%0/2
$config and $config eq $CLI::Simple::LOG4PERL_CONF
$config $config eq $CLI::Simple::LOG4PERL_CONF
Truth table0%0/3
A and B
A= $self->can("get_color")B= defined $self->get_color
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $configB= $config eq $CLI::Simple::LOG4PERL_CONF
ABresult
0X0
100
111
641  
642 0 ▶ $color = $color && eval { require Term::ANSIColor; 1; };
Condition0%0/3
$color && eval { do { require Term::ANSIColor; 1 } }
!ll&&!rl&&r
000
MC/DC0%0/2
$color && eval { do { require Term::ANSIColor; 1 } }
$color eval { do { require Term::ANSIColor; 1 } }
Truth table0%0/3
A && B
A= $colorB= eval { do { require Term::ANSIColor; 1 } }
ABresult
0X0
100
111
643  
644 # color on, but not done through use_log4perl?
645 0 ▶ if ( $color && !$config ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($color and not $config) { } 0 0 0
elsif (not $color and $config and $config =~ /screencoloredlevels/imsx) { } 0 0 0
Condition0%0/3
$color and not $config
!ll&&!rl&&r
000
MC/DC0%0/2
$color and not $config
$color not $config
Truth table0%0/3
A and not(B)
A= $colorB= not $config
ABresult
0X0
100
111
646 0 $config = $self->_set_color_config;
647 }
648 ▶ elsif ( !$color && $config && $config =~ /screencoloredlevels/xsmi ) {
Condition0%0/6
not $color and $config and $config =~ /screencoloredlevels/imsx
!ll&&!rl&&r
000
not $color and $config
!ll&&!rl&&r
000
MC/DC0%0/3
not $color and $config and $config =~ /screencoloredlevels/imsx
not $color $config $config =~ /screencoloredlevels/imsx
Truth table0%0/4
not(A) and B and C
A= not $colorB= $configC= $config =~ /screencoloredlevels/imsx
ABCresult
0XX0
10X0
1100
1111
649 0 $config = q{};
650 }
651  
652 0 $self->set_log4perl_conf($config);
653  
654 0 ▶ if ($config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config) { } 0 0 0
655 0 ▶ Log::Log4perl->init( ref $config ? $config : \$config );
Branch: 1 branch
BranchTrueFalseTotal
ref $config ? : 0 0 0
656 }
657 else {
658 0 Log::Log4perl->import(':easy');
659 0 Log::Log4perl->easy_init( $LOG_LEVELS{error} );
660 }
661  
662 0 my $logger = Log::Log4perl->get_logger(q{});
663  
664 0 $self->set_logger($logger);
665  
666 0 ▶ my $level = $self->get_log_level // $self->get_log4perl_level;
Condition0%0/3
$self->get_log_level // $self->get_log4perl_level
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_log_level // $self->get_log4perl_level
$self->get_log_level $self->get_log4perl_level
Truth table0%0/3
A // B
A= $self->get_log_levelB= $self->get_log4perl_level
ABresult
1X1
011
000
667  
668 0 $self->set_log_level($level);
669  
670 0 ▶ if ($level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) 0 0 0
671 0 $logger->level( $LOG_LEVELS{$level} );
672 }
673 }
674  
675 20 my $commands = $self->commands;
676 20 my $command = $self->command;
677  
678 return $self
679 20 ▶ if !$command || !$commands->{$command} || !ref( $commands->{command} ) || reftype( $commands->{$command} ) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if not $command && $commands->{$command} && ref $commands->{"command"} or builtin::reftype($commands->{$command}) ne "ARRAY" 20 0 20
Condition55%5/9
not $command && $commands->{$command} && ref $commands->{"command"} or builtin::reftype($commands->{$command}) ne "ARRAY"
l!l&&r!l&&!r
2000
$command && $commands->{$command} && ref $commands->{'command'}
!ll&&!rl&&r
4160
$command and $commands->{$command}
!ll&&!rl&&r
4016
MC/DC0%0/4
not $command && $commands->{$command} && ref $commands->{"command"} or builtin::reftype($commands->{$command}) ne "ARRAY"
$command $commands->{$command} ref $commands->{'command'} builtin::reftype($commands->{$command}) ne "ARRAY"
Truth table40%2/5
not(A and B && C) or D
A= $commandB= $commands->{$command}C= ref $commands->{'command'}D= builtin::reftype($commands->{$command}) ne "ARRAY"
ABCDresult
0XXX1
10XX1
110X1
11111
11100
680  
681 0 my ( $sub, $log_level ) = @{ $commands->{$command} };
682  
683 0 ▶ return $self
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_logger 0 0 0
684 if !$self->get_logger;
685  
686 0 ▶ $log_level = $self->get_log_level // $log_level;
Condition0%0/3
$self->get_log_level // $log_level
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_log_level // $log_level
$self->get_log_level $log_level
Truth table0%0/3
A // B
A= $self->get_log_levelB= $log_level
ABresult
1X1
011
000
687  
688 0 ▶ $self->get_logger->level( $LOG_LEVELS{$log_level} // $LOG_LEVELS{info} );
Condition0%0/3
$CLI::Simple::LOG_LEVELS{$log_level} // $CLI::Simple::LOG_LEVELS{"info"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$CLI::Simple::LOG_LEVELS{$log_level} // $CLI::Simple::LOG_LEVELS{"info"}
$CLI::Simple::LOG_LEVELS{$log_level} $CLI::Simple::LOG_LEVELS{"info"}
Truth table0%0/3
A // B
A= $CLI::Simple::LOG_LEVELS{$log_level}B= $CLI::Simple::LOG_LEVELS{"info"}
ABresult
1X1
011
000
689  
690 0 return $self;
691 }
692  
693 ########################################################################
694 0 ▶sub get_kv_args {
Subroutine get_kv_args: not called CC=2 SCAR=17.9
Pod undocumented
695 ########################################################################
696 0 my ($self) = @_;
697  
698 0 my @arg_list = @{ $self->get__command_args };
699  
700 0 my %args;
701  
702 0 foreach (@arg_list) {
703 0 my ( $k, $v ) = split /=/xsm;
704 0 $args{$k} = $v;
705 }
706  
707 0 return %args;
708 }
709  
710 ########################################################################
711 0 ▶sub set_args {
Subroutine set_args: not called CC=1 SCAR=6.9
Pod undocumented
712 ########################################################################
713 0 my ( $self, $args ) = @_;
714  
715 0 $self->set__command_args($args);
716  
717 0 return $args;
718 }
719  
720 ########################################################################
721 4 ▶sub get_args {
Subroutine get_args: called CC=5 SCAR=16.1
Pod documented
722 ########################################################################
723 4 my ( $self, @vars ) = @_;
724  
725 4 my $command_args = $self->get__command_args;
726  
727 4 ▶ return wantarray ? @{$command_args} : $command_args
Branch: 2 branches
BranchTrueFalseTotal
unless @vars 2 2 4
wantarray ? : 2 0 2
728 if !@vars;
729  
730 2 ▶ @vars = map { $_ ? $_ : '<undef>' } @vars;
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 5 1 6
731  
732 2 my %args;
733 2 @args{@vars} = @{$command_args}[ 0 .. $#vars ];
734  
735 2 delete $args{'<undef>'};
736  
737 2 ▶ return wantarray ? %args : \%args;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
738 }
739  
740 ########################################################################
741 0 ▶sub default_command {
Subroutine default_command: not called CC=1 SCAR=6.9
Pod undocumented
742 ########################################################################
743 0 goto &usage;
744 }
745  
746 ########################################################################
747 5 ▶sub usage {
Subroutine usage: called CC=5 SCAR=18.0
Pod documented
748 ########################################################################
749 5 my ($self) = @_;
750  
751 5 require Pod::Usage;
752  
753 5 ▶ my $wrapper = $ENV{MODULINO_WRAPPER} // q{};
Condition50%1/2
$ENV{"MODULINO_WRAPPER"} // ""
l!l
05
MC/DC0%0/1
$ENV{"MODULINO_WRAPPER"} // ""
$ENV{"MODULINO_WRAPPER"}
Truth table50%1/2
A
A= $ENV{"MODULINO_WRAPPER"}
Aresult
11
00
754  
755 5 ▶ my $input = $wrapper eq 'cli-simple' ? $INC{'CLI/Simple/Shell.pm'} : $self->get__program;
Branch: 1 branch
BranchTrueFalseTotal
$wrapper eq 'cli-simple' ? : 0 5 5
756  
757 5 ▶ if ( $PAGER && IO::Interactive::is_interactive ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CLI::Simple::PAGER and IO::Interactive::is_interactive()) 0 5 5
Condition66%2/3
$CLI::Simple::PAGER and IO::Interactive::is_interactive()
!ll&&!rl&&r
410
MC/DC0%0/2
$CLI::Simple::PAGER and IO::Interactive::is_interactive()
$CLI::Simple::PAGER IO::Interactive::is_interactive()
Truth table66%2/3
A and B
A= $CLI::Simple::PAGERB= IO::Interactive::is_interactive()
ABresult
0X0
100
111
758 0 eval {
759 0 require IO::Pager;
760 0 IO::Pager->new(*STDOUT);
761 };
762 }
763  
764 5 my $sections = $self->_get_help_sections($input);
765  
766 5 Pod::Usage::pod2usage(
767 -noperldoc => 1,
768 -exitval => 'NOEXIT',
769 -input => $input,
770 -verbose => 99,
771 -sections => $sections,
772 );
773  
774 5 return _leave($FAILURE);
775 }
776  
777 ########################################################################
778 0 ▶sub example {
Subroutine example: not called CC=1 SCAR=6.9
Pod undocumented
779 ########################################################################
780 0 require File::ShareDir;
781  
782 0 print {*STDOUT} slurp File::ShareDir::dist_file( 'CLI-Simple', 'MyScript.pm' );
783  
784 0 return 0;
785 }
786  
787 ########################################################################
788 75 ▶sub command {
Subroutine command: called CC=2 SCAR=7.6
Pod documented
789 ########################################################################
790 75 my ( $self, $command ) = @_;
791  
792 75 ▶ if ($command) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command) 0 75 75
793 0 $self->set__command($command);
794 }
795  
796 75 return $self->get__command;
797 }
798  
799 ########################################################################
800 0 ▶sub command_args {
Subroutine command_args: not called CC=3 SCAR=24.8
Pod documented
801 ########################################################################
802 0 my ( $self, @args ) = @_;
803  
804 0 ▶ return $self->get__command_args
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 0 0
805 if !@args;
806  
807 0 ▶ if ( ref $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0]) 0 0 0
808 0 $self->set__command_args( $args[0] );
809 0 return;
810 }
811  
812 0 $self->set__command_args( [@args] );
813  
814 0 return;
815 }
816  
817 ########################################################################
818 50 ▶sub commands {
Subroutine commands: called CC=4 SCAR=18.7
Pod documented
819 ########################################################################
820 50 my ( $self, $command, $handler ) = @_;
821  
822 50 my $commands = $self->get__commands;
823  
824 50 ▶ if ( $command && $handler ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command and $handler) 0 50 50
Condition33%1/3
$command and $handler
!ll&&!rl&&r
5000
MC/DC0%0/2
$command and $handler
$command $handler
Truth table33%1/3
A and B
A= $commandB= $handler
ABresult
0X0
100
111
825  
826 0 ▶ croak "ERROR: usage: commands([command, subref])\n"
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($handler) ne "CODE" 0 0 0
827 if reftype($handler) ne 'CODE';
828  
829 0 $commands->{$command} = $handler;
830 }
831  
832 50 return $commands;
833 }
834  
835 ########################################################################
836 11 ▶sub program {
Subroutine program: called CC=1 SCAR=0.0
Pod undocumented
837 ########################################################################
838 11 my ($self) = @_;
839  
840 11 return $self->get__program;
841 }
842  
843 ########################################################################
844 23 ▶sub validate_command {
Subroutine validate_command: called CC=7 SCAR=19.5
Pod documented
845 ########################################################################
846 23 my ($self) = @_;
847  
848 23 my $command = $self->command;
849  
850 return
851 23 ▶ if !$command || !$self->get__validate_command;
Branch: 1 branch
BranchTrueFalseTotal
unless $command and $self->get__validate_command 4 19 23
Condition66%2/3
$command and $self->get__validate_command
!ll&&!rl&&r
4019
MC/DC50%1/2
$command and $self->get__validate_command
$command $self->get__validate_command
Truth table66%2/3
A and B
A= $commandB= $self->get__validate_command
ABresult
0X0
100
111
852  
853 19 my $commands = $self->commands;
854  
855 return $command
856 19 ▶ if defined $commands->{$command};
Branch: 1 branch
BranchTrueFalseTotal
if defined $commands->{$command} 15 4 19
857  
858 4 ▶ croak sprintf "Unknown command: %s\n", $command
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get__abbreviations 1 3 4
859 if !$self->get__abbreviations;
860  
861 3 my $abbreviation = $command;
862  
863 3 my @matches = grep {/^$abbreviation/xsm} keys %{$commands};
864  
865 3 ▶ croak sprintf "Unknown command: %s\n", $command
Branch: 1 branch
BranchTrueFalseTotal
unless @matches 0 3 3
866 if !@matches;
867  
868 3 ▶ if ( @matches == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@matches == 1) 2 1 3
869 2 $command = $matches[0]; # Unique match - accept
870 2 $self->set__command($command);
871 2 return $command;
872 }
873  
874 1 croak sprintf "Ambiguous command '$abbreviation'; could match: %s\n", join q{,}, @matches;
875 }
876  
877 ########################################################################
878 0 ▶sub _cmd_generate_completion {
Subroutine _cmd_generate_completion: not called CC=4 SCAR=27.5
879 ########################################################################
880 0 my ( $class, $commands, $option_specs ) = @_;
881  
882 8 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
883 0 my $stash = \%{ $class . '::' };
884  
885 0 my $cmd_list = join q{ }, sort grep { !/^-/xsm } keys %{$commands};
886  
887 0 ▶ my $program = $ENV{MODULINO_WRAPPER} // do {
Condition0%0/3
$ENV{"MODULINO_WRAPPER"} // do { (my $name = $class) =~ s/::/-/gmsx; lc $name }
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"MODULINO_WRAPPER"} // do { (my $name = $class) =~ s/::/-/gmsx; lc $name }
$ENV{"MODULINO_WRAPPER"} do { (my $name = $class) =~ s/::/-/gmsx; lc $name }
Truth table0%0/3
A // B
A= $ENV{"MODULINO_WRAPPER"}B= do { (my $name = $class) =~ s/::/-/gmsx; lc $name }
ABresult
1X1
011
000
888 0 ( my $name = $class ) =~ s/::/-/gxsm;
889 0 lc $name;
890 };
891  
892 0 my @flags;
893 my @value_opts;
894  
895 0 for my $spec ( @{$option_specs} ) {
896 0 my ($name) = $spec =~ /\A([\w-]+)/xsm;
897 0 $name =~ s/_/-/gxsm;
898  
899 0 ▶ if ( $spec =~ /[=:]/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ /[=:]/msx) { } 0 0 0
900 0 push @value_opts, "--$name";
901 }
902 else {
903 0 push @flags, "--$name";
904 }
905 }
906  
907 0 my $flags = join q{ }, sort @flags;
908 0 my $value_opts = join q{ }, sort @value_opts;
909  
910 0 printf {*STDOUT} <<'END_COMPLETION', $program, $cmd_list, $value_opts, $flags, $program, $program;
911 _%s() {
912 local cur prev words cword
913 _init_completion || return
914  
915 local commands="%s"
916 local value_opts="%s"
917 local flags="%s"
918  
919 if [[ $cword -eq 1 ]]; then
920 if [[ "$cur" == --* ]]; then
921 COMPREPLY=( $(compgen -W "$flags $value_opts" -- "$cur") )
922 else
923 COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
924 fi
925 return
926 fi
927  
928 case $prev in
929 $value_opts)
930 COMPREPLY=( $(compgen -f -- "$cur") )
931 return ;;
932 esac
933  
934 COMPREPLY=( $(compgen -W "$flags $value_opts" -- "$cur") )
935 }
936  
937 complete -F _%s %s
938 END_COMPLETION
939  
940 0 return $SUCCESS;
941 }
942  
943 ########################################################################
944 11 ▶sub run {
Subroutine run: called CC=8 SCAR=27.7
Pod documented
945 ########################################################################
946 11 my ($self) = @_;
947  
948 11 my $command = $self->command;
949  
950 ######################################################################
951 # a blank command means that we did not have a default && AUTO_HELP
952 # is off scripter has deliberately decided to allow running of
953 # init() phase w/o a run phase
954 ######################################################################
955  
956 11 ▶ return $SUCCESS
Branch: 1 branch
BranchTrueFalseTotal
unless $command 0 11 11
957 if !$command;
958  
959 11 my $commands = $self->commands;
960  
961 11 my $program = $self->program;
962  
963 11 my $handler = $commands->{$command};
964  
965 11 ▶ if ( $handler && !ref $handler ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler and not ref $handler) 0 11 11
Condition33%1/3
$handler and not ref $handler
!ll&&!rl&&r
0110
MC/DC0%0/2
$handler and not ref $handler
$handler not ref $handler
Truth table33%1/3
A and not(B)
A= $handlerB= not ref $handler
ABresult
0X0
100
111
966 0 $handler = $commands->{$handler}; # default?
967 }
968  
969 11 ▶ die "ERROR: no such command '$command' has been registered.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 0 11 11
970 if !$handler;
971  
972 11 ▶ if ( ref $handler ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handler ne "ARRAY") 11 0 11
973 11 my $result = $handler->($self);
974 11 return $result;
975 }
976  
977 0 my ( $sub, $log_level ) = @{$handler};
978  
979 0 ▶ croak "ERROR: invalid specification for $command\n"
Branch: 1 branch
BranchTrueFalseTotal
if not ref $sub or builtin::reftype($sub) ne "CODE" 0 0 0
Condition0%0/3
not ref $sub or builtin::reftype($sub) ne "CODE"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $sub or builtin::reftype($sub) ne "CODE"
not ref $sub builtin::reftype($sub) ne "CODE"
Truth table0%0/3
not(A) or B
A= not ref $subB= builtin::reftype($sub) ne "CODE"
ABresult
1X1
011
000
980 if !ref $sub || reftype($sub) ne 'CODE';
981  
982 0 return $sub->($self);
983 }
984  
985 8 1;
986  
987 ## no critic (RequirePodSections)
988  
989 __END__
↑ Summary Simple/Scaffold.pm »