Bulk/Array.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 8 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 5 / 5 totaltotal 100% 62 / 62 CC 7 SCAR 11.9
CC
7
Cov
100%
list_cat
6.0
next
2.0
BEGIN
1.0
CRAP 3.3
« Bulk/Path/Class.pm ↑ Summary Bulk/DBIC.pm »
1 package Data::Stream::Bulk::Array;
2 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 $Data::Stream::Bulk::Array::AUTHORITY = 'cpan:NUFFIN';
4 }
5 {
6 3 $Data::Stream::Bulk::Array::VERSION = '0.11';
7 }
8 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # ABSTRACT: L<Data::Stream::Bulk> wrapper for simple arrays.
10  
11 3 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 with qw(Data::Stream::Bulk) => { -excludes => [qw/loaded filter list_cat/] };
14  
15 3 has array => (
16 isa => "ArrayRef",
17 reader => "_array",
18 writer => "_set_array",
19 clearer => "_clear_array",
20 predicate => "_has_array",
21 required => 1,
22 );
23  
24 6 ▶sub is_done {
Subroutine is_done: called CC=1 SCAR=0.0
Pod documented
25 6 my $self = shift;
26 6 !$self->_has_array;
27 }
28  
29 22 ▶sub next {
Subroutine next: called CC=2 SCAR=6.9
Pod documented
30 22 my $self = shift;
31  
32 22 ▶ if ( my $array = $self->_array ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $array = $self->_array) { } 13 9 22
33 13 $self->_clear_array;
34 13 return $array;
35 } else {
36 9 return;
37 }
38 }
39  
40 # squish several arrays into one
41 20 ▶sub list_cat {
Subroutine list_cat: called CC=6 SCAR=17.9
Pod documented
42 20 my ( $self, @rest ) = @_;
43  
44 20 ▶ return $self unless @rest;
Branch: 1 branch
BranchTrueFalseTotal
unless @rest 8 12 20
45  
46 12 my @arrays = ( $self );
47  
48 # fetch all adjacent arrays
49 12 ▶ push @arrays, shift @rest while @rest and $rest[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
@rest and $rest[0]->isa(__PACKAGE__) and do { push @arrays, shift @rest } 3 12 15
Condition100%3/3
@rest and $rest[0]->isa(__PACKAGE__)
!ll&&!rl&&r
393
MC/DC100%2/2
@rest and $rest[0]->isa(__PACKAGE__)
@rest $rest[0]->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= @restB= $rest[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
50  
51 12 ▶ if ( @arrays > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arrays > 1) { } 3 9 12
52 3 my @cat;
53 3 push @cat, @$_ for map { $_->_array } @arrays;
54 3 return __PACKAGE__->new(
55 array => \@cat,
56 )->cat( @rest );
57 } else {
58 9 my $head = shift @rest;
59 9 return ( $self, $head->list_cat(@rest) );
60 }
61 }
62  
63 2 ▶sub filter {
Subroutine filter: called CC=1 SCAR=0.0
Pod documented
64 2 my ( $self, $filter ) = @_;
65 2 local $_ = $self->next;
66 2 $self->_set_array( $filter->($_) );
67 2 return $self;
68 }
69  
70 1 ▶sub loaded { 1 }
Subroutine loaded: called CC=1 SCAR=0.0
Pod documented
71  
72 3 __PACKAGE__->meta->make_immutable;
73  
74 3 __PACKAGE__;
75  
76  
77  
78 =pod
79  
80 =head1 NAME
81  
82 Data::Stream::Bulk::Array - L<Data::Stream::Bulk> wrapper for simple arrays.
83  
84 =head1 VERSION
85  
86 version 0.11
87  
88 =head1 SYNOPSIS
89  
90 return Data::Stream::Bulk::Array->new(
91 array => \@results,
92 );
93  
94 =head1 DESCRIPTION
95  
96 This implementation of the L<Data::Stream::Bulk> api wraps an array.
97  
98 The use case is to keep the consumer of the data set implementation agnostic so
99 that it can deal with larger data sets if they are encountered, but still
100 retain most of the simplicity when the current data set easily fits in memory.
101  
102 =head1 ATTRIBUTES
103  
104 =over 4
105  
106 =item array
107  
108 The array reference to wrap.
109  
110 =back
111  
112 =head1 METHODS
113  
114 =over 4
115  
116 =item next
117  
118 Returns the array reference on the first invocation, and nothing thereafter.
119  
120 =item is_done
121  
122 Returns true if C<next> has been called.
123  
124 =item list_cat
125  
126 Squishes adjacent arrays into a new array.
127  
128 =item filter $filter
129  
130 Immediately applies C<$filter> to the internal array and returns C<$self>.
131  
132 =item loaded
133  
134 Returns true
135  
136 =back
137  
138 =head1 AUTHOR
139  
140 Yuval Kogman <nothingmuch@woobling.org>
141  
142 =head1 COPYRIGHT AND LICENSE
143  
144 This software is copyright (c) 2012 by Yuval Kogman.
145  
146 This is free software; you can redistribute it and/or modify it under
147 the same terms as the Perl 5 programming language system itself.
148  
149 =cut
150  
151  
152 __END__
« Bulk/Path/Class.pm ↑ Summary Bulk/DBIC.pm »