| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
eval {
do {
$chunk->has_citations
}
} and $chunk->citations
eval {
do {
$chunk->has_citations
}
} and $chunk->citations
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
Truth table0%0/3
A and B
A= eval {
do {
$chunk->has_citations
}
}B= $chunk->citations
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | while (my $chunk = $self->next) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||