Zoom/StreamUtils.pm

filter: Statementstmt 92.4% 49 / 53 Branchbran 85.0% 17 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 7 totaltotal 81.0% 81 / 100 SCAR 25.0
CC
12
Cov
88%
stream_from_proto
7.8
__ANON__
5.0
wrap_with_filter
2.0
CRAP 12.2
« Zoom.pm ↑ Summary Zoom/FilterBuilder/Template.pm »
1 package HTML::Zoom::StreamUtils;
2  
3 14 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use base qw(HTML::Zoom::SubObject);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 ▶use HTML::Zoom::CodeStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use HTML::Zoom::FilterStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use HTML::Zoom::ArrayStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub stream_from_code {
12 134 ▶ my ($self, $code) = @_;
Subroutine stream_from_code: called CC=1 SCAR=0.0
Pod undocumented
13 134 HTML::Zoom::CodeStream->new({
14 code => $code,
15 zconfig => $self->_zconfig,
16 })
17 }
18  
19 sub stream_from_array {
20 405 ▶ my $self = shift;
Subroutine stream_from_array: called CC=1 SCAR=0.0
Pod undocumented
21 405 my @array = @_;
22 405 HTML::Zoom::ArrayStream->new({
23 array => \@array,
24 zconfig => $self->_zconfig,
25 })
26 }
27  
28 sub stream_concat {
29 134 ▶ shift->stream_from_array(@_)->flatten;
Subroutine stream_concat: called CC=1 SCAR=0.0
Pod undocumented
30 }
31  
32 sub stream_from_proto {
33 151 ▶ my ($self, $proto) = @_;
Subroutine stream_from_proto: called CC=7 SCAR=20.5
Pod undocumented
34 151 my $ref = ref $proto;
35 151 ▶ if (not $ref) {
Branch: 5 branches
BranchTrueFalseTotal
if (not $ref) { } 98 53 151
elsif ($ref eq 'ARRAY') { } 28 25 53
elsif ($ref eq 'CODE') { } 24 1 25
elsif ($ref eq 'SCALAR') { } 0 1 1
elsif (builtin::blessed($proto) and $proto->can('to_stream')) { } 1 0 1
36 98 return $self->stream_from_array({
37 type => 'TEXT',
38 raw => $self->_zconfig->parser->html_escape($proto)
39 });
40 } elsif ($ref eq 'ARRAY') {
41 28 return $self->stream_from_array(@$proto);
42 } elsif ($ref eq 'CODE') {
43 24 return $proto->();
44 } elsif ($ref eq 'SCALAR') {
45 0 return $self->_zconfig->parser->html_to_stream($$proto);
46 ▶ } elsif (Scalar::Util::blessed($proto) && $proto->can('to_stream')) {
Condition33%1/3
builtin::blessed($proto) and $proto->can("to_stream")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($proto) and $proto->can("to_stream")
builtin::blessed($proto) $proto->can("to_stream")
Truth table33%1/3
A and B
A= builtin::blessed($proto)B= $proto->can("to_stream")
ABresult
0X0
100
111
47 1 my $stream = $proto->to_stream;
48 1 ▶ return $self->stream_from_code(sub { $stream->next });
Subroutine __ANON__: called CC=1 SCAR=0.0
49 }
50 0 die "Don't know how to turn $proto (ref $ref) into a stream";
51 }
52  
53 sub wrap_with_filter {
54 0 ▶ my ($self, $stream, $match, $filter) = @_;
Subroutine wrap_with_filter: not called CC=1 SCAR=6.9
Pod undocumented
55 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 ▶ my $stream = $_[1];
Subroutine stream_to_array: called CC=2 SCAR=6.9
Pod undocumented
65 86 my @array;
66 86 ▶ while (my ($evt) = $stream->next) { push @array, $evt }
Branch: 1 branch
BranchTrueFalseTotal
if (my($evt) = $stream->next) 1188 86 1274
67 86 return @array;
68 }
69  
70 sub flatten_stream_of_streams {
71 18 ▶ my ($self, $source_stream) = @_;
Subroutine flatten_stream_of_streams: called CC=1 SCAR=0.0
Pod undocumented
72 18 my $cur_stream;
73 HTML::Zoom::CodeStream->new({
74 code => sub {
75 306 ▶ return unless $source_stream;
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
unless $source_stream 0 306 306
76 306 my $next;
77 306 ▶ until (($next) = ($cur_stream ? $cur_stream->next : ())) {
Branch: 2 branches
BranchTrueFalseTotal
unless (($next) = $cur_stream ? $cur_stream->next : ()) 62 288 350
$cur_stream ? : 332 18 350
78 62 ▶ unless (($cur_stream) = $source_stream->next) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($cur_stream) = $source_stream->next) 18 44 62
79 18 undef $source_stream; return;
80 }
81 }
82 288 return $next;
83 }
84 18 });
85 }
86  
87 14 1;
« Zoom.pm ↑ Summary Zoom/FilterBuilder/Template.pm »