line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Pipeline::Adapter::Array; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
38420
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
extends 'Data::Pipeline::Adapter'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Data::Pipeline::Iterator::Source; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Data::Pipeline::Types qw(Iterator); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use MooseX::Types::Moose qw(ArrayRef CodeRef GlobRef); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has array => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'ArrayRef|Data::Pipeline::Types::Iterator|CodeRef', |
15
|
|
|
|
|
|
|
default => sub { [ ] }, |
16
|
|
|
|
|
|
|
lazy => 1 |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has '+source' => ( |
20
|
|
|
|
|
|
|
lazy => 1, |
21
|
|
|
|
|
|
|
coerce => 1, |
22
|
|
|
|
|
|
|
default => sub { |
23
|
|
|
|
|
|
|
my($self) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $i = 0; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#print STDERR "Array source\n"; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if( is_ArrayRef($self -> array) ) { |
30
|
|
|
|
|
|
|
Data::Pipeline::Iterator::Source -> new( |
31
|
|
|
|
|
|
|
get_next => sub { ($i <= $#{$self -> array}) ? $self -> array -> [$i++] : undef }, |
32
|
|
|
|
|
|
|
has_next => sub { $i <= $#{$self -> array} } |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
|
|
|
|
|
|
### TODO: fix this so CodeRefs are genericly handled |
37
|
|
|
|
|
|
|
my $it = $self -> array; |
38
|
|
|
|
|
|
|
if(is_CodeRef( $it )) { |
39
|
|
|
|
|
|
|
$it = $it -> (); |
40
|
|
|
|
|
|
|
Carp::carp "Code does not return an iterator"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
to_Iterator($it) -> source; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
override serialize => sub { |
48
|
|
|
|
|
|
|
my($self, $iterator, $target) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if(is_ArrayRef($target)) { |
51
|
|
|
|
|
|
|
@{$target} = ( ); |
52
|
|
|
|
|
|
|
push @{$target}, $iterator -> next until $iterator -> finished; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif(is_GlobRef($target)) { |
55
|
|
|
|
|
|
|
print $target $iterator->next until $iterator -> finished; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
|
|
|
|
|
|
local($Carp::CarpLevel) = 1; |
59
|
|
|
|
|
|
|
Carp::croak "Array serialization only works with an array reference target"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |