| 1 | package Directory::Scanner::StreamBuilder::Application; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Apply function to streaming directory iterator | ||||||||||||||||||||||||||||
| 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_APPLICATION_DEBUG} // 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{"DIR_SCANNER_STREAM_APPLICATION_DEBUG"} // 0
MC/DC0%0/1
$ENV{"DIR_SCANNER_STREAM_APPLICATION_DEBUG"} // 0
$ENV{"DIR_SCANNER_STREAM_APPLICATION_DEBUG"}
Truth table50%1/2
A
A= $ENV{"DIR_SCANNER_STREAM_APPLICATION_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 | ▶ | stream => sub {}, | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | ▶ | function => sub {}, | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | ) | ||||||||||||||||||||||||||||
| 26 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | ## ... | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub BUILD { | ||||||||||||||||||||||||||||
| 31 | 2 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 2 | my $stream = $self->{stream}; | |||||||||||||||||||||||||||
| 33 | 2 | my $f = $self->{function}; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | (Scalar::Util::blessed($stream) && $stream->DOES('Directory::Scanner::API::Stream')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($stream) and $stream->DOES("Directory::Scanner::API::Stream")
MC/DC0%0/2
builtin::blessed($stream) and $stream->DOES("Directory::Scanner::API::Stream")
builtin::blessed($stream)
$stream->DOES("Directory::Scanner::API::Stream")
Truth table33%1/3
A and B
A= builtin::blessed($stream)B= $stream->DOES("Directory::Scanner::API::Stream")
| |||||||||||||||||||||||||||||
| 36 | || Carp::confess 'You must supply a directory stream'; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | (defined $f) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | || Carp::confess 'You must supply a `function` value'; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | (ref $f eq 'CODE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | || Carp::confess 'The `function` value supplied must be a CODE reference'; | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub clone { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my ($self, $dir) = @_; | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | return $self->new( | ||||||||||||||||||||||||||||
| 48 | stream => $self->{stream}->clone( $dir ), | ||||||||||||||||||||||||||||
| 49 | function => $self->{function} | ||||||||||||||||||||||||||||
| 50 | 0 | ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | ## delegate | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 9 | ▶ | sub head { $_[0]->{stream}->head } | ||||||||||||||||||||||||||
|
Subroutine
head: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 4 | ▶ | sub is_done { $_[0]->{stream}->is_done } | ||||||||||||||||||||||||||
|
Subroutine
is_done: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 6 | ▶ | sub is_closed { $_[0]->{stream}->is_closed } | ||||||||||||||||||||||||||
|
Subroutine
is_closed: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 2 | ▶ | sub close { $_[0]->{stream}->close } | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub next { | ||||||||||||||||||||||||||||
| 61 | 12 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 12 | my $next = $self->{stream}->next; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # this means the stream is likely exhausted | ||||||||||||||||||||||||||||
| 65 | 12 | ▶ | return unless defined $next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # apply the function ... | ||||||||||||||||||||||||||||
| 68 | 10 | local $_ = $next; | |||||||||||||||||||||||||||
| 69 | 10 | $self->{function}->( $next ); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # return the next value | ||||||||||||||||||||||||||||
| 72 | 10 | return $next; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 8 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||