line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TAP::Parser::YAMLish::Writer; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
73866
|
use strict; |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
334
|
|
4
|
10
|
|
|
10
|
|
69
|
use warnings; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
367
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
69
|
use base 'TAP::Object'; |
|
10
|
|
|
|
|
33
|
|
|
10
|
|
|
|
|
8484
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '3.40_01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $ESCAPE_CHAR = qr{ [ \x00-\x1f \" ] }x; |
11
|
|
|
|
|
|
|
my $ESCAPE_KEY = qr{ (?: ^\W ) | $ESCAPE_CHAR }x; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my @UNPRINTABLE = qw( |
14
|
|
|
|
|
|
|
z x01 x02 x03 x04 x05 x06 a |
15
|
|
|
|
|
|
|
x08 t n v f r x0e x0f |
16
|
|
|
|
|
|
|
x10 x11 x12 x13 x14 x15 x16 x17 |
17
|
|
|
|
|
|
|
x18 x19 x1a e x1c x1d x1e x1f |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# new() implementation supplied by TAP::Object |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub write { |
23
|
20
|
|
|
20
|
1
|
40
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
20
|
50
|
|
|
|
56
|
die "Need something to write" |
26
|
|
|
|
|
|
|
unless @_; |
27
|
|
|
|
|
|
|
|
28
|
20
|
|
|
|
|
33
|
my $obj = shift; |
29
|
20
|
|
50
|
|
|
49
|
my $out = shift || \*STDOUT; |
30
|
|
|
|
|
|
|
|
31
|
20
|
50
|
|
|
|
53
|
die "Need a reference to something I can write to" |
32
|
|
|
|
|
|
|
unless ref $out; |
33
|
|
|
|
|
|
|
|
34
|
20
|
|
|
|
|
110
|
$self->{writer} = $self->_make_writer($out); |
35
|
|
|
|
|
|
|
|
36
|
20
|
|
|
|
|
61
|
$self->_write_obj( '---', $obj ); |
37
|
20
|
|
|
|
|
98
|
$self->_put('...'); |
38
|
|
|
|
|
|
|
|
39
|
20
|
|
|
|
|
81
|
delete $self->{writer}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _make_writer { |
43
|
20
|
|
|
20
|
|
34
|
my $self = shift; |
44
|
20
|
|
|
|
|
35
|
my $out = shift; |
45
|
|
|
|
|
|
|
|
46
|
20
|
|
|
|
|
32
|
my $ref = ref $out; |
47
|
|
|
|
|
|
|
|
48
|
20
|
100
|
0
|
|
|
52
|
if ( 'CODE' eq $ref ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
49
|
18
|
|
|
|
|
68
|
return $out; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
elsif ( 'ARRAY' eq $ref ) { |
52
|
1
|
|
|
26
|
|
5
|
return sub { push @$out, shift }; |
|
26
|
|
|
|
|
59
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ( 'SCALAR' eq $ref ) { |
55
|
1
|
|
|
26
|
|
5
|
return sub { $$out .= shift() . "\n" }; |
|
26
|
|
|
|
|
64
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ( 'GLOB' eq $ref || 'IO::Handle' eq $ref ) { |
58
|
0
|
|
|
0
|
|
0
|
return sub { print $out shift(), "\n" }; |
|
0
|
|
|
|
|
0
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
die "Can't write to $out"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _put { |
65
|
168
|
|
|
168
|
|
214
|
my $self = shift; |
66
|
168
|
|
|
|
|
433
|
$self->{writer}->( join '', @_ ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _enc_scalar { |
70
|
212
|
|
|
212
|
|
254
|
my $self = shift; |
71
|
212
|
|
|
|
|
250
|
my $val = shift; |
72
|
212
|
|
|
|
|
241
|
my $rule = shift; |
73
|
|
|
|
|
|
|
|
74
|
212
|
100
|
|
|
|
335
|
return '~' unless defined $val; |
75
|
|
|
|
|
|
|
|
76
|
209
|
100
|
|
|
|
754
|
if ( $val =~ /$rule/ ) { |
77
|
19
|
|
|
|
|
44
|
$val =~ s/\\/\\\\/g; |
78
|
19
|
|
|
|
|
31
|
$val =~ s/"/\\"/g; |
79
|
19
|
|
|
|
|
52
|
$val =~ s/ ( [\x00-\x1f] ) / '\\' . $UNPRINTABLE[ ord($1) ] /gex; |
|
16
|
|
|
|
|
53
|
|
80
|
19
|
|
|
|
|
65
|
return qq{"$val"}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
190
|
100
|
66
|
|
|
559
|
if ( length($val) == 0 or $val =~ /\s/ ) { |
84
|
3
|
|
|
|
|
7
|
$val =~ s/'/''/; |
85
|
3
|
|
|
|
|
17
|
return "'$val'"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
187
|
|
|
|
|
445
|
return $val; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _write_obj { |
92
|
148
|
|
|
148
|
|
200
|
my $self = shift; |
93
|
148
|
|
|
|
|
182
|
my $prefix = shift; |
94
|
148
|
|
|
|
|
198
|
my $obj = shift; |
95
|
148
|
|
100
|
|
|
267
|
my $indent = shift || 0; |
96
|
|
|
|
|
|
|
|
97
|
148
|
100
|
|
|
|
251
|
if ( my $ref = ref $obj ) { |
98
|
41
|
|
|
|
|
72
|
my $pad = ' ' x $indent; |
99
|
41
|
100
|
|
|
|
90
|
if ( 'HASH' eq $ref ) { |
|
|
50
|
|
|
|
|
|
100
|
30
|
100
|
|
|
|
74
|
if ( keys %$obj ) { |
101
|
28
|
|
|
|
|
75
|
$self->_put($prefix); |
102
|
28
|
|
|
|
|
152
|
for my $key ( sort keys %$obj ) { |
103
|
105
|
|
|
|
|
290
|
my $value = $obj->{$key}; |
104
|
105
|
|
|
|
|
184
|
$self->_write_obj( |
105
|
|
|
|
|
|
|
$pad . $self->_enc_scalar( $key, $ESCAPE_KEY ) . ':', |
106
|
|
|
|
|
|
|
$value, $indent + 1 |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
2
|
|
|
|
|
5
|
$self->_put( $prefix, ' {}' ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
elsif ( 'ARRAY' eq $ref ) { |
115
|
11
|
100
|
|
|
|
20
|
if (@$obj) { |
116
|
9
|
|
|
|
|
24
|
$self->_put($prefix); |
117
|
9
|
|
|
|
|
31
|
for my $value (@$obj) { |
118
|
23
|
|
|
|
|
86
|
$self->_write_obj( |
119
|
|
|
|
|
|
|
$pad . '-', $value, |
120
|
|
|
|
|
|
|
$indent + 1 |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else { |
125
|
2
|
|
|
|
|
5
|
$self->_put( $prefix, ' []' ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
else { |
129
|
0
|
|
|
|
|
0
|
die "Don't know how to encode $ref"; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else { |
133
|
107
|
|
|
|
|
190
|
$self->_put( $prefix, ' ', $self->_enc_scalar( $obj, $ESCAPE_CHAR ) ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |