| 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 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 1 | ▶ | use 5.014; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 1 | 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 | 1 | 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 | 1 | ▶ | [qw/Header1 Header2 Header3/, ' Header4 '], | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 66 | [qw/Field1 Field2 Field3 Field4 Field5/], | ||||||||||
| 67 | [qw/Field6 Field7 Field8 Field9 Field0/], | ||||||||||
| 68 | ] }, | ||||||||||
| 69 | 1 | 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 | 0 | ▶ | my ($self, $index) = @_; | ||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
| |||||||||||
| 88 | 0 | ▶ | return undef unless $index =~ m/^\d+$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | 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 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
next_record: not called CC=2 SCAR=17.9
| |||||||||||
| 102 | |||||||||||
| 103 | 0 | my $record = $self->retrieve; | |||||||||
| 104 | 0 | ▶ | if (defined $record) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | $self->current( $record ); | |||||||||
| 106 | 0 | return 1; | |||||||||
| 107 | 0 | } 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 | ▶ | sub configure {} | |||||||||
|
Subroutine
configure: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 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 | ▶ | sub finish {} | |||||||||
|
Subroutine
finish: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 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 | 1 | 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 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 154 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||