File Coverage

blib/lib/ETL/Pipeline/Output/UnitTest.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             =pod
2              
3             =head1 NAME
4              
5             ETL::Pipeline::Output::UnitTest - Output destination 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::Output::UnitTest> is an output destination used by the unit
19             tests. It proves that the L<ETL::Pipeline::Output> role works.
20              
21             The "data" is stored in memory.
22              
23             =cut
24              
25             package ETL::Pipeline::Output::UnitTest;
26 7     7   25 use Moose;
  7         10  
  7         43  
27              
28 7     7   30429 use Carp;
  7         11  
  7         429  
29 7     7   26 use String::Util qw/hascontent/;
  7         7  
  7         1107  
30              
31              
32             our $VERSION = '2.00';
33              
34              
35             =head1 METHODS & ATTRIBUTES
36              
37             =head3 records
38              
39             In B<ETL::Pipeline::Output::UnitTest>, a record is a hash reference.
40             B<records> stores a list of record (hash references). The list survives after
41             calling L</finish>. This allows you to check the results of a test after
42             calling L<ETL::Pipeline/process>.
43              
44             The list is cleared after calling L</configure>.
45              
46             =head3 all_records
47              
48             The B<all_records> method returns a list of all the records. It dereferences
49             L</records>.
50              
51             =head3 number_of_records
52              
53             The B<number_of_records> method returns the count of records currently in the
54             list.
55              
56             =cut
57              
58             has 'records' => (
59             default => sub { [] },
60             handles => {
61             all_records => 'elements',
62             _reset => 'clear',
63             get_record => 'get',
64             number_of_records => 'count',
65             _save_current_record => 'push',
66             },
67             is => 'ro',
68             isa => 'ArrayRef[HashRef[Any]]',
69             traits => [qw/Array/],
70             );
71              
72              
73             =head2 Called from L<ETL::Pipeline/process>
74              
75             =head3 write_record
76              
77             Saves the current record into L</records>.
78              
79             =cut
80              
81             sub write_record {
82             my $self = shift;
83            
84             $self->_save_current_record( $self->current );
85             return 1;
86             }
87              
88              
89             =head3 configure
90              
91             B<configure> doesn't actually do anything. But it is required by
92             L<ETL::Pipeline/process>.
93              
94             =cut
95              
96             sub configure { }
97              
98              
99             =head3 finish
100              
101             B<finish> doesn't actually do anything. But it is required by
102             L<ETL::Pipeline/process>. L</records> persists so that the unit test can check
103             its values.
104              
105             =cut
106              
107       5 1   sub finish {}
108              
109              
110             =head2 Other methods & attributes
111              
112             =head3 default_fields
113              
114             Initialize L</current> for the next record.
115              
116             =cut
117              
118 19     19 1 33 sub default_fields { () }
119              
120              
121             =head1 SEE ALSO
122              
123             L<ETL::Pipeline>, L<ETL::Pipeline::Output>,
124             L<ETL::Pipeline::Output::Storage::Hash>, L<ETL::Pipeline::Input::UnitTest>
125              
126             =cut
127              
128             with 'ETL::Pipeline::Output::Storage::Hash';
129             with 'ETL::Pipeline::Output';
130              
131              
132             =head1 AUTHOR
133              
134             Robert Wohlfarth <robert.j.wohlfarth@vanderbilt.edu>
135              
136             =head1 LICENSE
137              
138             Copyright 2016 (c) Vanderbilt University
139              
140             This program is free software; you can redistribute it and/or modify it under
141             the same terms as Perl itself.
142              
143             =cut
144              
145 7     7   28 no Moose;
  7         9  
  7         28  
146             __PACKAGE__->meta->make_immutable;