| 1 | package Directory::Scanner::StreamBuilder::Concat; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Connect streaming directory iterators | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use UNIVERSAL::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Directory::Scanner::API::Stream; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 8 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 14 | 8 | our $AUTHORITY = 'cpan:STEVAN'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use constant DEBUG => $ENV{DIR_SCANNER_STREAM_CONCAT_DEBUG} // 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{"DIR_SCANNER_STREAM_CONCAT_DEBUG"} // 0
MC/DC0%0/1
$ENV{"DIR_SCANNER_STREAM_CONCAT_DEBUG"} // 0
$ENV{"DIR_SCANNER_STREAM_CONCAT_DEBUG"}
Truth table50%1/2
A
A= $ENV{"DIR_SCANNER_STREAM_CONCAT_DEBUG"}
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | ## ... | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 8 | ▶ | our @ISA; BEGIN { @ISA = ('UNIVERSAL::Object', 'Directory::Scanner::API::Stream') } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 8 | our %HAS; BEGIN { | |||||||||||||||||||||||||||
| 22 | %HAS = ( | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | streams => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 24 | # internal state ... | ||||||||||||||||||||||||||||
| 25 | 1 | ▶ | _index => sub { 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | _is_done => sub { 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | _is_closed => sub { 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | ) | ||||||||||||||||||||||||||||
| 29 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | ## ... | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub BUILD { | ||||||||||||||||||||||||||||
| 34 | 1 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=15.8
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 1 | my $streams = $self->{streams}; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | (Scalar::Util::blessed($_) && $_->DOES('Directory::Scanner::API::Stream')) | ||||||||||||||||||||||||||||
| 38 | || Carp::confess 'You must supply all directory stream objects' | ||||||||||||||||||||||||||||
| 39 | 1 | ▶ | foreach @$streams; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($_) and $_->DOES("Directory::Scanner::API::Stream")
MC/DC0%0/2
builtin::blessed($_) and $_->DOES("Directory::Scanner::API::Stream")
builtin::blessed($_)
$_->DOES("Directory::Scanner::API::Stream")
Truth table33%1/3
A and B
A= builtin::blessed($_)B= $_->DOES("Directory::Scanner::API::Stream")
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub clone { | ||||||||||||||||||||||||||||
| 43 | # TODO - this might be possible ... | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | Carp::confess 'Cloning a concat stream is not a good idea, just dont do it'; | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | ## delegate | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub head { | ||||||||||||||||||||||||||||
| 50 | 7 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
head: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 7 | ▶ | return if $self->{_index} > $#{$self->{streams}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 6 | return $self->{streams}->[ $self->{_index} ]->head; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | sub is_done { $_[0]->{_is_done} } | ||||||||||||||||||||||||||
|
Subroutine
is_done: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 3 | ▶ | sub is_closed { $_[0]->{_is_closed} } | ||||||||||||||||||||||||||
|
Subroutine
is_closed: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub close { | ||||||||||||||||||||||||||||
| 59 | 1 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 1 | foreach my $stream ( @{ $self->{streams} } ) { | |||||||||||||||||||||||||||
| 61 | 2 | $stream->close; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 1 | $_[0]->{_is_closed} = 1; | |||||||||||||||||||||||||||
| 64 | return | ||||||||||||||||||||||||||||
| 65 | 1 | } | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub next { | ||||||||||||||||||||||||||||
| 68 | 6 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 6 | ▶ | return if $self->{_is_done}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Carp::confess 'Cannot call `next` on a closed stream' | ||||||||||||||||||||||||||||
| 73 | 6 | ▶ | if $self->{_is_closed}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | my $next; | |||||||||||||||||||||||||||
| 76 | 6 | while (1) { | |||||||||||||||||||||||||||
| 77 | 10 | undef $next; # clear any previous values, just cause ... | |||||||||||||||||||||||||||
| 78 | 10 | $self->_log('Entering loop ... ') if DEBUG; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 10 | ▶ | if ( $self->{_index} > $#{$self->{streams}} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | # end of the streams now ... | ||||||||||||||||||||||||||||
| 82 | 1 | $self->{_is_done} = 1; | |||||||||||||||||||||||||||
| 83 | 1 | last; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 9 | my $current = $self->{streams}->[ $self->{_index} ]; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 9 | ▶ | if ( $current->is_done ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | # if we are done, advance the | ||||||||||||||||||||||||||||
| 90 | # index and restart the loop | ||||||||||||||||||||||||||||
| 91 | 2 | $self->{_index}++; | |||||||||||||||||||||||||||
| 92 | 2 | next; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||
| 95 | 7 | $next = $current->next; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # if next returns nothing, | ||||||||||||||||||||||||||||
| 98 | # then we now done, so | ||||||||||||||||||||||||||||
| 99 | # restart the loop which | ||||||||||||||||||||||||||||
| 100 | # will trigger the ->is_done | ||||||||||||||||||||||||||||
| 101 | # block above and DWIM | ||||||||||||||||||||||||||||
| 102 | 7 | ▶ | next unless defined $next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 5 | $self->_log('Exiting loop ... ') if DEBUG; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # if we have gotten to this | ||||||||||||||||||||||||||||
| 107 | # point, we have a value and | ||||||||||||||||||||||||||||
| 108 | # want to return it | ||||||||||||||||||||||||||||
| 109 | 5 | last; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 6 | return $next; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 8 | 1; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||