line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Zoom::StreamUtils; |
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
85
|
use strictures 1; |
|
14
|
|
|
|
|
108
|
|
|
14
|
|
|
|
|
403
|
|
4
|
14
|
|
|
14
|
|
1124
|
use base qw(HTML::Zoom::SubObject); |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
1227
|
|
5
|
14
|
|
|
14
|
|
83
|
use Scalar::Util (); |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
259
|
|
6
|
|
|
|
|
|
|
|
7
|
14
|
|
|
14
|
|
3772
|
use HTML::Zoom::CodeStream; |
|
14
|
|
|
|
|
35
|
|
|
14
|
|
|
|
|
382
|
|
8
|
14
|
|
|
14
|
|
83
|
use HTML::Zoom::FilterStream; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
376
|
|
9
|
14
|
|
|
14
|
|
8964
|
use HTML::Zoom::ArrayStream; |
|
14
|
|
|
|
|
43
|
|
|
14
|
|
|
|
|
9919
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub stream_from_code { |
12
|
134
|
|
|
134
|
0
|
207
|
my ($self, $code) = @_; |
13
|
134
|
|
|
|
|
373
|
HTML::Zoom::CodeStream->new({ |
14
|
|
|
|
|
|
|
code => $code, |
15
|
|
|
|
|
|
|
zconfig => $self->_zconfig, |
16
|
|
|
|
|
|
|
}) |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub stream_from_array { |
20
|
405
|
|
|
405
|
0
|
533
|
my $self = shift; |
21
|
405
|
|
|
|
|
2324
|
my @array = @_; |
22
|
405
|
|
|
|
|
1446
|
HTML::Zoom::ArrayStream->new({ |
23
|
|
|
|
|
|
|
array => \@array, |
24
|
|
|
|
|
|
|
zconfig => $self->_zconfig, |
25
|
|
|
|
|
|
|
}) |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub stream_concat { |
29
|
134
|
|
|
134
|
0
|
292
|
shift->stream_from_array(@_)->flatten; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub stream_from_proto { |
33
|
151
|
|
|
151
|
0
|
232
|
my ($self, $proto) = @_; |
34
|
151
|
|
|
|
|
245
|
my $ref = ref $proto; |
35
|
151
|
100
|
33
|
|
|
407
|
if (not $ref) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
36
|
98
|
|
|
|
|
299
|
return $self->stream_from_array({ |
37
|
|
|
|
|
|
|
type => 'TEXT', |
38
|
|
|
|
|
|
|
raw => $self->_zconfig->parser->html_escape($proto) |
39
|
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
} elsif ($ref eq 'ARRAY') { |
41
|
28
|
|
|
|
|
74
|
return $self->stream_from_array(@$proto); |
42
|
|
|
|
|
|
|
} elsif ($ref eq 'CODE') { |
43
|
24
|
|
|
|
|
69
|
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
|
|
|
|
|
9
|
my $stream = $proto->to_stream; |
48
|
1
|
|
|
13
|
|
8
|
return $self->stream_from_code(sub { $stream->next }); |
|
13
|
|
|
|
|
32
|
|
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
|
86
|
|
|
86
|
0
|
140
|
my $stream = $_[1]; |
65
|
86
|
|
|
|
|
106
|
my @array; |
66
|
86
|
|
|
|
|
362
|
while (my ($evt) = $stream->next) { push @array, $evt } |
|
1188
|
|
|
|
|
4198
|
|
67
|
86
|
|
|
|
|
630
|
return @array; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub flatten_stream_of_streams { |
71
|
18
|
|
|
18
|
0
|
35
|
my ($self, $source_stream) = @_; |
72
|
18
|
|
|
|
|
26
|
my $cur_stream; |
73
|
|
|
|
|
|
|
HTML::Zoom::CodeStream->new({ |
74
|
|
|
|
|
|
|
code => sub { |
75
|
306
|
50
|
|
306
|
|
665
|
return unless $source_stream; |
76
|
306
|
|
|
|
|
307
|
my $next; |
77
|
306
|
100
|
|
|
|
990
|
until (($next) = ($cur_stream ? $cur_stream->next : ())) { |
78
|
62
|
100
|
|
|
|
198
|
unless (($cur_stream) = $source_stream->next) { |
79
|
18
|
|
|
|
|
31
|
undef $source_stream; return; |
|
18
|
|
|
|
|
177
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
288
|
|
|
|
|
1235
|
return $next; |
83
|
|
|
|
|
|
|
} |
84
|
18
|
|
|
|
|
172
|
}); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |