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 CC 12 SCAR 13.1
CC
12
Cov
88%
stream_from_proto
7.8
__ANON__
5.0
wrap_with_filter
2.0
CRAP 3.7
« Zoom/ReadFH.pm ↑ Summary Zoom/MappedStream.pm »
1 package HTML::Zoom::StreamUtils;
2  
3 13 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use base qw(HTML::Zoom::SubObject);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use HTML::Zoom::CodeStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use HTML::Zoom::FilterStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use HTML::Zoom::ArrayStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 134 ▶sub stream_from_code {
Subroutine stream_from_code: called CC=1 SCAR=0.0
Pod undocumented
12 134 my ($self, $code) = @_;
13 134 HTML::Zoom::CodeStream->new({
14 code => $code,
15 zconfig => $self->_zconfig,
16 })
17 }
18  
19 404 ▶sub stream_from_array {
Subroutine stream_from_array: called CC=1 SCAR=0.0
Pod undocumented
20 404 my $self = shift;
21 404 my @array = @_;
22 404 HTML::Zoom::ArrayStream->new({
23 array => \@array,
24 zconfig => $self->_zconfig,
25 })
26 }
27  
28 134 ▶sub stream_concat {
Subroutine stream_concat: called CC=1 SCAR=0.0
Pod undocumented
29 134 shift->stream_from_array(@_)->flatten;
30 }
31  
32 151 ▶sub stream_from_proto {
Subroutine stream_from_proto: called CC=7 SCAR=20.5
Pod undocumented
33 151 my ($self, $proto) = @_;
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 0 ▶sub wrap_with_filter {
Subroutine wrap_with_filter: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my ($self, $stream, $match, $filter) = @_;
55 0 HTML::Zoom::FilterStream->new({
56 stream => $stream,
57 match => $match,
58 filter => $filter,
59 zconfig => $self->_zconfig,
60 })
61 }
62  
63 85 ▶sub stream_to_array {
Subroutine stream_to_array: called CC=2 SCAR=6.9
Pod undocumented
64 85 my $stream = $_[1];
65 85 my @array;
66 85 ▶ while (my ($evt) = $stream->next) { push @array, $evt }
Branch: 1 branch
BranchTrueFalseTotal
if (my($evt) = $stream->next) 1187 85 1272
67 85 return @array;
68 }
69  
70 18 ▶sub flatten_stream_of_streams {
Subroutine flatten_stream_of_streams: called CC=1 SCAR=0.0
Pod undocumented
71 18 my ($self, $source_stream) = @_;
72 18 my $cur_stream;
73 HTML::Zoom::CodeStream->new({
74 306 ▶ code => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
75 306 ▶ return unless $source_stream;
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 13 1;
« Zoom/ReadFH.pm ↑ Summary Zoom/MappedStream.pm »