line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=pod |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
ETL::Pipeline::Input::UnitTest - Input source for unit tests |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use ETL::Pipeline; |
10
|
|
|
|
|
|
|
ETL::Pipeline->new( { |
11
|
|
|
|
|
|
|
input => ['UnitTest'], |
12
|
|
|
|
|
|
|
mapping => {First => 'Header1', Second => 'Header2'}, |
13
|
|
|
|
|
|
|
output => ['UnitTest'] |
14
|
|
|
|
|
|
|
} )->process; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
B<ETL::Pipeline::Input::UnitTest> is an input source used by the unit tests. |
19
|
|
|
|
|
|
|
It proves that the L<ETL::Pipeline::Input> role works. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
The "data" is hard coded. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package ETL::Pipeline::Input::UnitTest; |
26
|
3
|
|
|
3
|
|
5276
|
use Moose; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
18
|
|
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
|
12868
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
52
|
|
29
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
72
|
|
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
3
|
|
61
|
use 5.014; |
|
3
|
|
|
|
|
6
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our $VERSION = '2.00'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS & ATTRIBUTES |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head3 current |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This array reference holds the current record. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'current' => ( |
46
|
|
|
|
|
|
|
handles => { |
47
|
|
|
|
|
|
|
fields => 'elements', |
48
|
|
|
|
|
|
|
_get_value => 'get', |
49
|
|
|
|
|
|
|
number_of_fields => 'count', |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
is => 'rw', |
52
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
53
|
|
|
|
|
|
|
traits => [qw/Array/], |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head3 data |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The real input source. This is the data returned by L</next_record>. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has 'data' => ( |
64
|
|
|
|
|
|
|
default => sub { [ |
65
|
|
|
|
|
|
|
[qw/Header1 Header2 Header3/, ' Header4 '], |
66
|
|
|
|
|
|
|
[qw/Field1 Field2 Field3 Field4 Field5/], |
67
|
|
|
|
|
|
|
[qw/Field6 Field7 Field8 Field9 Field0/], |
68
|
|
|
|
|
|
|
] }, |
69
|
|
|
|
|
|
|
handles => {retrieve => 'shift'}, |
70
|
|
|
|
|
|
|
is => 'ro', |
71
|
|
|
|
|
|
|
isa => 'ArrayRef[ArrayRef[Str]]', |
72
|
|
|
|
|
|
|
traits => [qw/Array/], |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 Called from L<ETL::Pipeline/process> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head3 get |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
B<get> retrieves one field from the record. Pass an index number as the field |
81
|
|
|
|
|
|
|
name. The test data has 4 header fields and 5 values in each data row. |
82
|
|
|
|
|
|
|
Remember that index numbers start at zero. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get { |
87
|
|
|
|
|
|
|
my ($self, $index) = @_; |
88
|
|
|
|
|
|
|
return undef unless $index =~ m/^\d+$/; |
89
|
|
|
|
|
|
|
return $self->_get_value( $index ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head3 next_record |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
B<ETL::Pipeline::Input::UnitTest> returns 3 records by cycling through |
96
|
|
|
|
|
|
|
L</data>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub next_record { |
101
|
|
|
|
|
|
|
my $self = shift; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $record = $self->retrieve; |
104
|
|
|
|
|
|
|
if (defined $record) { |
105
|
|
|
|
|
|
|
$self->current( $record ); |
106
|
|
|
|
|
|
|
return 1; |
107
|
|
|
|
|
|
|
} else { return 0; } |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head3 configure |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
B<configure> doesn't actually do anything. But it is required by |
114
|
|
|
|
|
|
|
L<ETL::Pipeline/process>. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
10
|
1
|
|
sub configure {} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head3 finish |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
B<finish> doesn't actually do anything. But it is required by |
124
|
|
|
|
|
|
|
L<ETL::Pipeline/process>. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
9
|
1
|
|
sub finish {} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SEE ALSO |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<ETL::Pipeline>, L<ETL::Pipeline::Input>, L<ETL::Pipeline::Output::UnitTest> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
with 'ETL::Pipeline::Input'; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Robert Wohlfarth <robert.j.wohlfarth@vanderbilt.edu> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 LICENSE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Copyright 2016 (c) Vanderbilt University |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
149
|
|
|
|
|
|
|
the same terms as Perl itself. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
3
|
|
|
3
|
|
16
|
no Moose; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
12
|
|
154
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |