blib/lib/Perinci/CmdLine/Lite.pm

filter: Statementstmt 75.9% 275 / 362 Branchbran 58.2% 99 / 170 Conditioncond 45.1% 60 / 133 MC/DCmcdc 22.9% 17 / 74 Subroutinesub 86.6% 26 / 30 Podpod 41.6% 5 / 12 totaltotal 61.7% 482 / 781 CC 146 SCAR 37.3
CC
146
Cov
65%
__ANON__
130.1
hook_after_get_meta
46.0
hook_format_result
36.0
CRAP 41.7
« blib/lib/Perinci/CmdLine/Base.pm ↑ Summary blib/lib/Perinci/CmdLine/Plugin/Run/Completion.pm »
1 package Perinci::CmdLine::Lite;
2  
3 # put pragmas + Log::ger here
4 86 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 # use strict; # already enabled by Moo
6 # use warnings; # already enabled by Moo
7 86 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # put other modules alphabetically here
10 86 ▶use IO::Interactive qw(is_interactive);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 86 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 86 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #use Moo;
15 86 extends 'Perinci::CmdLine::Base';
16  
17 # put global variables alphabetically here
18 86 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
19 86 our $DATE = '2023-11-23'; # DATE
20 86 our $DIST = 'Perinci-CmdLine-Lite'; # DIST
21 86 our $VERSION = '1.929'; # VERSION
22  
23 86 has default_prompt_template => (
24 is=>'rw',
25 default => 'Enter %s: ',
26 );
27 86 has validate_args => (
28 is=>'rw',
29 default => 1,
30 );
31  
32 86 my $formats = [qw/text text-simple text-pretty json json-pretty csv termtable html html+datatables perl vd/];
33  
34 85 ▶sub BUILD {
Subroutine BUILD: called CC=14 SCAR=27.6
Pod undocumented
35 85 my ($self, $args) = @_;
36  
37 85 ▶ if (!$self->{riap_client}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"riap_client"}) 85 0 85
38 85 require Perinci::Access::Lite;
39 my %rcargs = (
40 riap_version => $self->{riap_version} // 1.1,
41 85 ▶ %{ $self->{riap_client_args} // {} },
Condition50%2/4
$self->{"riap_version"} // "1.1"
l!l
850
$self->{"riap_client_args"} // {}
l!l
085
MC/DC0%0/1
$self->{"riap_version"} // "1.1"
$self->{"riap_version"}
MC/DC0%0/1
$self->{"riap_client_args"} // {}
$self->{"riap_client_args"}
Truth table50%1/2
A
A= $self->{"riap_version"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"riap_client_args"}
Aresult
11
00
42 );
43 85 $self->{riap_client} = Perinci::Access::Lite->new(%rcargs);
44 }
45  
46 85 ▶ if (!$self->{actions}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"actions"}) 85 0 85
47 $self->{actions} = {
48 85 call => {},
49 version => {},
50 subcommands => {},
51 help => {},
52 };
53 }
54  
55 652 ▶ my $_copy = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 86 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 652 my $co_name = shift;
58 652 my $href = $Perinci::CmdLine::Base::copts{$co_name};
59 652 %$href;
60 85 };
61  
62 85 ▶ if (!$self->{common_opts}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"common_opts"}) 85 0 85
63 85 my $copts = {};
64  
65 85 $copts->{version} = { $_copy->('version'), };
66 85 $copts->{help} = { $_copy->('help'), };
67  
68 85 ▶ unless ($self->skip_format) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->skip_format) 85 0 85
69 $copts->{format} = {
70 85 $_copy->('format'),
71 schema => ['str*' => in => $formats],
72 };
73 85 $copts->{json} = { $_copy->('json'), };
74 85 $copts->{naked_res} = { $_copy->('naked_res'), };
75 85 $copts->{page_result} = { $_copy->('page_result'), };
76 85 $copts->{view_result} = { $_copy->('view_result'), };
77 }
78 85 ▶ if ($self->subcommands) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->subcommands) 11 74 85
79 11 $copts->{subcommands} = { $_copy->('subcommands'), };
80 }
81 85 ▶ if ($self->default_subcommand) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->default_subcommand) 3 82 85
82 3 $copts->{cmd} = { $_copy->('cmd') };
83 }
84 85 ▶ if ($self->read_config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->read_config) 13 72 85
85 13 $copts->{config_path} = { $_copy->('config_path') };
86 13 $copts->{no_config} = { $_copy->('no_config') };
87 13 $copts->{config_profile} = { $_copy->('config_profile') };
88 }
89 85 ▶ if ($self->read_env) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->read_env) 4 81 85
90 4 $copts->{no_env} = { $_copy->('no_env') };
91 }
92 85 ▶ if ($self->log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log) 0 85 85
93 0 $copts->{log_level} = { $_copy->('log_level'), };
94 0 $copts->{trace} = { $_copy->('trace'), };
95 0 $copts->{debug} = { $_copy->('debug'), };
96 0 $copts->{verbose} = { $_copy->('verbose'), };
97 0 $copts->{quiet} = { $_copy->('quiet'), };
98 }
99 85 $self->{common_opts} = $copts;
100 }
101  
102 85 ▶ $self->{formats} //= $formats;
Condition33%1/3
$self->{"formats"} //= $formats
l!l&&r!l&&!r
0850
MC/DC0%0/2
$self->{"formats"} //= $formats
$self->{"formats"} $formats
Truth table33%1/3
A //= B
A= $self->{"formats"}B= $formats
ABresult
1X1
011
000
103  
104 85 ▶ $self->{per_arg_json} //= 1;
Condition50%1/2
$self->{"per_arg_json"} //= 1
l!l
085
MC/DC0%0/1
$self->{"per_arg_json"} //= 1
$self->{"per_arg_json"}
Truth table50%1/2
A
A= $self->{"per_arg_json"}
Aresult
11
00
105 }
106  
107 86 my $setup_progress;
108 0 ▶sub _setup_progress_output {
Subroutine _setup_progress_output: not called CC=3 SCAR=24.8
109 0 my $self = shift;
110  
111 0 ▶ return unless $ENV{PROGRESS} // is_interactive(*STDOUT);
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"PROGRESS"} // is_interactive(*STDOUT) 0 0 0
Condition0%0/3
$ENV{"PROGRESS"} // is_interactive(*STDOUT)
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"PROGRESS"} // is_interactive(*STDOUT)
$ENV{"PROGRESS"} is_interactive(*STDOUT)
Truth table0%0/3
A // B
A= $ENV{"PROGRESS"}B= is_interactive(*STDOUT)
ABresult
1X1
011
000
112  
113 0 require Progress::Any::Output;
114 0 Progress::Any::Output->set("TermProgressBarColor");
115 0 $setup_progress = 1;
116 }
117  
118 0 ▶sub _unsetup_progress_output {
Subroutine _unsetup_progress_output: not called CC=3 SCAR=19.2
119 0 my $self = shift;
120  
121 0 ▶ return unless $setup_progress;
Branch: 1 branch
BranchTrueFalseTotal
unless $setup_progress 0 0 0
122 86 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
123 0 my $out = $Progress::Any::outputs{''}[0];
124 0 ▶ $out->cleanup if $out->can("cleanup");
Branch: 1 branch
BranchTrueFalseTotal
if $out->can("cleanup") 0 0 0
125 0 $setup_progress = 0;
126 }
127  
128 77 ▶sub hook_after_parse_argv {
Subroutine hook_after_parse_argv: called CC=7 SCAR=19.7
Pod documented
129 77 my ($self, $r) = @_;
130  
131 # since unlike Perinci::CmdLine, we don't wrap the function (where the
132 # wrapper assigns default values for arguments), we must do it here
133 # ourselves.
134 77 ▶ my $ass = $r->{meta}{args} // {};
Condition100%2/2
$r->{"meta"}{"args"} // {}
l!l
698
MC/DC100%1/1
$r->{"meta"}{"args"} // {}
$r->{"meta"}{"args"}
Truth table100%2/2
A
A= $r->{"meta"}{"args"}
Aresult
11
00
135 77 my $args = $r->{args};
136 77 for (keys %$ass) {
137 122 ▶ next if exists $args->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{$_} 49 73 122
138 73 my $as = $ass->{$_};
139 73 ▶ if (exists $as->{default}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $as->{'default'}) { } 0 73 73
elsif ($as->{'schema'} and exists $as->{'schema'}[1]{'default'}) { } 5 68 73
140 0 $args->{$_} = $as->{default};
141 ▶ } elsif ($as->{schema} && exists $as->{schema}[1]{default}) {
Condition66%2/3
$as->{"schema"} and exists $as->{"schema"}[1]{"default"}
!ll&&!rl&&r
0685
MC/DC50%1/2
$as->{"schema"} and exists $as->{"schema"}[1]{"default"}
$as->{"schema"} exists $as->{"schema"}[1]{"default"}
Truth table66%2/3
A and B
A= $as->{"schema"}B= exists $as->{"schema"}[1]{"default"}
ABresult
0X0
100
111
142 5 $args->{$_} = $as->{schema}[1]{default};
143 }
144 }
145 }
146  
147 85 ▶sub hook_before_parse_argv {
Subroutine hook_before_parse_argv: called CC=12 SCAR=25.3
Pod undocumented
148 85 my ($self, $r) = @_;
149  
150 # in this hook, we want to add several shortcut options (e.g. -C for
151 # --no-config, etc) if the function is not using those shortcut options. but
152 # to do this, we need to get meta first and this is only possible when there
153 # is no subcommand
154 85 ▶ return if $r->{subcommands};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"subcommands"} 0 85 85
155 85 $self->get_meta($r, $self->{url});
156  
157 85 my $copts = $self->common_opts;
158  
159 # XXX cache
160 85 require Perinci::Sub::GetArgs::Argv;
161 my $ggls_res = Perinci::Sub::GetArgs::Argv::gen_getopt_long_spec_from_meta(
162 meta => $r->{meta},
163 meta_is_normalized => 1,
164 args => $r->{args},
165 common_opts => $copts,
166 per_arg_json => $self->{per_arg_json},
167 per_arg_yaml => $self->{per_arg_yaml},
168 85 );
169  
170 85 my $meta_uses_opt_P = 0;
171 85 my $meta_uses_opt_c = 0;
172 85 my $meta_uses_opt_C = 0;
173 {
174 85 ▶ last unless $ggls_res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $ggls_res->[0] == 200 0 85 85
175 85 my $opts = $ggls_res->[3]{'func.opts'};
176 0 ▶ if (grep { $_ eq '-P' } @$opts) { $meta_uses_opt_P = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-P";} @$opts) 0 85 85
177 85 ▶ if (grep { $_ eq '-c' } @$opts) { $meta_uses_opt_c = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-c";} @$opts) 10 75 85
178 0 ▶ if (grep { $_ eq '-C' } @$opts) { $meta_uses_opt_C = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-C";} @$opts) 0 85 85
179 }
180  
181 #say "D:meta_uses_opt_P=<$meta_uses_opt_P>";
182 #say "D:meta_uses_opt_c=<$meta_uses_opt_c>";
183 #say "D:meta_uses_opt_C=<$meta_uses_opt_C>";
184  
185 # add -P shortcut for --config-profile if no conflict
186 85 ▶ if ($copts->{config_profile} && !$meta_uses_opt_P) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copts->{"config_profile"} and not $meta_uses_opt_P) 13 72 85
Condition66%2/3
$copts->{"config_profile"} and not $meta_uses_opt_P
!ll&&!rl&&r
72013
MC/DC50%1/2
$copts->{"config_profile"} and not $meta_uses_opt_P
$copts->{"config_profile"} not $meta_uses_opt_P
Truth table66%2/3
A and not(B)
A= $copts->{"config_profile"}B= not $meta_uses_opt_P
ABresult
0X0
100
111
187 13 $copts->{config_profile}{getopt} = 'config-profile|P=s';
188 }
189  
190 # add -c shortcut for --config-path if no conflict
191 85 ▶ if ($copts->{config_path} && !$meta_uses_opt_c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copts->{"config_path"} and not $meta_uses_opt_c) 3 82 85
Condition100%3/3
$copts->{"config_path"} and not $meta_uses_opt_c
!ll&&!rl&&r
72103
MC/DC100%2/2
$copts->{"config_path"} and not $meta_uses_opt_c
$copts->{"config_path"} not $meta_uses_opt_c
Truth table100%3/3
A and not(B)
A= $copts->{"config_path"}B= not $meta_uses_opt_c
ABresult
0X0
100
111
192 3 $copts->{config_path}{getopt} = 'config-path|c=s';
193 }
194  
195 # add -P shortcut for --no-config if no conflict
196 85 ▶ if ($copts->{no_config} && !$meta_uses_opt_C) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copts->{"no_config"} and not $meta_uses_opt_C) 13 72 85
Condition66%2/3
$copts->{"no_config"} and not $meta_uses_opt_C
!ll&&!rl&&r
72013
MC/DC50%1/2
$copts->{"no_config"} and not $meta_uses_opt_C
$copts->{"no_config"} not $meta_uses_opt_C
Truth table66%2/3
A and not(B)
A= $copts->{"no_config"}B= not $meta_uses_opt_C
ABresult
0X0
100
111
197 13 $copts->{no_config}{getopt} = 'no-config|C';
198 }
199 }
200  
201 67 ▶sub hook_before_action {
Subroutine hook_before_action: called CC=7 SCAR=23.3
Pod documented
202  
203 67 my ($self, $r) = @_;
204  
205 VALIDATE_ARGS: {
206 67 ▶ last unless $self->validate_args;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->validate_args 0 67 67
207  
208 # unless we're feeding the arguments to function, don't bother
209 # validating arguments
210 67 ▶ last unless $r->{action} eq 'call';
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"action"} eq "call" 6 61 67
211  
212 61 my $meta = $r->{meta};
213  
214 # function says it's already already wrapped and the wrapper adds
215 # validator.
216 last if $meta->{'x.perinci.sub.wrapper.logs'} &&
217 0 (grep { $_->{validate_args} }
218 0 ▶ @{ $meta->{'x.perinci.sub.wrapper.logs'} });
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"x.perinci.sub.wrapper.logs"} and grep {$_->{"validate_args"};} @{$$meta{"x.perinci.sub.wrapper.logs"};} 0 61 61
Condition33%1/3
$meta->{"x.perinci.sub.wrapper.logs"} and grep {$_->{"validate_args"};} @{$$meta{"x.perinci.sub.wrapper.logs"};}
!ll&&!rl&&r
6100
MC/DC0%0/2
$meta->{"x.perinci.sub.wrapper.logs"} and grep {$_->{"validate_args"};} @{$$meta{"x.perinci.sub.wrapper.logs"};}
$meta->{"x.perinci.sub.wrapper.logs"} grep {$_->{"validate_args"};} @{$$meta{"x.perinci.sub.wrapper.logs"};}
Truth table33%1/3
A and B
A= $meta->{"x.perinci.sub.wrapper.logs"}B= grep {$_->{"validate_args"};} @{$$meta{"x.perinci.sub.wrapper.logs"};}
ABresult
0X0
100
111
219  
220 # function can validate its args, so we don't have to do validation for
221 # it
222 61 ▶ last if $meta->{features} && $meta->{features}{validate_vars};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"features"} and $meta->{"features"}{"validate_vars"} 0 61 61
Condition66%2/3
$meta->{"features"} and $meta->{"features"}{"validate_vars"}
!ll&&!rl&&r
47140
MC/DC0%0/2
$meta->{"features"} and $meta->{"features"}{"validate_vars"}
$meta->{"features"} $meta->{"features"}{"validate_vars"}
Truth table66%2/3
A and B
A= $meta->{"features"}B= $meta->{"features"}{"validate_vars"}
ABresult
0X0
100
111
223  
224 $self->_plugin_run_event(
225 name => 'validate_args',
226 r => $r,
227 61 ▶ on_success => sub {
Subroutine __ANON__: called CC=36 SCAR=48.7
228 86 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
229  
230 # to be cheap, we simply use "$ref" as key as cache key. to be
231 # proper, it should be hash of serialized content.
232 61 my %validators_by_arg; # key = argname
233  
234 my %arg_has_default;
235  
236 USE_VALIDATORS_FROM_SCHEMA_V: {
237 61 my $url = $r->{subcommand_data}{url};
238 61 ▶ $url =~ m!\A/(.+)/(\w+)\z! or last;
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m[\A/(.+)/(\w+)\z] or last 61 0 61
239 61 my $func = $2;
240 61 (my $mod = $1) =~ s!/!::!g;
241 61 my $schemav_mod = "Sah::SchemaV::$mod";
242 61 (my $schemav_mod_pm = "$schemav_mod.pm") =~ s!::!/!g;
243 61 eval { require $schemav_mod_pm };
244 61 ▶ last if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 61 0 61
245  
246 #say "D:we have pre-compiled validator codes";
247  
248 0 ▶ for my $arg (sort keys %{ $meta->{args} // {} }) {
Condition0%0/2
$meta->{"args"} // {}
l!l
00
MC/DC0%0/1
$meta->{"args"} // {}
$meta->{"args"}
Truth table0%0/2
A
A= $meta->{"args"}
Aresult
11
00
249 ### para1, sync with all others
250 0 my $argspec = $meta->{args}{$arg};
251 0 my $argschema = $argspec->{schema};
252 0 ▶ next unless $argschema;
Branch: 1 branch
BranchTrueFalseTotal
unless $argschema 0 0 0
253 my $schema_has_default = defined $argschema->[1]{default} ||
254 0 ▶ $argschema->[1]{'x.perl.default_value_rules'} && @{ $argschema->[1]{'x.perl.default_value_rules'} };
Condition0%0/6
defined $argschema->[1]{'default'} || $argschema->[1]{'x.perl.default_value_rules'} && @{$argschema->[1]{'x.perl.default_value_rules'};}
l!l&&r!l&&!r
000
$argschema->[1]{"x.perl.default_value_rules"} and @{$argschema->[1]{"x.perl.default_value_rules"};}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $argschema->[1]{'default'} || $argschema->[1]{'x.perl.default_value_rules'} && @{$argschema->[1]{'x.perl.default_value_rules'};}
defined $argschema->[1]{'default'} $argschema->[1]{"x.perl.default_value_rules"} @{$argschema->[1]{"x.perl.default_value_rules"};}
Truth table0%0/4
A || B and C
A= defined $argschema->[1]{'default'}B= $argschema->[1]{"x.perl.default_value_rules"}C= @{$argschema->[1]{"x.perl.default_value_rules"};}
ABCresult
1XX1
0111
00X0
0100
255 0 ▶ next unless exists($r->{args}{$arg}) || $schema_has_default;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $r->{"args"}{$arg} or $schema_has_default 0 0 0
Condition0%0/3
exists $r->{"args"}{$arg} or $schema_has_default
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $r->{"args"}{$arg} or $schema_has_default
exists $r->{"args"}{$arg} $schema_has_default
Truth table0%0/3
A or B
A= exists $r->{"args"}{$arg}B= $schema_has_default
ABresult
1X1
011
000
256  
257 # we don't support validation of input stream because
258 # this must be done after each 'get item' (but periswrap
259 # does)
260 0 ▶ next if $meta->{args}{$arg}{stream};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"args"}{$arg}{"stream"} 0 0 0
261  
262 0 ▶ my $v = ${"$schemav_mod\::Args_Validators"}{$func}{$arg}
Branch: 1 branch
BranchTrueFalseTotal
my $v = do { "${schemav_mod}::Args_Validators" }->{$func}{$arg} or next 0 0 0
263 or next;
264 #say "D:using precompiled validator for arg $arg";
265 0 $validators_by_arg{$arg} = $v;
266 }
267 }
268  
269 GEN_VALIDATORS: {
270 61 my %validators_by_schema; # key = "$schema"
271 61 require Data::Sah;
272 61 require Data::Sah::Resolve;
273 61 ▶ for my $arg (sort keys %{ $meta->{args} // {} }) {
Condition100%2/2
$meta->{"args"} // {}
l!l
592
MC/DC100%1/1
$meta->{"args"} // {}
$meta->{"args"}
Truth table100%2/2
A
A= $meta->{"args"}
Aresult
11
00
274 109 ▶ $arg_has_default{$arg} = 1 if defined $meta->{args}{$arg}{default};
Branch: 1 branch
BranchTrueFalseTotal
if defined $meta->{"args"}{$arg}{"default"} 0 109 109
275  
276 # we don't support validation of input stream because
277 # this must be done after each 'get item' (but periswrap
278 # does)
279 109 ▶ next if $meta->{args}{$arg}{stream};
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"args"}{$arg}{"stream"} 4 105 109
280  
281 ### para1, sync with all others
282 105 my $argspec = $meta->{args}{$arg};
283 105 my $argschema = $argspec->{schema};
284 105 ▶ next unless $argschema;
Branch: 1 branch
BranchTrueFalseTotal
unless $argschema 0 105 105
285 105 my $argschemar = Data::Sah::Resolve::resolve_schema($argschema);
286 105 my $schema_has_default;
287 105 for my $clset (@{ $argschemar->{"clsets_after_type.alt.merge.merged"} }) {
288 5 do { $schema_has_default = 1; last } if defined $clset->{default} ||
289 0 ▶ $clset->{'x.perl.default_value_rules'} && @{ $clset->{'x.perl.default_value_rules'} };
Branch: 1 branch
BranchTrueFalseTotal
if (defined $clset->{"default"} or $clset->{"x.perl.default_value_rules"} and @{$clset->{"x.perl.default_value_rules"};}) 5 40 45
Condition50%3/6
defined $clset->{"default"} or $clset->{"x.perl.default_value_rules"} and @{$clset->{"x.perl.default_value_rules"};}
l!l&&r!l&&!r
5040
$clset->{"x.perl.default_value_rules"} and @{$clset->{"x.perl.default_value_rules"};}
!ll&&!rl&&r
4000
MC/DC33%1/3
defined $clset->{"default"} or $clset->{"x.perl.default_value_rules"} and @{$clset->{"x.perl.default_value_rules"};}
defined $clset->{"default"} $clset->{"x.perl.default_value_rules"} @{$clset->{"x.perl.default_value_rules"};}
Truth table50%2/4
A or B and C
A= defined $clset->{"default"}B= $clset->{"x.perl.default_value_rules"}C= @{$clset->{"x.perl.default_value_rules"};}
ABCresult
1XX1
0111
00X0
0100
290 }
291 105 ▶ $arg_has_default{$arg} = 1 if $schema_has_default;
Branch: 1 branch
BranchTrueFalseTotal
if $schema_has_default 5 100 105
292 105 ▶ next unless exists($r->{args}{$arg}) || $schema_has_default;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $r->{"args"}{$arg} or $schema_has_default 37 68 105
Condition66%2/3
exists $r->{"args"}{$arg} or $schema_has_default
l!l&&r!l&&!r
68037
MC/DC50%1/2
exists $r->{"args"}{$arg} or $schema_has_default
exists $r->{"args"}{$arg} $schema_has_default
Truth table66%2/3
A or B
A= exists $r->{"args"}{$arg}B= $schema_has_default
ABresult
1X1
011
000
293  
294 68 ▶ unless ($validators_by_schema{"$argschema"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($validators_by_schema{"$argschema"}) 68 0 68
295 68 my $v = Data::Sah::gen_validator($argschema, {
296 return_type => 'str+val',
297 schema_is_normalized => 1,
298 });
299 68 $validators_by_schema{"$argschema"} = $v;
300 68 $validators_by_arg{$arg} = $v;
301 }
302 }
303 }
304  
305 DO_VALIDATE: {
306 61 ▶ for my $arg (sort keys %{ $meta->{args} // {} }) {
Condition100%2/2
$meta->{"args"} // {}
l!l
592
MC/DC100%1/1
$meta->{"args"} // {}
$meta->{"args"}
Truth table100%2/2
A
A= $meta->{"args"}
Aresult
11
00
307 109 ▶ my $v = $validators_by_arg{$arg} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $v = $validators_by_arg{$arg} or next 68 41 109
308  
309 68 my $argspec = $meta->{args}{$arg};
310 68 my $argschema = $argspec->{schema};
311  
312 # we want to get default value from schema, but do not
313 # want to make unspecified args spring into existence
314 # with 'undef' values. so we record the existence first
315 # here.
316 my $arg_exists = $r->{args}{"-set_$arg"} =
317 68 ▶ exists($r->{args}{$arg}) ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
exists $r->{'args'}{$arg} ? : 68 0 68
318  
319 68 ▶ if ($arg_has_default{$arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_has_default{$arg}) 5 63 68
320 5 my $res = $v->(undef);
321 5 $r->{args}{"-default_$arg"} = $res->[1];
322 }
323  
324 68 ▶ if ($arg_exists || $arg_has_default{$arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_exists or $arg_has_default{$arg}) 68 0 68
Condition33%1/3
$arg_exists or $arg_has_default{$arg}
l!l&&r!l&&!r
6800
MC/DC0%0/2
$arg_exists or $arg_has_default{$arg}
$arg_exists $arg_has_default{$arg}
Truth table33%1/3
A or B
A= $arg_existsB= $arg_has_default{$arg}
ABresult
1X1
011
000
325 68 my $res = $v->($r->{args}{$arg});
326 68 ▶ if ($res->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[0]) 0 68 68
327 0 die [400, "Argument '$arg' fails validation: $res->[0]"];
328 }
329 68 my $val0 = $r->{args}{$arg};
330 68 my $coerced_val = $res->[1];
331 68 $r->{args}{$arg} = $coerced_val;
332 68 $r->{args}{"-orig_$arg"} = $val0;
333 }
334 }
335 } # DO_VALIDATE
336  
337 DO_VALIDATE_ARGS_RELS: {
338 61 ▶ last unless $meta->{args_rels};
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->{"args_rels"} 61 0 61
339  
340 # we haven't precompiled validator for args_rels yet
341 0 require Data::Sah;
342  
343 0 my $schema = [hash => $meta->{args_rels}];
344 0 my $sah = Data::Sah->new;
345 0 my $hc = $sah->get_compiler("human");
346 0 my $cd = $hc->init_cd;
347 0 ▶ $cd->{args}{lang} //= $cd->{default_lang};
Condition0%0/3
$cd->{"args"}{"lang"} //= $cd->{"default_lang"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$cd->{"args"}{"lang"} //= $cd->{"default_lang"}
$cd->{"args"}{"lang"} $cd->{"default_lang"}
Truth table0%0/3
A //= B
A= $cd->{"args"}{"lang"}B= $cd->{"default_lang"}
ABresult
1X1
011
000
348 0 my $v = Data::Sah::gen_validator($schema, {
349 return_type => 'str',
350 human_hash_values => {
351 field => $hc->_xlt($cd, "argument"),
352 fields => $hc->_xlt($cd, "arguments"),
353 },
354 });
355 0 my $res = $v->($r->{args});
356 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
357 0 die [400, $res];
358 }
359 } # DO_VALIDATE_ARGS_RELS
360  
361 },
362 61 );
363 } # VALIDATE_ARGS
364 }
365  
366 75 ▶sub hook_format_result {
Subroutine hook_format_result: called CC=14 SCAR=35.8
Pod documented
367 75 require Perinci::Result::Format::Lite;
368 75 my ($self, $r) = @_;
369  
370 75 ▶ my $fmt = $r->{format} // 'text';
Condition100%2/2
$r->{"format"} // "text"
l!l
1461
MC/DC100%1/1
$r->{"format"} // "text"
$r->{"format"}
Truth table100%2/2
A
A= $r->{"format"}
Aresult
11
00
371  
372 75 ▶ if ($fmt eq 'html+datatables') {
Branch: 3 branches
BranchTrueFalseTotal
if ($fmt eq 'html+datatables') { } 0 75 75
elsif ($fmt eq 'termtable') { } 0 75 75
elsif ($fmt eq 'vd') { } 0 75 75
373 0 $fmt = 'text-pretty';
374 0 ▶ $ENV{VIEW_RESULT} //= 1;
Condition0%0/2
$ENV{"VIEW_RESULT"} //= 1
l!l
00
MC/DC0%0/1
$ENV{"VIEW_RESULT"} //= 1
$ENV{"VIEW_RESULT"}
Truth table0%0/2
A
A= $ENV{"VIEW_RESULT"}
Aresult
11
00
375 86 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
376 0 $Perinci::CmdLine::Base::tempfile_opt_suffix = '.html';
377 0 ▶ $ENV{FORMAT_PRETTY_TABLE_BACKEND} //= 'Text::Table::HTML::DataTables';
Condition0%0/2
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"} //= "Text::Table::HTML::DataTables"
l!l
00
MC/DC0%0/1
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"} //= "Text::Table::HTML::DataTables"
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"}
Truth table0%0/2
A
A= $ENV{"FORMAT_PRETTY_TABLE_BACKEND"}
Aresult
11
00
378 } elsif ($fmt eq 'termtable') {
379 0 $fmt = 'text-pretty';
380 86 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
381 0 ▶ $ENV{FORMAT_PRETTY_TABLE_BACKEND} //= 'Term::TablePrint';
Condition0%0/2
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"} //= "Term::TablePrint"
l!l
00
MC/DC0%0/1
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"} //= "Term::TablePrint"
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"}
Truth table0%0/2
A
A= $ENV{"FORMAT_PRETTY_TABLE_BACKEND"}
Aresult
11
00
382 } elsif ($fmt eq 'vd') { # view in Visidata
383 0 $fmt = 'text-pretty';
384 0 ▶ $ENV{VIEW_RESULT} //= 1;
Condition0%0/2
$ENV{"VIEW_RESULT"} //= 1
l!l
00
MC/DC0%0/1
$ENV{"VIEW_RESULT"} //= 1
$ENV{"VIEW_RESULT"}
Truth table0%0/2
A
A= $ENV{"VIEW_RESULT"}
Aresult
11
00
385 86 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
386 0 $Perinci::CmdLine::Base::tempfile_opt_suffix = '.csv';
387 0 ▶ $ENV{FORMAT_PRETTY_TABLE_BACKEND} //= 'Text::Table::CSV';
Condition0%0/2
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"} //= "Text::Table::CSV"
l!l
00
MC/DC0%0/1
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"} //= "Text::Table::CSV"
$ENV{"FORMAT_PRETTY_TABLE_BACKEND"}
Truth table0%0/2
A
A= $ENV{"FORMAT_PRETTY_TABLE_BACKEND"}
Aresult
11
00
388 0 ▶ $r->{viewer} //= 'vd';
Condition0%0/2
$r->{"viewer"} //= "vd"
l!l
00
MC/DC0%0/1
$r->{"viewer"} //= "vd"
$r->{"viewer"}
Truth table0%0/2
A
A= $r->{"viewer"}
Aresult
11
00
389 }
390  
391 my $fres = Perinci::Result::Format::Lite::format(
392 75 $r->{res}, $fmt, $r->{naked_res}, $self->{use_cleanser});
393  
394 # ux: prefix error message with program name
395 75 ▶ if ($fmt =~ /text/ && $r->{res}[0] =~ /\A[45]/ && defined($r->{res}[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /text/ and $r->{"res"}[0] =~ /\A[45]/ and defined $r->{"res"}[1]) 15 60 75
Condition83%5/6
$fmt =~ /text/ and $r->{"res"}[0] =~ /\A[45]/ and defined $r->{"res"}[1]
!ll&&!rl&&r
60015
$fmt =~ /text/ and $r->{"res"}[0] =~ /\A[45]/
!ll&&!rl&&r
134715
MC/DC66%2/3
$fmt =~ /text/ and $r->{"res"}[0] =~ /\A[45]/ and defined $r->{"res"}[1]
$fmt =~ /text/ $r->{"res"}[0] =~ /\A[45]/ defined $r->{"res"}[1]
Truth table75%3/4
A and B and C
A= $fmt =~ /text/B= $r->{"res"}[0] =~ /\A[45]/C= defined $r->{"res"}[1]
ABCresult
0XX0
10X0
1100
1111
396 15 $fres = $self->program_name . ": $fres";
397 }
398  
399 75 $fres;
400 }
401  
402 0 ▶sub hook_format_row {
Subroutine hook_format_row: not called CC=3 SCAR=24.8
Pod undocumented
403 0 my ($self, $r, $row) = @_;
404  
405 0 ▶ if (ref($row) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $row eq 'ARRAY') { } 0 0 0
406 0 return join("\t", @$row) . "\n";
407 } else {
408 0 ▶ return ($row // "") . "\n";
Condition0%0/2
$row // ""
l!l
00
MC/DC0%0/1
$row // ""
$row
Truth table0%0/2
A
A= $row
Aresult
11
00
409 }
410 }
411  
412 85 ▶sub hook_display_result {
Subroutine hook_display_result: called CC=9 SCAR=24.3
Pod documented
413 85 my ($self, $r) = @_;
414  
415 85 my $res = $r->{res};
416 85 ▶ my $resmeta = $res->[3] // {};
Condition50%1/2
$res->[3] // {}
l!l
850
MC/DC0%0/1
$res->[3] // {}
$res->[3]
Truth table50%1/2
A
A= $res->[3]
Aresult
11
00
417  
418 85 my $handle = $r->{output_handle};
419  
420 85 my $layer;
421 SELECT_LAYER:
422 {
423 85 ▶ if ($resmeta->{'x.hint.result_binary'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resmeta->{"x.hint.result_binary"}) 0 85 85
424 # XXX only when format is text?
425 0 $layer = ":bytes"; last;
426 }
427  
428 85 ▶ if ($ENV{UTF8} ||
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"UTF8"} or defined($r->{"subcommand_data"} && $r->{"subcommand_data"}{"use_utf8"}) or $self->use_utf8) 3 82 85
Condition55%5/9
$ENV{"UTF8"} or defined($r->{"subcommand_data"} && $r->{"subcommand_data"}{"use_utf8"}) or $self->use_utf8
l!l&&r!l&&!r
0382
$ENV{"UTF8"} or defined($r->{"subcommand_data"} && $r->{"subcommand_data"}{"use_utf8"})
l!l&&r!l&&!r
0085
$r->{'subcommand_data'} && $r->{'subcommand_data'}{'use_utf8'}
!ll&&!rl&&r
2830
MC/DC25%1/4
$ENV{"UTF8"} or defined($r->{"subcommand_data"} && $r->{"subcommand_data"}{"use_utf8"}) or $self->use_utf8
$ENV{"UTF8"} $r->{'subcommand_data'} $r->{'subcommand_data'}{'use_utf8'} $self->use_utf8
Truth table66%4/6
A or B && C or D
A= $ENV{"UTF8"}B= $r->{'subcommand_data'}C= $r->{'subcommand_data'}{'use_utf8'}D= $self->use_utf8
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
429 defined($r->{subcommand_data} && $r->{subcommand_data}{use_utf8}) ||
430 $self->use_utf8) {
431 3 $layer = ":encoding(utf8)"; last;
432 }
433  
434 82 ▶ if ($self->use_locale) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_locale) 0 82 82
435 0 $layer = ":locale"; last;
436 }
437  
438 }
439 85 ▶ binmode($handle, $layer) if $layer;
Branch: 1 branch
BranchTrueFalseTotal
if $layer 3 82 85
440  
441 85 $self->display_result($r);
442 }
443  
444 98 ▶sub hook_after_get_meta {
Subroutine hook_after_get_meta: called CC=20 SCAR=38.3
Pod documented
445 98 my ($self, $r) = @_;
446  
447 98 my $copts = $self->common_opts;
448  
449 # note: we cannot cache this to $r->{_ggls_res} because we produce this
450 # without dry-run
451 98 require Perinci::Sub::GetArgs::Argv;
452 my $ggls_res = Perinci::Sub::GetArgs::Argv::gen_getopt_long_spec_from_meta(
453 meta => $r->{meta},
454 meta_is_normalized => 1,
455 args => $r->{args},
456 common_opts => $copts,
457 per_arg_json => $self->{per_arg_json},
458 per_arg_yaml => $self->{per_arg_yaml},
459 98 );
460  
461 98 my $meta_uses_opt_n = 0;
462 98 my $meta_uses_opt_N = 0;
463 {
464 98 ▶ last unless $ggls_res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $ggls_res->[0] == 200 0 98 98
465 98 my $opts = $ggls_res->[3]{'func.opts'};
466 98 ▶ if (grep { $_ eq '-n' } @$opts) { $meta_uses_opt_n = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-n";} @$opts) 1 97 98
467 0 ▶ if (grep { $_ eq '-N' } @$opts) { $meta_uses_opt_N = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-N";} @$opts) 0 98 98
468 }
469  
470 98 require Perinci::Object;
471 98 my $metao = Perinci::Object::risub($r->{meta});
472  
473 # delete --format, --json, --naked-res if function does not want its output
474 # to be formatted
475 {
476 98 ▶ last if $self->skip_format; # already doesn't have those copts
Branch: 1 branch
BranchTrueFalseTotal
if $self->skip_format 0 98 98
477 98 ▶ last unless $r->{meta}{'cmdline.skip_format'};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"meta"}{"cmdline.skip_format"} 98 0 98
478 0 delete $copts->{format};
479 0 delete $copts->{json};
480 0 delete $copts->{naked_res};
481 }
482  
483 # add --dry-run (and -n shortcut, if no conflict)
484 {
485 98 ▶ last if $copts->{dry_run} || $copts->{no_dry_run}; # sometimes we are run more than once?
Branch: 1 branch
BranchTrueFalseTotal
if $copts->{"dry_run"} or $copts->{"no_dry_run"} 0 98 98
Condition33%1/3
$copts->{"dry_run"} or $copts->{"no_dry_run"}
l!l&&r!l&&!r
0098
MC/DC0%0/2
$copts->{"dry_run"} or $copts->{"no_dry_run"}
$copts->{"dry_run"} $copts->{"no_dry_run"}
Truth table33%1/3
A or B
A= $copts->{"dry_run"}B= $copts->{"no_dry_run"}
ABresult
1X1
011
000
486 98 ▶ last unless $metao->can_dry_run;
Branch: 1 branch
BranchTrueFalseTotal
unless $metao->can_dry_run 95 3 98
487 3 ▶ my $default_dry_run = $metao->default_dry_run // $self->default_dry_run;
Condition33%1/3
$metao->default_dry_run // $self->default_dry_run
l!l&&r!l&&!r
300
MC/DC0%0/2
$metao->default_dry_run // $self->default_dry_run
$metao->default_dry_run $self->default_dry_run
Truth table33%1/3
A // B
A= $metao->default_dry_runB= $self->default_dry_run
ABresult
1X1
011
000
488 3 ▶ $r->{dry_run} = 1 if $default_dry_run;
Branch: 1 branch
BranchTrueFalseTotal
if $default_dry_run 0 3 3
489 3 ▶ $r->{dry_run} = ($ENV{DRY_RUN} ? 1:0) if defined $ENV{DRY_RUN};
Branch: 2 branches
BranchTrueFalseTotal
if defined $ENV{"DRY_RUN"} 3 0 3
$ENV{'DRY_RUN'} ? : 1 2 3
490  
491 3 ▶ if ($default_dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default_dry_run) { } 0 3 3
492 0 ▶ my $optname = 'no-dry-run' . ($meta_uses_opt_N ? '' : '|N');
Branch: 1 branch
BranchTrueFalseTotal
$meta_uses_opt_N ? : 0 0 0
493 $copts->{no_dry_run} = {
494 getopt => $optname,
495 summary => "Disable simulation mode (also via DRY_RUN=0)",
496 0 ▶ handler => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
497 0 my ($go, $val, $r) = @_;
498 0 log_debug("[pericmd] Dry-run mode is deactivated");
499 0 $r->{dry_run} = 0;
500 },
501 0 };
502 } else {
503 3 ▶ my $optname = 'dry-run' . ($meta_uses_opt_n ? '' : '|n');
Branch: 1 branch
BranchTrueFalseTotal
$meta_uses_opt_n ? : 0 3 3
504 $copts->{dry_run} = {
505 getopt => $optname,
506 summary => "Run in simulation mode (also via DRY_RUN=1)",
507 1 ▶ handler => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
508 1 my ($go, $val, $r) = @_;
509 1 log_debug("[pericmd] Dry-run mode is activated");
510 1 $r->{dry_run} = 1;
511 }
512 3 };
513 }
514 }
515  
516 # check deps property. XXX this should be done only when we don't wrap
517 # subroutine, because Perinci::Sub::Wrapper already checks the deps
518 # property.
519 98 ▶ if ($r->{meta}{deps} && !$r->{in_dump_object} && !$r->{in_completion}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"meta"}{"deps"} and not $r->{"in_dump_object"} and not $r->{"in_completion"}) 0 98 98
Condition33%2/6
$r->{"meta"}{"deps"} and not $r->{"in_dump_object"} and not $r->{"in_completion"}
!ll&&!rl&&r
9800
$r->{"meta"}{"deps"} and not $r->{"in_dump_object"}
!ll&&!rl&&r
9800
MC/DC0%0/3
$r->{"meta"}{"deps"} and not $r->{"in_dump_object"} and not $r->{"in_completion"}
$r->{"meta"}{"deps"} not $r->{"in_dump_object"} not $r->{"in_completion"}
Truth table25%1/4
A and not(B) and not(C)
A= $r->{"meta"}{"deps"}B= not $r->{"in_dump_object"}C= not $r->{"in_completion"}
ABCresult
0XX0
10X0
1100
1111
520 0 require Perinci::Sub::DepChecker;
521 0 my $res = Perinci::Sub::DepChecker::check_deps($r->{meta}{deps});
522 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
523 0 die [412, "Dependency failed: $res"];
524 }
525 }
526 }
527  
528 1 ▶sub action_subcommands {
Subroutine action_subcommands: called CC=5 SCAR=16.6
Pod undocumented
529 1 my ($self, $r) = @_;
530  
531 1 ▶ if (!$self->subcommands) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->subcommands) 0 1 1
532 0 say "There are no subcommands.";
533 0 return 0;
534 }
535  
536 1 say "Available subcommands:";
537 1 my $scs = $self->list_subcommands;
538 1 my $longest = 6;
539 1 ▶ for (keys %$scs) { my $l = length; $longest = $l if $l > $longest }
Branch: 1 branch
BranchTrueFalseTotal
if $l > $longest 1 1 2
540 [200, "OK",
541 join("",
542 1 ▶ (map { sprintf(" %-${longest}s %s\n",$_,$scs->{$_}{summary}//"") }
Condition50%1/2
$scs->{$_}{"summary"} // ""
l!l
02
MC/DC0%0/1
$scs->{$_}{"summary"} // ""
$scs->{$_}{"summary"}
Truth table50%1/2
A
A= $scs->{$_}{"summary"}
Aresult
11
00
543 sort keys %$scs),
544 )];
545 }
546  
547 1 ▶sub action_version {
Subroutine action_version: called CC=12 SCAR=33.1
Pod undocumented
548 86 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
549  
550 1 my ($self, $r) = @_;
551  
552 1 my @text;
553  
554 {
555 1 my $meta = $r->{meta} = $self->get_meta($r, $self->url);
556 push @text, $self->get_program_and_subcommand_name($r),
557 " version ", ($meta->{entity_v} // "?"),
558 1 ▶ ($meta->{entity_date} ? " ($meta->{entity_date})" : ''),
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'entity_date'} ? : 1 0 1
Condition50%1/2
$meta->{"entity_v"} // "?"
l!l
10
MC/DC0%0/1
$meta->{"entity_v"} // "?"
$meta->{"entity_v"}
Truth table50%1/2
A
A= $meta->{"entity_v"}
Aresult
11
00
559 "\n";
560 1 ▶ for my $mod (@{ $meta->{'x.dynamic_generator_modules'} // [] }) {
Condition50%1/2
$meta->{"x.dynamic_generator_modules"} // []
l!l
01
MC/DC0%0/1
$meta->{"x.dynamic_generator_modules"} // []
$meta->{"x.dynamic_generator_modules"}
Truth table50%1/2
A
A= $meta->{"x.dynamic_generator_modules"}
Aresult
11
00
561 0 ▶ push @text, " $mod version ", ${"$mod\::VERSION"},
Branch: 1 branch
BranchTrueFalseTotal
${"${mod}::DATE";} ? : 0 0 0
562 0 (${"$mod\::DATE"} ? " (".${"$mod\::DATE"}.")" : ""),
563 "\n";
564 }
565 }
566  
567 1 ▶ for my $url (@{ $self->extra_urls_for_version // [] }) {
Condition50%1/2
$self->extra_urls_for_version // []
l!l
01
MC/DC0%0/1
$self->extra_urls_for_version // []
$self->extra_urls_for_version
Truth table50%1/2
A
A= $self->extra_urls_for_version
Aresult
11
00
568 0 my $meta = $self->get_meta($r, $url);
569 push @text, " $url version ", ($meta->{entity_v} // "?"),
570 0 ▶ ($meta->{entity_date} ? " ($meta->{entity_date})" : ''),
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'entity_date'} ? : 0 0 0
Condition0%0/2
$meta->{"entity_v"} // "?"
l!l
00
MC/DC0%0/1
$meta->{"entity_v"} // "?"
$meta->{"entity_v"}
Truth table0%0/2
A
A= $meta->{"entity_v"}
Aresult
11
00
571 "\n";
572 }
573  
574 1 ▶ push @text, " ", __PACKAGE__,
Branch: 1 branch
BranchTrueFalseTotal
$Perinci::CmdLine::Lite::DATE ? : 1 0 1
Condition50%1/2
$Perinci::CmdLine::Lite::VERSION // "?"
l!l
10
MC/DC0%0/1
$Perinci::CmdLine::Lite::VERSION // "?"
$Perinci::CmdLine::Lite::VERSION
Truth table50%1/2
A
A= $Perinci::CmdLine::Lite::VERSION
Aresult
11
00
575 " version ", ($Perinci::CmdLine::Lite::VERSION // "?"),
576 ($Perinci::CmdLine::Lite::DATE ?
577 " ($Perinci::CmdLine::Lite::DATE)":''),
578 "\n";
579  
580 1 [200, "OK", join("", @text)];
581 }
582  
583 4 ▶sub action_help {
Subroutine action_help: called CC=10 SCAR=23.5
Pod undocumented
584 4 require Perinci::CmdLine::Help;
585  
586 4 my ($self, $r) = @_;
587  
588 4 my @help;
589 4 my $scn = $r->{subcommand_name};
590 4 my $scd = $r->{subcommand_data};
591  
592 4 ▶ my $meta = $self->get_meta($r, $scd->{url} // $self->{url});
Condition33%1/3
$scd->{"url"} // $self->{"url"}
l!l&&r!l&&!r
400
MC/DC0%0/2
$scd->{"url"} // $self->{"url"}
$scd->{"url"} $self->{"url"}
Truth table33%1/3
A // B
A= $scd->{"url"}B= $self->{"url"}
ABresult
1X1
011
000
593  
594 # XXX use 'delete local' when we bump minimal perl to 5.12
595 4 my $common_opts = { %{$self->common_opts} };
596  
597 # hide usage '--subcommands' if we have subcommands but user has specified a
598 # subcommand to use
599 my $has_sc_no_sc = $self->subcommands &&
600 4 ▶ !length($r->{subcommand_name} // '');
Condition80%4/5
$self->subcommands && !length($r->{'subcommand_name'} // '')
!ll&&!rl&&r
211
$r->{"subcommand_name"} // ""
l!l
20
MC/DC0%0/2
$self->subcommands && !length($r->{'subcommand_name'} // '')
$self->subcommands $r->{"subcommand_name"}
Truth table66%2/3
A && not(B)
A= $self->subcommandsB= $r->{"subcommand_name"}
ABresult
0X0
110
101
601 4 ▶ delete $common_opts->{subcommands} if $self->subcommands && !$has_sc_no_sc;
Branch: 1 branch
BranchTrueFalseTotal
if $self->subcommands and not $has_sc_no_sc 1 3 4
Condition100%3/3
$self->subcommands and not $has_sc_no_sc
!ll&&!rl&&r
211
MC/DC100%2/2
$self->subcommands and not $has_sc_no_sc
$self->subcommands not $has_sc_no_sc
Truth table100%3/3
A and not(B)
A= $self->subcommandsB= not $has_sc_no_sc
ABresult
0X0
100
111
602  
603 my $res = Perinci::CmdLine::Help::gen_help(
604 program_name => $self->get_program_and_subcommand_name($r),
605 program_summary => ($scd ? $scd->{summary}:undef ) // $meta->{summary},
606 program_description => $scd ? $scd->{description} : undef,
607 4 ▶ meta => $meta,
Branch: 3 branches
BranchTrueFalseTotal
$scd ? : 4 0 4
$scd ? : 4 0 4
$has_sc_no_sc ? : 1 3 4
Condition66%2/3
($scd ? $scd->{"summary"} : undef) // $meta->{"summary"}
l!l&&r!l&&!r
031
MC/DC50%1/2
($scd ? $scd->{"summary"} : undef) // $meta->{"summary"}
($scd ? $scd->{"summary"} : undef) $meta->{"summary"}
Truth table66%2/3
A // B
A= ($scd ? $scd->{"summary"} : undef)B= $meta->{"summary"}
ABresult
1X1
011
000
608 meta_is_normalized => 1,
609 subcommands => $has_sc_no_sc ? $self->list_subcommands : undef,
610 common_opts => $common_opts,
611 per_arg_json => $self->per_arg_json,
612 per_arg_yaml => $self->per_arg_yaml,
613 mark_different_lang => 0,
614 );
615  
616 4 $res->[3]{"cmdline.skip_format"} = 1;
617 4 $res;
618 }
619  
620 61 ▶sub action_call {
Subroutine action_call: called CC=5 SCAR=16.9
Pod undocumented
621 61 my ($self, $r) = @_;
622  
623 61 my %extra;
624 61 ▶ if ($r->{send_argv}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{'send_argv'}) { } 0 61 61
625 0 log_trace("[pericmd] Sending argv to server: %s", $extra{argv});
626 0 $extra{argv} = $r->{orig_argv};
627 } else {
628 61 my %extra_args;
629 61 ▶ $extra_args{-dry_run} = 1 if $r->{dry_run};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"dry_run"} 2 59 61
630 61 $extra{args} = {%extra_args, %{$r->{args}}};
631 }
632  
633 61 ▶ $extra{stream_arg} = 1 if $r->{stream_arg};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"stream_arg"} 0 61 61
634  
635 61 my $url = $r->{subcommand_data}{url};
636  
637 # currently we don't log args because it's potentially large
638 61 log_trace("[pericmd] Riap request: action=call, url=%s", $url);
639  
640 #log_trace("TMP: extra=%s", \%extra);
641  
642 # setup output progress indicator
643 61 ▶ if ($r->{meta}{features}{progress}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"meta"}{"features"}{"progress"}) 0 61 61
644 0 $self->_setup_progress_output;
645 }
646  
647 $self->riap_client->request(
648 61 call => $url, \%extra);
649 }
650  
651 86 1;
652 # ABSTRACT: A Rinci/Riap-based command-line application framework
653  
654 __END__
« blib/lib/Perinci/CmdLine/Base.pm ↑ Summary blib/lib/Perinci/CmdLine/Plugin/Run/Completion.pm »