| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Response class for App::Spec::Run |
|
2
|
4
|
|
|
4
|
|
24
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
98
|
|
|
3
|
4
|
|
|
4
|
|
45
|
use warnings; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
173
|
|
|
4
|
|
|
|
|
|
|
package App::Spec::Run::Response; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.012'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
1242
|
use App::Spec::Run::Output; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
104
|
|
|
9
|
4
|
|
|
4
|
|
24
|
use Scalar::Util qw/ blessed /; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
159
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
18
|
use Moo; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
13
|
|
|
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
|
63
|
my ($self, @out) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
22
|
|
|
|
|
58
|
for my $out (@out) { |
|
24
|
22
|
50
|
|
|
|
70
|
unless (blessed $out) { |
|
25
|
22
|
100
|
|
|
|
513
|
$out = App::Spec::Run::Output->new( |
|
26
|
|
|
|
|
|
|
content => $out, |
|
27
|
|
|
|
|
|
|
ref $out ? (type => 'data') : (), |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
22
|
100
|
|
|
|
3479
|
if ($self->buffered) { |
|
33
|
20
|
|
|
|
|
55
|
my $outputs = $self->outputs; |
|
34
|
20
|
|
|
|
|
179
|
push @$outputs, @out; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
else { |
|
37
|
2
|
|
|
|
|
6
|
$self->print_output(@out); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_error { |
|
42
|
28
|
|
|
28
|
1
|
62
|
my ($self, @out) = @_; |
|
43
|
|
|
|
|
|
|
|
|
44
|
28
|
|
|
|
|
53
|
for my $out (@out) { |
|
45
|
28
|
50
|
|
|
|
84
|
unless (blessed $out) { |
|
46
|
28
|
|
|
|
|
620
|
$out = App::Spec::Run::Output->new( |
|
47
|
|
|
|
|
|
|
error => 1, |
|
48
|
|
|
|
|
|
|
content => $out, |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
28
|
50
|
|
|
|
612
|
if ($self->buffered) { |
|
54
|
28
|
|
|
|
|
63
|
my $outputs = $self->outputs; |
|
55
|
28
|
|
|
|
|
85
|
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
|
|
|
|
|
5
|
my $outputs = $self->outputs; |
|
65
|
2
|
|
|
|
|
4
|
push @$outputs, @out; |
|
66
|
|
|
|
|
|
|
|
|
67
|
2
|
|
50
|
|
|
6
|
my $callbacks = $self->callbacks->{print_output} || []; |
|
68
|
2
|
|
|
|
|
4
|
for my $cb (@$callbacks) { |
|
69
|
4
|
|
|
|
|
8
|
$cb->(); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
6
|
while (my $out = shift @$outputs) { |
|
73
|
2
|
|
|
|
|
4
|
my $content = $out->content; |
|
74
|
2
|
50
|
|
|
|
10
|
if (ref $content) { |
|
75
|
0
|
|
|
|
|
0
|
require Data::Dumper; |
|
76
|
0
|
|
|
|
|
0
|
$content = Data::Dumper->Dump([$content], ['output']); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
2
|
50
|
|
|
|
5
|
if ($out->error) { |
|
79
|
0
|
|
|
|
|
0
|
print STDERR $content; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
else { |
|
82
|
2
|
|
|
|
|
107
|
print $content; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub add_callbacks { |
|
88
|
60
|
|
|
60
|
1
|
129
|
my ($self, $event, $cb_add) = @_; |
|
89
|
60
|
|
|
|
|
173
|
my $callbacks = $self->callbacks; |
|
90
|
60
|
|
50
|
|
|
292
|
my $cb = $callbacks->{ $event } ||= []; |
|
91
|
60
|
|
|
|
|
187
|
push @$cb, @$cb_add; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |