Transactional/Stream.pm

filter: Statementstmt 100% 59 / 59 Branchbran 100% 22 / 22 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 95.0% 96 / 101 CC 14 SCAR 21.4
CC
14
Cov
98%
next
13.0
is_done
2.0
BEGIN
1.0
CRAP 8.5
↑ Summary Transactional.pm »
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
!ll&&!rl&&r
066
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (@$stack) 18 16 34
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)])
l!l&&r!l&&!r
8100
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)])
ABresult
1X1
011
000
87  
88 18 ▶ while ( defined(my $path = shift @$children) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $path = shift @$children)) 18 10 28
89 18 ▶ if ( $m->is_dir($path) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->is_dir($path)) { } 4 14 18
90 4 ▶ if ( $depth_first ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth_first) { } 2 2 4
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
BranchTrueFalseTotal
if @ret >= $chunk_size 4 10 14
100 }
101 }
102  
103 # we're done reading this dir
104 10 pop @$stack;
105 }
106  
107 20 ▶ if ( @$queue ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$queue) 10 10 20
108 10 my $dir = shift @$queue;
109  
110 10 ▶ if ( $depth_first ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth_first) { } 5 5 10
111 5 push @$stack, [ $dir ],
112 } else {
113 5 unshift @$stack, [ $dir ],
114 }
115  
116 10 ▶ unless ( $only_files ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($only_files) 4 6 10
117 4 ▶ push @ret, $dir if length $dir;
Branch: 1 branch
BranchTrueFalseTotal
if length $dir 2 2 4
118 4 ▶ return \@ret if @ret >= $chunk_size;
Branch: 1 branch
BranchTrueFalseTotal
if @ret >= $chunk_size 2 2 4
119 }
120  
121 8 redo;
122 }
123 }
124  
125 10 ▶ return unless @ret;
Branch: 1 branch
BranchTrueFalseTotal
unless @ret 6 4 10
126 4 return \@ret;
127 }
128  
129  
130 2 __PACKAGE__->meta->make_immutable;
131  
132 2 __PACKAGE__
133  
134 __END__
↑ Summary Transactional.pm »