Spec/Run/Response.pm

filter: Statementstmt 93.2% 55 / 59 Branchbran 68.7% 11 / 16 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 86.4% 83 / 96 CC 14 SCAR 13.6
CC
14
Cov
86%
print_output
6.7
add_output
5.0
add_error
4.2
CRAP 3.9
« Spec/Plugin/Help.pm ↑ Summary Spec/Parameter.pm »
1 # ABSTRACT: Response class for App::Spec::Run
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package App::Spec::Run::Response;
5  
6 6 our $VERSION = 'v0.15.1'; # TRIAL VERSION
7  
8 6 ▶use App::Spec::Run::Output;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Scalar::Util qw/ blessed /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 has exit => ( is => 'rw', default => 0 );
14 34 ▶has outputs => ( is => 'rw', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
15 6 has finished => ( is => 'rw' );
16 6 has halted => ( is => 'rw' );
17 6 has buffered => ( is => 'rw', default => 0 );
18 34 ▶has callbacks => ( is => 'rw', default => sub { +{} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
19  
20 26 ▶sub add_output {
Subroutine add_output: called CC=5 SCAR=16.1
Pod documented
21 26 my ($self, @out) = @_;
22  
23 26 for my $out (@out) {
24 26 ▶ unless (blessed $out) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($out)) 26 0 26
25 26 ▶ $out = App::Spec::Run::Output->new(
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 1 25 26
26 content => $out,
27 ref $out ? (type => 'data') : (),
28 );
29 }
30 }
31  
32 26 ▶ if ($self->buffered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffered) { } 24 2 26
33 24 my $outputs = $self->outputs;
34 24 push @$outputs, @out;
35 }
36 else {
37 2 $self->print_output(@out);
38 }
39 }
40  
41 28 ▶sub add_error {
Subroutine add_error: called CC=4 SCAR=14.5
Pod documented
42 28 my ($self, @out) = @_;
43  
44 28 for my $out (@out) {
45 28 ▶ unless (blessed $out) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($out)) 28 0 28
46 28 $out = App::Spec::Run::Output->new(
47 error => 1,
48 content => $out,
49 );
50 }
51 }
52  
53 28 ▶ if ($self->buffered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffered) { } 28 0 28
54 28 my $outputs = $self->outputs;
55 28 push @$outputs, @out;
56 }
57 else {
58 0 $self->print_output(@out);
59 }
60 }
61  
62 2 ▶sub print_output {
Subroutine print_output: called CC=6 SCAR=19.1
Pod documented
63 2 my ($self, @out) = @_;
64 2 my $outputs = $self->outputs;
65 2 push @$outputs, @out;
66  
67 2 ▶ my $callbacks = $self->callbacks->{print_output} || [];
Condition50%1/2
$self->callbacks->{'print_output'} || []
l!l
20
MC/DC0%0/1
$self->callbacks->{'print_output'} || []
$self->callbacks->{'print_output'}
Truth table50%1/2
A
A= $self->callbacks->{'print_output'}
Aresult
11
00
68 2 for my $cb (@$callbacks) {
69 4 $cb->();
70 }
71  
72 2 ▶ while (my $out = shift @$outputs) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $out = shift @$outputs) 2 2 4
73 2 my $content = $out->content;
74 2 ▶ if (ref $content) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content) 0 2 2
75 0 require Data::Dumper;
76 0 $content = Data::Dumper->Dump([$content], ['output']);
77 }
78 2 ▶ if ($out->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->error) { } 0 2 2
79 0 print STDERR $content;
80 }
81 else {
82 2 print $content;
83 }
84 }
85 }
86  
87 68 ▶sub add_callbacks {
Subroutine add_callbacks: called CC=2 SCAR=7.0
Pod documented
88 68 my ($self, $event, $cb_add) = @_;
89 68 my $callbacks = $self->callbacks;
90 68 ▶ my $cb = $callbacks->{ $event } ||= [];
Condition50%1/2
$callbacks->{$event} ||= []
l!l
068
MC/DC0%0/1
$callbacks->{$event} ||= []
$callbacks->{$event}
Truth table50%1/2
A
A= $callbacks->{$event}
Aresult
11
00
91 68 push @$cb, @$cb_add;
92 }
93  
94 6 1;
95  
96 __END__
« Spec/Plugin/Help.pm ↑ Summary Spec/Parameter.pm »