blib/lib/Langertha/Stream.pm

filter: Statementstmt 57.7% 41 / 71 Branchbran 45.0% 9 / 20 Conditioncond 33.3% 2 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 56.2% 9 / 16 Podpod 100% 14 / 14 totaltotal 58.0% 76 / 131 CC 15 SCAR 12.9
CC
15
Cov
54%
citations
6.6
citations
6.6
each
4.6
CRAP 3.6
« blib/lib/Langertha/Role/HermesTools.pm ↑ Summary blib/lib/Langertha/Role/KeepAlive.pm »
1 package Langertha::Stream;
2 # ABSTRACT: Iterator for streaming responses
3 194 our $VERSION = '0.505';
4 194 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 194 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 194 has chunks => (
9 is => 'ro',
10 isa => 'ArrayRef[Langertha::Stream::Chunk]',
11 required => 1,
12 );
13  
14  
15 194 has _position => (
16 is => 'rw',
17 isa => 'Int',
18 default => 0,
19 );
20  
21 19 ▶sub next {
Subroutine next: called CC=2 SCAR=9.2
Pod documented
22 0 ▶ my ($self) = @_;
Subroutine next: not called CC=2 SCAR=9.2
Pod documented
23 0 my $pos = $self->_position;
24 0 ▶ return undef if $pos >= scalar @{$self->chunks};
Branch: 2 branches
BranchTrueFalseTotal
if $pos >= scalar @{$self->chunks;} 4 15 19
if $pos >= scalar @{$self->chunks;} 0 0 0
25 0 $self->_position($pos + 1);
26 0 return $self->chunks->[$pos];
27 }
28  
29  
30 5 ▶sub has_next {
Subroutine has_next: called CC=1 SCAR=1.2
Pod documented
31 0 ▶ my ($self) = @_;
Subroutine has_next: not called CC=1 SCAR=1.2
Pod documented
32 0 return $self->_position < scalar @{$self->chunks};
33 }
34  
35  
36 1 ▶sub collect {
Subroutine collect: called CC=2 SCAR=9.2
Pod documented
37 0 ▶ my ($self) = @_;
Subroutine collect: not called CC=2 SCAR=9.2
Pod documented
38 0 my @remaining;
39 0 ▶ while (my $chunk = $self->next) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $chunk = $self->next) 3 1 4
if (my $chunk = $self->next) 0 0 0
40 0 push @remaining, $chunk;
41 }
42 0 return @remaining;
43 }
44  
45  
46 1 ▶sub content {
Subroutine content: called CC=1 SCAR=1.2
Pod documented
47 0 ▶ my ($self) = @_;
Subroutine content: not called CC=1 SCAR=1.2
Pod documented
48 0 return join('', map { $_->content } @{$self->chunks});
49 }
50  
51  
52 2 ▶sub citations {
Subroutine citations: called CC=4 SCAR=18.9
Pod documented
53 0 ▶ my ($self) = @_;
Subroutine citations: not called CC=4 SCAR=18.9
Pod documented
54 0 for my $chunk (@{$self->chunks}) {
55 0 ▶ return $chunk->citations if eval { $chunk->has_citations } && $chunk->citations;
Branch: 2 branches
BranchTrueFalseTotal
if eval { do { $chunk->has_citations } } and $chunk->citations 1 3 4
if eval { do { $chunk->has_citations } } and $chunk->citations 0 0 0
Condition33%2/6
eval { do { $chunk->has_citations } } and $chunk->citations
!ll&&!rl&&r
301
eval { do { $chunk->has_citations } } and $chunk->citations
!ll&&!rl&&r
000
MC/DC50%1/2
eval { do { $chunk->has_citations } } and $chunk->citations
eval { do { $chunk->has_citations } } $chunk->citations
MC/DC0%0/2
eval { do { $chunk->has_citations } } and $chunk->citations
eval { do { $chunk->has_citations } } $chunk->citations
Truth table66%2/3
A and B
A= eval { do { $chunk->has_citations } }B= $chunk->citations
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= eval { do { $chunk->has_citations } }B= $chunk->citations
ABresult
0X0
100
111
56 }
57 0 return undef;
58 }
59  
60  
61 1 ▶sub each {
Subroutine each: called CC=3 SCAR=15.3
Pod documented
62 0 ▶ my ($self, $callback) = @_;
Subroutine each: not called CC=3 SCAR=15.3
Pod documented
63 0 ▶ croak "each() requires a callback" unless ref $callback eq 'CODE';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $callback eq "CODE" 0 1 1
unless ref $callback eq "CODE" 0 0 0
64 0 ▶ while (my $chunk = $self->next) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $chunk = $self->next) 3 1 4
if (my $chunk = $self->next) 0 0 0
65 0 $callback->($chunk);
66 }
67 }
68  
69  
70 2 ▶sub reset {
Subroutine reset: called CC=1 SCAR=1.2
Pod documented
71 0 ▶ my ($self) = @_;
Subroutine reset: not called CC=1 SCAR=1.2
Pod documented
72 0 $self->_position(0);
73 }
74  
75  
76  
77 194 __PACKAGE__->meta->make_immutable;
78  
79 194 1;
80  
81 __END__
« blib/lib/Langertha/Role/HermesTools.pm ↑ Summary blib/lib/Langertha/Role/KeepAlive.pm »