| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package Directory::Transactional::Stream; | ||||||||||||||||||||
| 4 | 2 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | $Directory::Transactional::Stream::VERSION = '0.09'; | |||||||||||||||||||
| 6 | } | ||||||||||||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | with qw(Data::Stream::Bulk); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | has manager => ( | |||||||||||||||||||
| 16 | isa => "Directory::Transactional", | ||||||||||||||||||||
| 17 | is => "ro", | ||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 2 | has dir => ( | |||||||||||||||||||
| 22 | isa => "Str", | ||||||||||||||||||||
| 23 | is => "ro", | ||||||||||||||||||||
| 24 | default => "", | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 2 | has depth_first => ( | |||||||||||||||||||
| 28 | isa => "Bool", | ||||||||||||||||||||
| 29 | is => "rw", | ||||||||||||||||||||
| 30 | default => 1, | ||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 2 | has only_files => ( | |||||||||||||||||||
| 34 | isa => "Bool", | ||||||||||||||||||||
| 35 | is => "ro", | ||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | has chunk_size => ( | |||||||||||||||||||
| 39 | isa => "Int", | ||||||||||||||||||||
| 40 | is => "rw", | ||||||||||||||||||||
| 41 | default => 250, | ||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | has _stack => ( | ||||||||||||||||||||
| 45 | isa => "ArrayRef", | ||||||||||||||||||||
| 46 | is => "ro", | ||||||||||||||||||||
| 47 | 6 | ▶ | default => sub { [] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 48 | 2 | ); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | has _queue => ( | ||||||||||||||||||||
| 51 | isa => "ArrayRef", | ||||||||||||||||||||
| 52 | is => "ro", | ||||||||||||||||||||
| 53 | lazy => 1, | ||||||||||||||||||||
| 54 | 6 | ▶ | default => sub { [ shift->dir ] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 2 | ); | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 12 | ▶ | sub is_done { | ||||||||||||||||||
|
Subroutine
is_done: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 58 | 12 | my $self = shift; | |||||||||||||||||||
| 59 | return ( | ||||||||||||||||||||
| 60 | 12 | @{ $self->_stack } == 0 | |||||||||||||||||||
| 61 | and | ||||||||||||||||||||
| 62 | 12 | ▶ | @{ $self->_queue } == 0 | ||||||||||||||||||
|
Condition66%2/3
@{$self->_stack;} == 0 && @{$self->_queue;} == 0
MC/DC50%1/2
@{$self->_stack;} == 0 && @{$self->_queue;} == 0
@{$self->_stack;} == 0
@{$self->_queue;} == 0
Truth table66%2/3
A && B
A= @{$self->_stack;} == 0B= @{$self->_queue;} == 0
| |||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 16 | ▶ | sub next { | ||||||||||||||||||
|
Subroutine
next: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||
| 67 | 16 | my $self = shift; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 16 | my $queue = $self->_queue; | |||||||||||||||||||
| 70 | 16 | my $stack = $self->_stack; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 16 | my $depth_first = $self->depth_first; | |||||||||||||||||||
| 73 | 16 | my $only_files = $self->only_files; | |||||||||||||||||||
| 74 | 16 | my $chunk_size = $self->chunk_size; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 16 | my @ret; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 16 | my $m = $self->manager; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | { | ||||||||||||||||||||
| 81 | 16 | ▶ | outer: while ( @$stack ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 18 | my $frame = $stack->[-1]; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 18 | my ( $parent, $children ) = @$frame; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 18 | ▶ | $children ||= ( $frame->[1] = [ $m->list($parent) ] ); | ||||||||||||||||||
|
Condition66%2/3
$children ||= ($frame->[1] = [$m->list($parent)])
MC/DC0%0/2
$children ||= ($frame->[1] = [$m->list($parent)])
$children
($frame->[1] = [$m->list($parent)])
Truth table66%2/3
A ||= B
A= $childrenB= ($frame->[1] = [$m->list($parent)])
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 18 | ▶ | while ( defined(my $path = shift @$children) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 18 | ▶ | if ( $m->is_dir($path) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 4 | ▶ | if ( $depth_first ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 2 | unshift @$queue, $path; | |||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||
| 93 | 2 | push @$queue, $path; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 4 | last outer; | |||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||
| 98 | 14 | push @ret, $path; | |||||||||||||||||||
| 99 | 14 | ▶ | return \@ret if @ret >= $chunk_size; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | # we're done reading this dir | ||||||||||||||||||||
| 104 | 10 | pop @$stack; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 20 | ▶ | if ( @$queue ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 108 | 10 | my $dir = shift @$queue; | |||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 10 | ▶ | if ( $depth_first ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 5 | push @$stack, [ $dir ], | |||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||
| 113 | 5 | unshift @$stack, [ $dir ], | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 10 | ▶ | unless ( $only_files ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 117 | 4 | ▶ | push @ret, $dir if length $dir; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 118 | 4 | ▶ | return \@ret if @ret >= $chunk_size; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 8 | redo; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 10 | ▶ | return unless @ret; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | 4 | return \@ret; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 2 | __PACKAGE__ | |||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||