line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Response class for App::Spec::Run |
2
|
4
|
|
|
4
|
|
28
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
121
|
|
3
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
191
|
|
4
|
|
|
|
|
|
|
package App::Spec::Run::Response; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.013'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
1571
|
use App::Spec::Run::Output; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
137
|
|
9
|
4
|
|
|
4
|
|
30
|
use Scalar::Util qw/ blessed /; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
201
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
24
|
use Moo; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
40
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has exit => ( is => 'rw', default => 0 ); |
14
|
|
|
|
|
|
|
has outputs => ( is => 'rw', default => sub { [] } ); |
15
|
|
|
|
|
|
|
has finished => ( is => 'rw' ); |
16
|
|
|
|
|
|
|
has halted => ( is => 'rw' ); |
17
|
|
|
|
|
|
|
has buffered => ( is => 'rw', default => 0 ); |
18
|
|
|
|
|
|
|
has callbacks => ( is => 'rw', default => sub { +{} } ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub add_output { |
21
|
22
|
|
|
22
|
1
|
72
|
my ($self, @out) = @_; |
22
|
|
|
|
|
|
|
|
23
|
22
|
|
|
|
|
63
|
for my $out (@out) { |
24
|
22
|
50
|
|
|
|
87
|
unless (blessed $out) { |
25
|
22
|
100
|
|
|
|
603
|
$out = App::Spec::Run::Output->new( |
26
|
|
|
|
|
|
|
content => $out, |
27
|
|
|
|
|
|
|
ref $out ? (type => 'data') : (), |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
22
|
100
|
|
|
|
4222
|
if ($self->buffered) { |
33
|
20
|
|
|
|
|
54
|
my $outputs = $self->outputs; |
34
|
20
|
|
|
|
|
193
|
push @$outputs, @out; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
2
|
|
|
|
|
9
|
$self->print_output(@out); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_error { |
42
|
28
|
|
|
28
|
1
|
70
|
my ($self, @out) = @_; |
43
|
|
|
|
|
|
|
|
44
|
28
|
|
|
|
|
100
|
for my $out (@out) { |
45
|
28
|
50
|
|
|
|
88
|
unless (blessed $out) { |
46
|
28
|
|
|
|
|
702
|
$out = App::Spec::Run::Output->new( |
47
|
|
|
|
|
|
|
error => 1, |
48
|
|
|
|
|
|
|
content => $out, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
28
|
50
|
|
|
|
728
|
if ($self->buffered) { |
54
|
28
|
|
|
|
|
74
|
my $outputs = $self->outputs; |
55
|
28
|
|
|
|
|
111
|
push @$outputs, @out; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
0
|
$self->print_output(@out); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub print_output { |
63
|
2
|
|
|
2
|
1
|
6
|
my ($self, @out) = @_; |
64
|
2
|
|
|
|
|
18
|
my $outputs = $self->outputs; |
65
|
2
|
|
|
|
|
6
|
push @$outputs, @out; |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
50
|
|
|
8
|
my $callbacks = $self->callbacks->{print_output} || []; |
68
|
2
|
|
|
|
|
5
|
for my $cb (@$callbacks) { |
69
|
4
|
|
|
|
|
10
|
$cb->(); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
7
|
while (my $out = shift @$outputs) { |
73
|
2
|
|
|
|
|
6
|
my $content = $out->content; |
74
|
2
|
50
|
|
|
|
13
|
if (ref $content) { |
75
|
0
|
|
|
|
|
0
|
require Data::Dumper; |
76
|
0
|
|
|
|
|
0
|
$content = Data::Dumper->Dump([$content], ['output']); |
77
|
|
|
|
|
|
|
} |
78
|
2
|
50
|
|
|
|
6
|
if ($out->error) { |
79
|
0
|
|
|
|
|
0
|
print STDERR $content; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
2
|
|
|
|
|
136
|
print $content; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub add_callbacks { |
88
|
60
|
|
|
60
|
1
|
158
|
my ($self, $event, $cb_add) = @_; |
89
|
60
|
|
|
|
|
164
|
my $callbacks = $self->callbacks; |
90
|
60
|
|
50
|
|
|
331
|
my $cb = $callbacks->{ $event } ||= []; |
91
|
60
|
|
|
|
|
227
|
push @$cb, @$cb_add; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |