line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Zoom::StreamUtils; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
77
|
use strictures 1; |
|
13
|
|
|
|
|
89
|
|
|
13
|
|
|
|
|
362
|
|
4
|
13
|
|
|
13
|
|
1315
|
use base qw(HTML::Zoom::SubObject); |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
1391
|
|
5
|
13
|
|
|
13
|
|
78
|
use Scalar::Util (); |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
217
|
|
6
|
|
|
|
|
|
|
|
7
|
13
|
|
|
13
|
|
1669
|
use HTML::Zoom::CodeStream; |
|
13
|
|
|
|
|
32
|
|
|
13
|
|
|
|
|
309
|
|
8
|
13
|
|
|
13
|
|
89
|
use HTML::Zoom::FilterStream; |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
332
|
|
9
|
13
|
|
|
13
|
|
8637
|
use HTML::Zoom::ArrayStream; |
|
13
|
|
|
|
|
105
|
|
|
13
|
|
|
|
|
8174
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub stream_from_code { |
12
|
130
|
|
|
130
|
0
|
225
|
my ($self, $code) = @_; |
13
|
130
|
|
|
|
|
374
|
HTML::Zoom::CodeStream->new({ |
14
|
|
|
|
|
|
|
code => $code, |
15
|
|
|
|
|
|
|
zconfig => $self->_zconfig, |
16
|
|
|
|
|
|
|
}) |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub stream_from_array { |
20
|
386
|
|
|
386
|
0
|
509
|
my $self = shift; |
21
|
386
|
|
|
|
|
845
|
my @array = @_; |
22
|
386
|
|
|
|
|
1293
|
HTML::Zoom::ArrayStream->new({ |
23
|
|
|
|
|
|
|
array => \@array, |
24
|
|
|
|
|
|
|
zconfig => $self->_zconfig, |
25
|
|
|
|
|
|
|
}) |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub stream_concat { |
29
|
130
|
|
|
130
|
0
|
283
|
shift->stream_from_array(@_)->flatten; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub stream_from_proto { |
33
|
149
|
|
|
149
|
0
|
241
|
my ($self, $proto) = @_; |
34
|
149
|
|
|
|
|
296
|
my $ref = ref $proto; |
35
|
149
|
100
|
33
|
|
|
544
|
if (not $ref) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
36
|
96
|
|
|
|
|
321
|
return $self->stream_from_array({ |
37
|
|
|
|
|
|
|
type => 'TEXT', |
38
|
|
|
|
|
|
|
raw => $self->_zconfig->parser->html_escape($proto) |
39
|
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
} elsif ($ref eq 'ARRAY') { |
41
|
28
|
|
|
|
|
89
|
return $self->stream_from_array(@$proto); |
42
|
|
|
|
|
|
|
} elsif ($ref eq 'CODE') { |
43
|
24
|
|
|
|
|
78
|
return $proto->(); |
44
|
|
|
|
|
|
|
} elsif ($ref eq 'SCALAR') { |
45
|
0
|
|
|
|
|
0
|
return $self->_zconfig->parser->html_to_stream($$proto); |
46
|
|
|
|
|
|
|
} elsif (Scalar::Util::blessed($proto) && $proto->can('to_stream')) { |
47
|
1
|
|
|
|
|
6
|
my $stream = $proto->to_stream; |
48
|
1
|
|
|
13
|
|
7
|
return $self->stream_from_code(sub { $stream->next }); |
|
13
|
|
|
|
|
37
|
|
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
die "Don't know how to turn $proto (ref $ref) into a stream"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub wrap_with_filter { |
54
|
0
|
|
|
0
|
0
|
0
|
my ($self, $stream, $match, $filter) = @_; |
55
|
0
|
|
|
|
|
0
|
HTML::Zoom::FilterStream->new({ |
56
|
|
|
|
|
|
|
stream => $stream, |
57
|
|
|
|
|
|
|
match => $match, |
58
|
|
|
|
|
|
|
filter => $filter, |
59
|
|
|
|
|
|
|
zconfig => $self->_zconfig, |
60
|
|
|
|
|
|
|
}) |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub stream_to_array { |
64
|
75
|
|
|
75
|
0
|
109
|
my $stream = $_[1]; |
65
|
75
|
|
|
|
|
162
|
my @array; |
66
|
75
|
|
|
|
|
321
|
while (my ($evt) = $stream->next) { push @array, $evt } |
|
1047
|
|
|
|
|
4323
|
|
67
|
75
|
|
|
|
|
700
|
return @array; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub flatten_stream_of_streams { |
71
|
18
|
|
|
18
|
0
|
43
|
my ($self, $source_stream) = @_; |
72
|
18
|
|
|
|
|
26
|
my $cur_stream; |
73
|
|
|
|
|
|
|
HTML::Zoom::CodeStream->new({ |
74
|
|
|
|
|
|
|
code => sub { |
75
|
306
|
50
|
|
306
|
|
842
|
return unless $source_stream; |
76
|
306
|
|
|
|
|
346
|
my $next; |
77
|
306
|
100
|
|
|
|
1016
|
until (($next) = ($cur_stream ? $cur_stream->next : ())) { |
78
|
62
|
100
|
|
|
|
201
|
unless (($cur_stream) = $source_stream->next) { |
79
|
18
|
|
|
|
|
31
|
undef $source_stream; return; |
|
18
|
|
|
|
|
172
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
288
|
|
|
|
|
1188
|
return $next; |
83
|
|
|
|
|
|
|
} |
84
|
18
|
|
|
|
|
191
|
}); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |