line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Response class for App::Spec::Run |
2
|
4
|
|
|
4
|
|
29
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
122
|
|
3
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
193
|
|
4
|
|
|
|
|
|
|
package App::Spec::Run::Response; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.011'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
1820
|
use App::Spec::Run::Output; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
129
|
|
9
|
4
|
|
|
4
|
|
29
|
use Scalar::Util qw/ blessed /; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
186
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
23
|
use Moo; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
17
|
|
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
|
61
|
my ($self, @out) = @_; |
22
|
|
|
|
|
|
|
|
23
|
22
|
|
|
|
|
53
|
for my $out (@out) { |
24
|
22
|
50
|
|
|
|
75
|
unless (blessed $out) { |
25
|
22
|
100
|
|
|
|
505
|
$out = App::Spec::Run::Output->new( |
26
|
|
|
|
|
|
|
content => $out, |
27
|
|
|
|
|
|
|
ref $out ? (type => 'data') : (), |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
22
|
100
|
|
|
|
4234
|
if ($self->buffered) { |
33
|
20
|
|
|
|
|
51
|
my $outputs = $self->outputs; |
34
|
20
|
|
|
|
|
186
|
push @$outputs, @out; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
2
|
|
|
|
|
7
|
$self->print_output(@out); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_error { |
42
|
28
|
|
|
28
|
1
|
77
|
my ($self, @out) = @_; |
43
|
|
|
|
|
|
|
|
44
|
28
|
|
|
|
|
68
|
for my $out (@out) { |
45
|
28
|
50
|
|
|
|
105
|
unless (blessed $out) { |
46
|
28
|
|
|
|
|
762
|
$out = App::Spec::Run::Output->new( |
47
|
|
|
|
|
|
|
error => 1, |
48
|
|
|
|
|
|
|
content => $out, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
28
|
50
|
|
|
|
697
|
if ($self->buffered) { |
54
|
28
|
|
|
|
|
75
|
my $outputs = $self->outputs; |
55
|
28
|
|
|
|
|
105
|
push @$outputs, @out; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
0
|
$self->print_output(@out); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub print_output { |
63
|
2
|
|
|
2
|
1
|
5
|
my ($self, @out) = @_; |
64
|
2
|
|
|
|
|
6
|
my $outputs = $self->outputs; |
65
|
2
|
|
|
|
|
5
|
push @$outputs, @out; |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
50
|
|
|
9
|
my $callbacks = $self->callbacks->{print_output} || []; |
68
|
2
|
|
|
|
|
3
|
for my $cb (@$callbacks) { |
69
|
4
|
|
|
|
|
10
|
$cb->(); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
8
|
while (my $out = shift @$outputs) { |
73
|
2
|
|
|
|
|
4
|
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
|
|
|
|
|
126
|
print $content; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub add_callbacks { |
88
|
60
|
|
|
60
|
1
|
160
|
my ($self, $event, $cb_add) = @_; |
89
|
60
|
|
|
|
|
149
|
my $callbacks = $self->callbacks; |
90
|
60
|
|
50
|
|
|
296
|
my $cb = $callbacks->{ $event } ||= []; |
91
|
60
|
|
|
|
|
198
|
push @$cb, @$cb_add; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |