| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package IPC::PrettyPipe::Render::Template::Tiny; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: rendering backend using B |
|
4
|
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
2344
|
use Carp; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
280
|
|
|
6
|
4
|
|
|
4
|
|
485
|
use Template::Tiny; |
|
|
4
|
|
|
|
|
1303
|
|
|
|
4
|
|
|
|
|
114
|
|
|
7
|
4
|
|
|
4
|
|
23
|
use Safe::Isa; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
553
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
2052
|
use Text::Tabs qw[ expand ]; |
|
|
4
|
|
|
|
|
3082
|
|
|
|
4
|
|
|
|
|
268
|
|
|
10
|
4
|
|
|
4
|
|
31
|
use Types::Standard -all; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
56
|
|
|
11
|
4
|
|
|
4
|
|
195796
|
use Type::Params qw[ validate ]; |
|
|
4
|
|
|
|
|
14
|
|
|
|
4
|
|
|
|
|
42
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
1167
|
use Moo; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
41
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.11'; # TRIAL |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
BEGIN { |
|
19
|
4
|
50
|
|
4
|
|
3247
|
if ( $^O =~ /Win32/i ) { |
|
20
|
0
|
|
|
|
|
0
|
require Win32::Console::ANSI; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
} |
|
23
|
4
|
|
|
4
|
|
3101
|
use Term::ANSIColor (); |
|
|
4
|
|
|
|
|
38123
|
|
|
|
4
|
|
|
|
|
180
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
|
39
|
use namespace::clean; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
41
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has pipe => ( |
|
53
|
|
|
|
|
|
|
is => 'rw', |
|
54
|
|
|
|
|
|
|
isa => InstanceOf ['IPC::PrettyPipe'], |
|
55
|
|
|
|
|
|
|
required => 1, |
|
56
|
|
|
|
|
|
|
); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has colors => ( |
|
74
|
|
|
|
|
|
|
is => 'rw', |
|
75
|
|
|
|
|
|
|
isa => HashRef, |
|
76
|
|
|
|
|
|
|
default => sub { |
|
77
|
|
|
|
|
|
|
{ |
|
78
|
|
|
|
|
|
|
cmd => { |
|
79
|
|
|
|
|
|
|
cmd => 'blue', |
|
80
|
|
|
|
|
|
|
stream => { |
|
81
|
|
|
|
|
|
|
spec => 'red', |
|
82
|
|
|
|
|
|
|
file => 'green', |
|
83
|
|
|
|
|
|
|
}, |
|
84
|
|
|
|
|
|
|
arg => { |
|
85
|
|
|
|
|
|
|
name => 'red', |
|
86
|
|
|
|
|
|
|
sep => 'yellow', |
|
87
|
|
|
|
|
|
|
value => 'green', |
|
88
|
|
|
|
|
|
|
}, |
|
89
|
|
|
|
|
|
|
}, |
|
90
|
|
|
|
|
|
|
pipe => { |
|
91
|
|
|
|
|
|
|
stream => { |
|
92
|
|
|
|
|
|
|
spec => 'red', |
|
93
|
|
|
|
|
|
|
file => 'green', |
|
94
|
|
|
|
|
|
|
}, |
|
95
|
|
|
|
|
|
|
}, |
|
96
|
|
|
|
|
|
|
}; |
|
97
|
|
|
|
|
|
|
}, |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
has cmd_template => ( |
|
119
|
|
|
|
|
|
|
is => 'rw', |
|
120
|
|
|
|
|
|
|
default => <<"EOT", |
|
121
|
|
|
|
|
|
|
[%- indent %][% color.cmd.cmd %][% cmd.quoted_cmd %][% color.reset %] |
|
122
|
|
|
|
|
|
|
[%- FOREACH arg IN cmd.args.elements %]\\ |
|
123
|
|
|
|
|
|
|
[% indent %][% indent %][% color.cmd.arg.pfx %][% arg.pfx %][% color.cmd.arg.name %][% arg.quoted_name %] |
|
124
|
|
|
|
|
|
|
[%- IF arg.has_value %][%- IF arg.sep %][% color.cmd.arg.sep %][% arg.sep %][% ELSE %] [% END %] |
|
125
|
|
|
|
|
|
|
[%- color.cmd.arg.value %][% arg.quoted_value %][% END %][% color.reset %] |
|
126
|
|
|
|
|
|
|
[%- END %] |
|
127
|
|
|
|
|
|
|
[%- FOREACH stream IN cmd.streams.elements %]\\ |
|
128
|
|
|
|
|
|
|
[% indent %][% indent %][% color.cmd.stream.spec %][% stream.spec -%] |
|
129
|
|
|
|
|
|
|
[% IF stream.has_file %] [% color.cmd.stream.file %][% stream.quoted_file %][% color.reset %][% END %] |
|
130
|
|
|
|
|
|
|
[%- END -%] |
|
131
|
|
|
|
|
|
|
EOT |
|
132
|
|
|
|
|
|
|
); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
has pipe_template => ( |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
is => 'rw', |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
default => <<"EOT", |
|
156
|
|
|
|
|
|
|
[% indent %][% IF pipe.streams.empty %][% ELSE %](\\ |
|
157
|
|
|
|
|
|
|
[% END %][% cmds %] |
|
158
|
|
|
|
|
|
|
[%- IF pipe.streams.empty %][% ELSE %]\\ |
|
159
|
|
|
|
|
|
|
[% indent %])[% FOREACH stream IN pipe.streams.elements -%] |
|
160
|
|
|
|
|
|
|
[% IF stream.first %]\t[% ELSE %]\\ |
|
161
|
|
|
|
|
|
|
\t[% indent %][% END -%] |
|
162
|
|
|
|
|
|
|
[% color.pipe.stream.spec %][% stream.spec -%] |
|
163
|
|
|
|
|
|
|
[% IF stream.has_file %] [% color.pipe.stream.file %][% stream.quoted_file %][% color.reset %][% END %] |
|
164
|
|
|
|
|
|
|
[%- END -%] |
|
165
|
|
|
|
|
|
|
[%- END -%] |
|
166
|
|
|
|
|
|
|
EOT |
|
167
|
|
|
|
|
|
|
); |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub _colorize { |
|
170
|
|
|
|
|
|
|
|
|
171
|
120
|
|
|
120
|
|
391
|
my ( $tmpl, $colors ) = @_; |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
## no critic (ProhibitAccessOfPrivateData) |
|
174
|
|
|
|
|
|
|
|
|
175
|
120
|
|
|
|
|
412
|
while ( my ( $node, $value ) = each %$tmpl ) { |
|
176
|
|
|
|
|
|
|
|
|
177
|
260
|
100
|
|
|
|
3328
|
if ( ref $value ) { |
|
178
|
|
|
|
|
|
|
|
|
179
|
100
|
|
|
|
|
203
|
$colors->{$node} = {}; |
|
180
|
100
|
|
|
|
|
228
|
_colorize( $value, $colors->{$node} ); |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
else { |
|
185
|
160
|
|
|
|
|
405
|
$colors->{$node} = Term::ANSIColor::color( $value ); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub render { |
|
211
|
|
|
|
|
|
|
|
|
212
|
20
|
|
|
20
|
1
|
2965
|
my $self = shift; |
|
213
|
|
|
|
|
|
|
|
|
214
|
20
|
|
|
|
|
143
|
my ( $args ) = validate( |
|
215
|
|
|
|
|
|
|
\@_, |
|
216
|
|
|
|
|
|
|
slurpy Dict [ |
|
217
|
|
|
|
|
|
|
colorize => Optional [Bool], |
|
218
|
|
|
|
|
|
|
] ); |
|
219
|
|
|
|
|
|
|
|
|
220
|
20
|
|
50
|
|
|
41738
|
$args->{colorize} //= 1; ## no critic (ProhibitAccessOfPrivateData) |
|
221
|
|
|
|
|
|
|
|
|
222
|
20
|
|
|
|
|
2257
|
my %color; |
|
223
|
20
|
|
|
|
|
601
|
_colorize( $self->colors, \%color ); |
|
224
|
|
|
|
|
|
|
|
|
225
|
20
|
50
|
|
|
|
468
|
$color{reset} = Term::ANSIColor::color( 'reset' ) |
|
226
|
|
|
|
|
|
|
if keys %color; |
|
227
|
|
|
|
|
|
|
|
|
228
|
20
|
|
|
|
|
386
|
local $Text::Tabs::tabstop = 2; |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# generate non-colorized version so can get length of records to |
|
231
|
|
|
|
|
|
|
# pad out any continuation lines |
|
232
|
20
|
|
|
|
|
37
|
my @output; |
|
233
|
20
|
|
|
|
|
477
|
$self->_render_pipe( $self->pipe, { indent => '' }, \@output); |
|
234
|
|
|
|
|
|
|
|
|
235
|
20
|
|
|
|
|
89
|
my @records = map { expand( $_ ) } map { split( /\n/, $_ ) } @output; |
|
|
77
|
|
|
|
|
2000
|
|
|
|
20
|
|
|
|
|
102
|
|
|
236
|
20
|
|
|
|
|
617
|
my @lengths = map { length } @records; |
|
|
77
|
|
|
|
|
148
|
|
|
237
|
20
|
|
|
|
|
119
|
my $max = List::Util::max( @lengths ) + 4; |
|
238
|
|
|
|
|
|
|
|
|
239
|
20
|
50
|
|
|
|
87
|
if ( $args->{colorize} ) { |
|
240
|
0
|
|
|
|
|
0
|
@output = (); |
|
241
|
0
|
|
|
|
|
0
|
$self->_render_pipe( $self->pipe, { indent => '', color => \%color }, \@output); |
|
242
|
0
|
|
|
|
|
0
|
@records = map { expand( $_ ) } map { split( /\n/, $_ ) } @output; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
|
|
245
|
20
|
|
|
|
|
59
|
foreach ( @records ) { |
|
246
|
77
|
|
|
|
|
184
|
my $pad = ' ' x ($max - shift @lengths); |
|
247
|
77
|
|
|
|
|
348
|
s/\\$/$pad \\/; |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
20
|
|
|
|
|
347
|
return join ("\n", @records ) . "\n"; |
|
251
|
|
|
|
|
|
|
} |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub _render_pipe { |
|
254
|
|
|
|
|
|
|
|
|
255
|
22
|
|
|
22
|
|
240
|
my $self = shift; |
|
256
|
|
|
|
|
|
|
|
|
257
|
22
|
|
|
|
|
65
|
my ( $pipe, $process_args, $output ) = @_; |
|
258
|
|
|
|
|
|
|
|
|
259
|
22
|
|
|
|
|
44
|
my %process_args = %{$process_args}; |
|
|
22
|
|
|
|
|
94
|
|
|
260
|
|
|
|
|
|
|
|
|
261
|
22
|
|
|
|
|
50
|
my @output; |
|
262
|
|
|
|
|
|
|
|
|
263
|
22
|
|
|
|
|
43
|
for my $cmd ( @{ $pipe->cmds->elements } ) { |
|
|
22
|
|
|
|
|
137
|
|
|
264
|
30
|
100
|
|
|
|
820
|
if ( $cmd->isa( 'IPC::PrettyPipe' ) ) { |
|
265
|
2
|
|
|
|
|
10
|
local $process_args{indent} = $process_args{indent} . "\t"; |
|
266
|
2
|
|
|
|
|
14
|
$self->_render_pipe( $cmd, \%process_args, \@output ); |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
else { |
|
269
|
28
|
|
|
|
|
105
|
local $process_args{indent} = $process_args{indent} . "\t"; |
|
270
|
28
|
|
|
|
|
65
|
push @output, ''; |
|
271
|
28
|
|
|
|
|
79
|
local $process_args{cmd} = $cmd; |
|
272
|
28
|
|
|
|
|
145
|
Template::Tiny->new->process( \$self->cmd_template, \%process_args, |
|
273
|
|
|
|
|
|
|
\( $output[-1] ) ); |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
} |
|
276
|
|
|
|
|
|
|
|
|
277
|
22
|
|
|
|
|
1703
|
$process_args{cmds} = join( "\\\n|", @output ); |
|
278
|
22
|
|
|
|
|
63
|
$process_args{pipe} = $pipe; |
|
279
|
22
|
|
|
|
|
42
|
push @{$output}, ''; |
|
|
22
|
|
|
|
|
65
|
|
|
280
|
22
|
|
|
|
|
92
|
Template::Tiny->new->process( \$self->pipe_template, \%process_args, |
|
281
|
|
|
|
|
|
|
\( $output->[-1] ) ); |
|
282
|
22
|
|
|
|
|
2033
|
return; |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
with 'IPC::PrettyPipe::Renderer'; |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
1; |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# |
|
291
|
|
|
|
|
|
|
# This file is part of IPC-PrettyPipe |
|
292
|
|
|
|
|
|
|
# |
|
293
|
|
|
|
|
|
|
# This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. |
|
294
|
|
|
|
|
|
|
# |
|
295
|
|
|
|
|
|
|
# This is free software, licensed under: |
|
296
|
|
|
|
|
|
|
# |
|
297
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
|
298
|
|
|
|
|
|
|
# |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
__END__ |