Spec/Run.pm

filter: Statementstmt 91.7% 243 / 265 Branchbran 76.1% 64 / 84 Conditioncond 65.9% 31 / 47 MC/DCmcdc 40.7% 11 / 27 Subroutinesub 90.3% 28 / 31 Podpod 100% 17 / 17 totaltotal 83.6% 394 / 471 CC 71 SCAR 21.9
CC
71
Cov
85%
completion_output
16.9
process_input
14.1
colorize
13.7
CRAP 9.0
« Spec/Pod.pm ↑ Summary Spec/Role/Command.pm »
1 # ABSTRACT: App::Spec framework to run your app
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package App::Spec::Run;
5 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 our $VERSION = 'v0.15.1'; # TRIAL VERSION
7  
8 5 ▶use App::Spec::Run::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use App::Spec::Run::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Getopt::Long qw/ :config pass_through bundling /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Ref::Util qw/ is_arrayref /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 has spec => ( is => 'ro' );
15 5 has options => ( is => 'rw' );
16 34 ▶has parameters => ( is => 'rw', default => sub { +{} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
17 5 has commands => ( is => 'rw' );
18 5 has argv => ( is => 'rw' );
19 5 has argv_orig => ( is => 'rw' );
20 #has runmode => ( is => 'rw', default => 'normal' );
21 5 has validation_errors => ( is => 'rw' );
22 5 has op => ( is => 'rw' );
23 5 has cmd => ( is => 'rw' );
24 34 ▶has response => ( is => 'rw', default => sub { App::Spec::Run::Response->new } );
Subroutine __ANON__: called CC=1 SCAR=0.0
25 34 ▶has subscribers => ( is => 'rw', default => sub { +{} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
26  
27 5 my %EVENTS = (
28 print_output => 1,
29 global_options => 1,
30 );
31  
32 34 ▶sub process {
Subroutine process: called CC=12 SCAR=24.9
Pod documented
33 34 my ($self) = @_;
34  
35 34 ▶ my $plugins = $self->spec->plugins || [];
Condition50%1/2
$self->spec->plugins || []
l!l
340
MC/DC0%0/1
$self->spec->plugins || []
$self->spec->plugins
Truth table50%1/2
A
A= $self->spec->plugins
Aresult
11
00
36 34 for my $plugin (@$plugins) {
37 92 $plugin->init_run($self);
38 }
39 34 my @callbacks;
40 34 my $subscriber_events = $self->subscribers;
41 34 for my $key (qw/ global_options print_output /) {
42 68 my $subscribers = $subscriber_events->{ $key };
43 68 for my $sub (@$subscribers) {
44 62 my $plugin = $sub->{plugin};
45 62 my $method = $sub->{method};
46 4 ▶ my $callback = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
47 4 $plugin->$method( run => $self, @_);
48 62 };
49 62 push @callbacks, $callback;
50 }
51 68 $self->response->add_callbacks($key => \@callbacks);
52 }
53  
54 34 my $argv = $self->argv;
55 34 ▶ unless ($argv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($argv) 33 1 34
56 33 $argv = \@ARGV;
57 33 $self->argv($argv);
58 33 $self->argv_orig([ @$argv ]);
59 }
60  
61 34 my $completion_parameter = $ENV{PERL5_APPSPECRUN_COMPLETION_PARAMETER};
62  
63 34 my %option_specs;
64 my %param_specs;
65 34 ▶ unless ($self->op) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->op) 34 0 34
66 34 $self->process_input(
67 option_specs => \%option_specs,
68 param_specs => \%param_specs,
69 );
70 }
71  
72 34 ▶ unless ($self->response->halted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->response->halted) 31 3 34
73 31 my $opt = App::Spec::Run::Validator->new({
74 options => $self->options,
75 option_specs => \%option_specs,
76 parameters => $self->parameters,
77 param_specs => \%param_specs,
78 });
79 31 my %errs;
80 31 my $ok = $opt->process( $self, \%errs );
81 31 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 15 16 31
82 15 $self->validation_errors(\%errs);
83 # if we are in completion mode, some errors might be ok
84 15 ▶ if (not $completion_parameter) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($completion_parameter) 9 6 15
85 9 $self->error_output;
86 }
87 }
88 }
89  
90 34 ▶ unless ($self->response->halted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->response->halted) 22 12 34
91  
92 22 my $op = $self->op;
93  
94 22 ▶ if ($completion_parameter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($completion_parameter) { } 6 16 22
95 6 $self->completion_output(
96 param_specs => \%param_specs,
97 option_specs => \%option_specs,
98 completion_parameter => $completion_parameter,
99 );
100 }
101 else {
102 16 $self->run_op($op);
103 }
104 }
105  
106 }
107  
108 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
109 0 my ($self) = @_;
110  
111 0 $self->process;
112  
113 # $self->event_processed;
114 0 $self->finish;
115  
116 }
117  
118 21 ▶sub run_op {
Subroutine run_op: called CC=1 SCAR=0.0
Pod documented
119 21 my ($self, $op, $args) = @_;
120 21 $self->cmd->$op($self, $args);
121 }
122  
123 26 ▶sub out {
Subroutine out: called CC=3 SCAR=11.0
Pod documented
124 26 my ($self, $text) = @_;
125 26 ▶ $text .= "\n" if (not ref $text and $text !~ m/\n\z/);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $text or $text =~ /\n\z/ 13 13 26
Condition100%3/3
ref $text or $text =~ /\n\z/
l!l&&r!l&&!r
11213
MC/DC100%2/2
ref $text or $text =~ /\n\z/
ref $text $text =~ /\n\z/
Truth table100%3/3
A or B
A= ref $textB= $text =~ /\n\z/
ABresult
1X1
011
000
126 26 $self->response->add_output($text);
127 }
128  
129 28 ▶sub err {
Subroutine err: called CC=3 SCAR=11.0
Pod documented
130 28 my ($self, $text) = @_;
131 28 ▶ $text .= "\n" if (not ref $text and $text !~ m/\n\z/);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $text or $text =~ /\n\z/ 1 27 28
Condition66%2/3
ref $text or $text =~ /\n\z/
l!l&&r!l&&!r
0271
MC/DC50%1/2
ref $text or $text =~ /\n\z/
ref $text $text =~ /\n\z/
Truth table66%2/3
A or B
A= ref $textB= $text =~ /\n\z/
ABresult
1X1
011
000
132 28 $self->response->add_error($text);
133 }
134  
135 13 ▶sub halt {
Subroutine halt: called CC=2 SCAR=7.1
Pod documented
136 13 my ($self, $exit) = @_;
137 13 $self->response->halted(1);
138 13 ▶ $self->response->exit($exit || 0);
Condition50%1/2
$exit || 0
l!l
130
MC/DC0%0/1
$exit || 0
$exit
Truth table50%1/2
A
A= $exit
Aresult
11
00
139 }
140  
141 0 ▶sub finish {
Subroutine finish: not called CC=2 SCAR=17.9
Pod documented
142 0 my ($self) = @_;
143 0 my $res = $self->response;
144 0 $res->print_output;
145 0 $res->finished(1);
146 0 ▶ if (my $exit = $res->exit) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exit = $res->exit) 0 0 0
147 0 exit $exit;
148 }
149 }
150  
151 6 ▶sub completion_output {
Subroutine completion_output: called CC=16 SCAR=28.3
Pod documented
152 6 my ($self, %args) = @_;
153 6 my $completion_parameter = $args{completion_parameter};
154 6 my $param_specs = $args{param_specs};
155 6 my $option_specs = $args{option_specs};
156 6 ▶ my $shell = $ENV{PERL5_APPSPECRUN_SHELL} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $shell = $ENV{"PERL5_APPSPECRUN_SHELL"} or return 5 1 6
157 5 my $param = $param_specs->{ $completion_parameter };
158 5 ▶ $param ||= $option_specs->{ $completion_parameter };
Condition33%1/3
$param ||= $option_specs->{$completion_parameter}
l!l&&r!l&&!r
500
MC/DC0%0/2
$param ||= $option_specs->{$completion_parameter}
$param $option_specs->{$completion_parameter}
Truth table33%1/3
A ||= B
A= $paramB= $option_specs->{$completion_parameter}
ABresult
1X1
011
000
159 5 my $unique = $param->{unique};
160 5 ▶ my $completion = $param->completion or return;
Branch: 1 branch
BranchTrueFalseTotal
my $completion = $param->completion or return 5 0 5
161 5 my $op;
162 5 ▶ if (ref $completion) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $completion) { } 2 3 5
163 2 ▶ $op = $completion->{op} or return;
Branch: 1 branch
BranchTrueFalseTotal
$op = $completion->{"op"} or return 2 0 2
164 }
165 else {
166 3 ▶ my $possible_values = $param->values or return;
Branch: 1 branch
BranchTrueFalseTotal
my $possible_values = $param->values or return 3 0 3
167 3 ▶ $op = $possible_values->{op} or return;
Branch: 1 branch
BranchTrueFalseTotal
$op = $possible_values->{"op"} or return 3 0 3
168 }
169 5 my $args = {
170 runmode => "completion",
171 parameter => $completion_parameter,
172 };
173 5 my $result = $self->run_op($op, $args);
174  
175 5 my $string = '';
176 5 my %seen;
177 5 ▶ if ($unique) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unique) 3 2 5
178 3 my $params = $self->parameters;
179 3 my $value = $params->{ $completion_parameter };
180 3 ▶ $value = [$value] unless is_arrayref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless is_arrayref($value) 0 3 3
181 # cmd param1 param2<TAB> results in
182 # @ARGV = ["param1", "param2"]
183 # cmd param1 param2 <TAB> results in
184 # @ARGV = ["param1", "param2", ""]
185 # so we know that there is a new value to be completed
186 3 my $last = pop @$value;
187 3 @seen{ @$value } = (1) x @$value;
188 }
189 5 for my $item (@$result) {
190 11 ▶ if (ref $item eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq 'HASH') { } 2 9 11
191 2 my $name = $item->{name};
192 2 ▶ $unique and $seen{ $name }++ and next;
Branch: 1 branch
BranchTrueFalseTotal
$unique and $seen{$name}++ and next 0 2 2
Condition33%1/3
$unique and $seen{$name}++
!ll&&!rl&&r
200
MC/DC0%0/2
$unique and $seen{$name}++
$unique $seen{$name}++
Truth table33%1/3
A and B
A= $uniqueB= $seen{$name}++
ABresult
0X0
100
111
193 2 my $desc = $item->{description};
194 2 $string .= "$name\t$desc\n";
195 }
196 else {
197 9 ▶ $unique and $seen{ $item }++ and next;
Branch: 1 branch
BranchTrueFalseTotal
$unique and $seen{$item}++ and next 2 7 9
Condition100%3/3
$unique and $seen{$item}++
!ll&&!rl&&r
342
MC/DC100%2/2
$unique and $seen{$item}++
$unique $seen{$item}++
Truth table100%3/3
A and B
A= $uniqueB= $seen{$item}++
ABresult
0X0
100
111
198 7 $string .= "$item\n";
199 }
200 }
201  
202 5 $self->out($string);
203 5 return;
204 }
205  
206 9 ▶sub error_output {
Subroutine error_output: called CC=6 SCAR=18.4
Pod documented
207 9 my ($self) = @_;
208 9 my $errs = $self->validation_errors;
209 9 my @error_output;
210 9 for my $key (sort keys %$errs) {
211 9 my $errors = $errs->{ $key };
212 9 ▶ if ($key eq "parameters" or $key eq "options") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'parameters' or $key eq 'options') { } 9 0 9
Condition66%2/3
$key eq "parameters" or $key eq "options"
l!l&&r!l&&!r
540
MC/DC0%0/2
$key eq "parameters" or $key eq "options"
$key eq "parameters" $key eq "options"
Truth table66%2/3
A or B
A= $key eq "parameters"B= $key eq "options"
ABresult
1X1
011
000
213 9 for my $name (sort keys %$errors) {
214 12 my $error = $errors->{ $name };
215 12 $key =~ s/s$//;
216 12 push @error_output, "Error: $key '$name': $error";
217 }
218 }
219 else {
220 0 require Data::Dumper;
221 0 my $err = Data::Dumper->Dump([$errs], ['errs']);
222 0 push @error_output, $err;
223 }
224 }
225 9 my $help = $self->spec->usage(
226 commands => $self->commands,
227 highlights => $errs,
228 colored => $self->colorize_code('err'),
229 );
230 9 $self->err($help);
231 9 for my $msg (@error_output) {
232 12 $msg = $self->colored('err', [qw/ error /], $msg);
233 12 $self->err("$msg\n");
234 }
235 9 $self->halt(1);
236 }
237  
238 19 ▶sub colorize_code {
Subroutine colorize_code: called CC=2 SCAR=11.1
Pod documented
239 19 my ($self, $out) = @_;
240 $self->colorize($out)
241 0 ▶ ? sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
242 0 my $colored = $self->colored($out, $_[0], $_[1]);
243 0 ▶ unless (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
244 0 $_[1] = $colored;
245 }
246 0 return $colored;
247 }
248 95 ▶ : sub { $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
249 19 ▶}
Branch: 1 branch
BranchTrueFalseTotal
$self->colorize($out) ? : 0 19 19
250  
251 34 ▶sub colorize {
Subroutine colorize: called CC=10 SCAR=26.2
Pod documented
252 34 my ($self, $out) = @_;
253 34 ▶ $out ||= 'out';
Condition100%2/2
$out ||= "out"
l!l
277
MC/DC100%1/1
$out ||= "out"
$out
Truth table100%2/2
A
A= $out
Aresult
11
00
254 34 ▶ if (($ENV{PERL5_APPSPECRUN_COLOR} // '') eq 'always') {
Branch: 1 branch
BranchTrueFalseTotal
if (($ENV{"PERL5_APPSPECRUN_COLOR"} // "") eq "always") 0 34 34
Condition100%2/2
$ENV{"PERL5_APPSPECRUN_COLOR"} // ""
l!l
322
MC/DC100%1/1
$ENV{"PERL5_APPSPECRUN_COLOR"} // ""
$ENV{"PERL5_APPSPECRUN_COLOR"}
Truth table100%2/2
A
A= $ENV{"PERL5_APPSPECRUN_COLOR"}
Aresult
11
00
255 0 return 1;
256 }
257 34 ▶ if (($ENV{PERL5_APPSPECRUN_COLOR} // '') eq 'never') {
Branch: 1 branch
BranchTrueFalseTotal
if (($ENV{"PERL5_APPSPECRUN_COLOR"} // "") eq "never") 32 2 34
Condition100%2/2
$ENV{"PERL5_APPSPECRUN_COLOR"} // ""
l!l
322
MC/DC100%1/1
$ENV{"PERL5_APPSPECRUN_COLOR"} // ""
$ENV{"PERL5_APPSPECRUN_COLOR"}
Truth table100%2/2
A
A= $ENV{"PERL5_APPSPECRUN_COLOR"}
Aresult
11
00
258 32 return 0;
259 }
260 2 ▶ if ($out eq 'out' and -t STDOUT or $out eq 'err' and -t STDERR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out eq "out" and -t STDOUT or $out eq "err" and -t STDERR) 0 2 2
Condition33%3/9
$out eq "out" and -t STDOUT or $out eq "err" and -t STDERR
l!l&&r!l&&!r
002
$out eq "out" and -t STDOUT
!ll&&!rl&&r
200
$out eq "err" and -t STDERR
!ll&&!rl&&r
020
MC/DC0%0/4
$out eq "out" and -t STDOUT or $out eq "err" and -t STDERR
$out eq "out" -t STDOUT $out eq "err" -t STDERR
Truth table14%1/7
A and B or C and D
A= $out eq "out"B= -t STDOUTC= $out eq "err"D= -t STDERR
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
261 0 return 1;
262 }
263 2 return 0;
264 }
265  
266 70 ▶sub process_parameters {
Subroutine process_parameters: called CC=3 SCAR=11.0
Pod documented
267 70 my ($self, %args) = @_;
268 70 my $param_list = $args{parameter_list};
269 70 my $parameters = $self->parameters;
270 70 my $param_specs = $args{param_specs};
271 70 for my $p (@$param_list) {
272 46 my $name = $p->name;
273 46 my $type = $p->type;
274 46 my $multiple = $p->multiple;
275 46 my $required = $p->required;
276 46 my $value;
277 46 ▶ if ($multiple) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multiple) { } 11 35 46
278 11 $value = [@{ $self->argv }];
279 11 @{ $self->argv } = ();
280 }
281 else {
282 35 $value = shift @{ $self->argv };
283 }
284 46 $parameters->{ $name } = $value;
285 46 $param_specs->{ $name } = $p;
286 }
287 }
288  
289 34 ▶sub process_input {
Subroutine process_input: called CC=14 SCAR=26.4
Pod documented
290 34 my ($self, %args) = @_;
291 34 my %options;
292 34 $self->options(\%options);
293 34 my @cmds;
294 34 my $spec = $self->spec;
295 34 my $option_specs = $args{option_specs};
296 34 my $param_specs = $args{param_specs};
297 34 my $global_options = $spec->options;
298 34 my $global_parameters = $spec->parameters;
299 34 my @getopt = $spec->make_getopt($global_options, \%options, $option_specs);
300 34 GetOptions(@getopt);
301 34 $self->event_globaloptions;
302 34 my $op = $self->op;
303  
304 34 $self->process_parameters(
305 parameter_list => $global_parameters,
306 param_specs => $param_specs,
307 );
308  
309  
310  
311 34 my $commands = $spec->subcommands;
312 34 my $opclass = $self->spec->class;
313 34 my $cmd_spec;
314 34 my $subcommand_required = 1;
315 34 ▶ while (keys %$commands) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$commands) 42 28 70
316 42 my $cmd = shift @{ $self->argv };
317 42 ▶ if (not defined $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cmd) 4 38 42
318 4 ▶ if (not $op or $subcommand_required) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $op or $subcommand_required) 1 3 4
Condition66%2/3
not $op or $subcommand_required
l!l&&r!l&&!r
103
MC/DC50%1/2
not $op or $subcommand_required
not $op $subcommand_required
Truth table66%2/3
not(A) or B
A= not $opB= $subcommand_required
ABresult
1X1
011
000
319 1 $self->err($spec->usage(
320 commands => \@cmds,
321 colored => $self->colorize_code('err'),
322 highlights => {
323 subcommands => 1,
324 },
325 ));
326 1 $self->err( $self->colorize_error("Missing subcommand(s)") );
327 1 $self->halt(1);
328 }
329 4 last;
330 }
331 38 ▶ $cmd_spec = $commands->{ $cmd } or do {
Branch: 1 branch
BranchTrueFalseTotal
$cmd_spec = $commands->{$cmd} or do { $self->err($spec->usage("commands", \@cmds, "colored", $self->colorize_code("err"), "highlights", {"subcommands", 1})); $self->err($self->colorize_error("Unknown subcommand '${cmd}'")); $self->halt(1); last } 36 2 38
332 2 $self->err($spec->usage(
333 commands => \@cmds,
334 colored => $self->colorize_code('err'),
335 highlights => {
336 subcommands => 1,
337 },
338 ));
339 2 $self->err( $self->colorize_error("Unknown subcommand '$cmd'") );
340 2 $self->halt(1);
341 2 last;
342 };
343 36 ▶ $subcommand_required = $cmd_spec->{subcommand_required} // 1;
Condition100%2/2
$cmd_spec->{"subcommand_required"} // 1
l!l
927
MC/DC100%1/1
$cmd_spec->{"subcommand_required"} // 1
$cmd_spec->{"subcommand_required"}
Truth table100%2/2
A
A= $cmd_spec->{"subcommand_required"}
Aresult
11
00
344 36 my $cmd_options = $cmd_spec->options;
345 36 my @getopt = $spec->make_getopt($cmd_options, \%options, $option_specs);
346 36 GetOptions(@getopt);
347 36 push @cmds, $cmd;
348 36 ▶ $commands = $cmd_spec->subcommands || {};
Condition100%2/2
$cmd_spec->subcommands || {}
l!l
1323
MC/DC100%1/1
$cmd_spec->subcommands || {}
$cmd_spec->subcommands
Truth table100%2/2
A
A= $cmd_spec->subcommands
Aresult
11
00
349 36 ▶ $op = '::' . $cmd_spec->op if $cmd_spec->op;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd_spec->op 29 7 36
350 36 ▶ $opclass = $cmd_spec->class if $cmd_spec->class;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd_spec->class 6 30 36
351  
352 36 $self->process_parameters(
353 parameter_list => $cmd_spec->parameters,
354 param_specs => $param_specs,
355 );
356 }
357  
358 34 ▶ unless ($self->response->halted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->response->halted) 31 3 34
359 31 ▶ unless ($op) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op) 1 30 31
360 1 ▶ if ($spec->has_subcommands) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->has_subcommands) { } 0 1 1
361 0 $self->err( "Missing op for commands (@cmds)\n" );
362 0 my $help = $spec->usage(
363 commands => \@cmds,
364 colored => $self->colorize_code('err'),
365 );
366 0 $self->err( $help );
367 0 $self->halt(1);
368 }
369 else {
370 1 $op = "::execute";
371 }
372 }
373 31 $self->commands(\@cmds);
374 31 $self->options(\%options);
375 31 ▶ if ($op =~ m/^::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /^::/) 30 1 31
376 30 $op = $opclass . $op;
377 }
378 31 $self->op($op);
379 31 return $op;
380 }
381  
382 3 return;
383 }
384  
385 3 ▶sub colorize_error {
Subroutine colorize_error: called CC=1 SCAR=0.0
Pod documented
386 3 my ($self, $msg) = @_;
387 3 $msg = $self->colored('err', [qw/ error /], $msg) . "\n";
388 }
389  
390 5 my $has_color;
391 15 ▶sub colored {
Subroutine colored: called CC=5 SCAR=16.6
Pod documented
392 15 my ($self, $out, $colors, $msg) = @_;
393 15 ▶ $colors = [ map { $_ eq 'error' ? qw/ bold red / : $_ } @$colors ];
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'error' ? : 15 0 15
394 15 ▶ $has_color //= eval { require Term::ANSIColor; 1 };
Condition66%2/3
$has_color //= eval { do { require Term::ANSIColor; 1 } }
l!l&&r!l&&!r
1320
MC/DC0%0/2
$has_color //= eval { do { require Term::ANSIColor; 1 } }
$has_color eval { do { require Term::ANSIColor; 1 } }
Truth table66%2/3
A //= B
A= $has_colorB= eval { do { require Term::ANSIColor; 1 } }
ABresult
1X1
011
000
395 15 ▶ return $msg unless $has_color;
Branch: 1 branch
BranchTrueFalseTotal
unless $has_color 0 15 15
396 15 ▶ $self->colorize($out)
Branch: 1 branch
BranchTrueFalseTotal
$self->colorize($out) and $msg = Term::ANSIColor::colored($colors, $msg) 0 15 15
397 and $msg = Term::ANSIColor::colored($colors, $msg);
398 15 return $msg;
399 }
400  
401 62 ▶sub subscribe {
Subroutine subscribe: called CC=3 SCAR=11.0
Pod documented
402 62 my ($self, %args) = @_;
403  
404 62 for my $event (sort keys %args) {
405 62 ▶ next unless exists $EVENTS{ $event };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $EVENTS{$event} 0 62 62
406 62 my $info = $args{ $event };
407 62 push @{ $self->subscribers->{ $event } }, $info;
408 }
409  
410 }
411  
412 34 ▶sub event_globaloptions {
Subroutine event_globaloptions: called CC=2 SCAR=6.9
Pod documented
413 34 my ($self) = @_;
414  
415 34 my $subscribers = $self->subscribers->{global_options};
416 34 for my $sub (@$subscribers) {
417 34 my $plugin = $sub->{plugin};
418 34 my $method = $sub->{method};
419 34 $plugin->$method( run => $self);
420 }
421 }
422  
423 #sub event_processed {
424 # my ($self) = @_;
425 # my $plugins = $self->spec->plugins_by_type->{GlobalOptions};
426 # for my $plugin (@$plugins) {
427 # next unless $plugin->can("event_processed");
428 # $plugin->event_processed(
429 # run => $self,
430 # );
431 # }
432 #}
433  
434 5 1;
435  
436 __END__
« Spec/Pod.pm ↑ Summary Spec/Role/Command.pm »