File Coverage

blib/lib/Spreadsheet/Compare/Reporter.pm
Criterion Covered Total %
statement 44 84 52.3
branch 6 10 60.0
condition 2 3 66.6
subroutine 8 15 53.3
pod 11 11 100.0
total 71 123 57.7


line stmt bran cond sub pod time code
1             package Spreadsheet::Compare::Reporter;
2              
3 4     4   3263 use Mojo::Base -base, -signatures;
  4         16  
  4         57  
4 4     4   1771 use Spreadsheet::Compare::Common;
  4         15  
  4         94  
5              
6             #<<<
7             use Spreadsheet::Compare::Config {
8             rootdir => '.',
9 20         74 ( map { $_ => undef } qw(
10             report_filename
11             report_line_numbers
12             report_line_source
13             report_max_columns
14             report_ignored_columns
15             )),
16 4         26 ( map { $_ => sub { croak 'attribute "$_" not implemented by subclass'; } } qw(
  60         412  
  0         0  
17             fmt_head
18             fmt_headerr
19             fmt_default
20             fmt_left_odd
21             fmt_right_odd
22             fmt_diff_odd
23             fmt_left_even
24             fmt_right_even
25             fmt_diff_even
26             fmt_left_high
27             fmt_right_high
28             fmt_diff_high
29             fmt_left_low
30             fmt_right_low
31             fmt_diff_low
32             )),
33 4     4   47 }, make_attributes => 1;
  4         12  
34             #>>>
35              
36             #<<<
37             # attributes set by after_reader_setup
38             has [qw(ign record_header header test_title)] => undef, ro => 1;
39             has stat_head => sub { [qw/title left right same diff miss add dup limit link/] }, ro => 1;
40             has max_hdr => sub { $_[0]->report_max_columns ? [qw/ABS_FIELD ABS_VALUE REL_FIELD REL_VALUE/] : []; }, ro => 1;
41             has sln_hdr => sub { $_[0]->report_line_numbers ? [qw/__SLN__/] : []; }, ro => 1;
42             has src_hdr => sub { $_[0]->report_line_source ? [qw/__SRC__/] : [] }, ro => 1;
43             has head_offset => sub { $_[0]->src_hdr->@* + $_[0]->sln_hdr->@* + $_[0]->max_hdr->@* }, ro => 1;
44             #>>>
45              
46              
47 5366     5366 1 12456 sub output_record ( $self, $robj ) {
  5366         10541  
  5366         8728  
  5366         8589  
48 5366 50       22251 my @src = $self->report_line_source ? $robj->side_name : ();
49 5366 50       44064 my @sln = $self->report_line_numbers ? $robj->sln : ();
50 5366         36144 my @max = $robj->diff_info->@{ $self->max_hdr->@* };
51 5366         59499 my $rec = $self->strip_ignore( $robj->rec );
52 5366         83302 return [ @src, @sln, @max, @$rec ];
53             }
54              
55 10710     10710 1 53349 sub strip_ignore ( $self, $aref ) {
  10710         16165  
  10710         17157  
  10710         14863  
56 10710         28629 my $ign = $self->ign;
57 10710 100       78413 return [ map { $ign->{$_} ? () : $aref->[$_] } 0 .. $#$aref ];
  732671         1564009  
58             }
59              
60 7     7   17 sub _after_reader_setup ( $self, $look ) { ## no critic (ProhibitUnusedPrivateSubroutines)
  7         12  
  7         27  
  7         13  
61 7 50       30 $self->{__ro__ign} = $self->report_ignored_columns ? {} : $look->{ign};
62 7         76 $self->{__ro__record_header} = $self->strip_ignore( $look->{hdr} );
63 7         63 $self->{__ro__header} = [ $self->src_hdr->@*, $self->sln_hdr->@*, $self->max_hdr->@*, $self->record_header->@* ];
64 7         76 return $self;
65             }
66              
67 25     25 1 66 sub report_fullname ( $self, $fn = undef ) {
  25         72  
  25         63  
  25         49  
68 25   66     173 $fn //= $self->report_filename;
69 25         340 my $pfn = path($fn);
70 25 50       1555 return $pfn if $pfn->is_absolute;
71 0         0 return path( $self->rootdir, $fn );
72             }
73              
74             # Methods that must/should be overridden by subclasses
75              
76 7     7 1 21 sub setup ($self) { }
  7         19  
77              
78 0     0 1   sub add_stream ( $self, $name ) {
  0            
  0            
  0            
79 0           croak 'method "add_stream" not implemented by subclass';
80             }
81              
82 0     0 1   sub write_row ( $self, $name, $robj ) {
  0            
  0            
  0            
  0            
83 0           croak 'method "write_row" not implemented by subclass';
84             }
85              
86 0     0 1   sub write_fmt_row ( $self, $name, $robj ) {
  0            
  0            
  0            
  0            
87 0           croak 'method "write_fmt_row" not implemented by subclass';
88             }
89              
90 0     0 1   sub write_header ( $self, $name ) {
  0            
  0            
  0            
91 0           croak 'method "write_header" not implemented by subclass';
92             }
93              
94 0     0 1   sub mark_header ( $self, $name, $mask ) {
  0            
  0            
  0            
  0            
95 0           croak 'method "mark_header" not implemented by subclass';
96             }
97              
98 0     0 1   sub write_summary ( $self, $stats, $filename ) {
  0            
  0            
  0            
  0            
99 0           croak 'method "write_summary" not implemented by subclass';
100             }
101              
102 0     0 1   sub save_and_close ($self) {
  0            
  0            
103 0           croak 'method "save_and_close" not implemented by subclass';
104             }
105              
106              
107             1;
108              
109             =head1 NAME
110              
111             Spreadsheet::Compare::Reporter - Abstract Base Class for Reporters
112              
113             =head1 DESCRIPTION
114              
115             This module defines the methods and attributes that are provided for or need to be overrridden
116             by a Spreadsheet::Compare::Reporter subclass.
117              
118             When subclassing consider using L<Spreadsheet::Compare::Common> for convenience.
119              
120             =head1 ATTRIBUTES
121              
122             All read write attributes can be set as options from the config file passed to L<Spreadsheet::Compare>
123             or L<spreadcomp>.
124              
125             The defaults for the C<fmt_*> attributes are specific to the Reporter subclass and are documented there.
126              
127             =head2 fmt_head
128              
129             The format for the header line.
130              
131             =head2 fmt_headerr
132              
133             The format for marking headers of columns that contain differences.
134              
135             =head2 fmt_default
136              
137             The default format for a single cell.
138              
139             =head2 fmt_left_odd
140              
141             The default format for a cell on the left side of the comparison with an odd line index.
142              
143             =head2 fmt_right_odd
144              
145             The default format for a cell on the right side of the comparison with an odd line index.
146              
147             =head2 fmt_diff_odd
148              
149             The default format for a cell of the differences line with an odd line index.
150             (only with L</report_diff_row>)
151              
152             =head2 fmt_left_even
153              
154             The default format for a cell on the left side of the comparison with an even line index.
155              
156             =head2 fmt_right_even
157              
158             The default format for a cell on the right side of the comparison with an even line index.
159              
160             =head2 fmt_diff_even
161              
162             The default format for a cell of the differences line with an even line index.
163             (only with L</report_diff_row>)
164              
165             =head2 fmt_left_high
166              
167             Format set on the left side when a difference was detected and at least one limit was exceeded.
168              
169             =head2 fmt_right_high
170              
171             Format set on the right side when a difference was detected and at least one limit was exceeded.
172              
173             =head2 fmt_diff_high
174              
175             Format set in the differences line when a difference was detected and at least one limit was exceeded.
176             (only with L</report_diff_row>)
177              
178             =head2 fmt_left_low
179              
180             Format set on the left side when a difference was detected and all deviations are below their limits.
181              
182             =head2 fmt_right_low
183              
184             Format set on the right side when a difference was detected and all deviations are below their limits.
185              
186             =head2 fmt_diff_low
187              
188             Format sset in the differences line when a difference was detected and all deviations are below their limits.
189             (only with L</report_diff_row>)
190              
191             =head2 report_diff_row
192              
193             possible values: 0|1
194             default: 0
195              
196             Add a row with the absolute (or relative if L<<Spreadsheet::Compare::Single/diff_relative>> is used ) differences
197             after each pair of data lines in the diff output.
198              
199             =head2 report_filename
200              
201             possible values: <string>
202             default: undef
203              
204             The output filename for the generated report. This will be prepended with the directory
205             set with the L<Spreadsheet::Compare/rootdir> option unless it is an absolute filename.
206              
207             =head2 report_ignored_columns
208              
209             possible values: 0|1
210             default: 0
211              
212             Per default ignored columns will not be written to reports. Setting this option will include
213             them. They will be marked as 'IGNORED' when L</report_diff_row> is set.
214              
215             =head2 report_line_numbers
216              
217             possible values: 0|1
218             default: 0
219              
220             Add a column named '__SLN__' to the report output containing the record's line number
221             in the source file should the Reader module provide it.
222              
223             =head2 report_line_source
224              
225             possible values: 0|1
226             default: 0
227              
228             Add a column named __SRC__ specifying the source name in the diff output. The
229             names set by the options "left" and "right" will be used. For diff lines it will be 'diff'.
230              
231             =head2 report_max_columns
232              
233             possible values: 0|1
234             default: 1
235              
236             Add the columns ABS_FIELD, ABS_VALUE, REL_FIELD and REL_VALUE to the diff output.
237             They indicate the field names and maximal differences for absolute and
238             relative deviations for a line comparison.
239              
240             =head2 rootdir
241              
242             Set by L<Spreadsheet::Compare> during reporter initialisation.
243             Same as L<Spreadsheet::Compare/rootdir>.
244              
245             =head2 stat_head
246              
247             B<readonly>) A reference to an array with the column headers for statistics information
248              
249             =head2 test_title
250              
251             B<readonly>) A copy of L<Spreadsheet::Compare::Single/title>
252              
253             =head1 METHODS
254              
255             The methods marked as B<event handler> have to implemented by subclasses to handle events
256             emitted by L<Spreadsheet::Compare::Single> (see L<Spreadsheet::Compare::Single/EVENTS>
257             for descriptions of the event parameters).
258              
259             =head2 add_stream($name)
260              
261             (B<event handler>)
262              
263             =head2 mark_header($stream, $mask)
264              
265             (B<event handler>)
266              
267             =head2 output_record ($record_obj)
268              
269             Return a reference to an array with all valid output values for a record according to the
270             current reporting attributes (e.g. L</report_ignored_colums>, L</report_max_columns>, ...)
271              
272             =head2 report_fullname([$fn])
273              
274             Return the full report filename by combining L</rootdir> and $fn (defaults to L</report_filename>).
275             Will just return the filename if it is absolute.
276              
277             =head2 save_and_close()
278              
279             Will be called by L<Spreadsheet::Compare> after a comparison has finished and the report_finished
280             event was emitted. The Reporter can safely close the report.
281              
282             =head2 setup
283              
284             Will be called by L<Spreadsheet::Compare> before starting a comparison. Does not need
285             to be implemented by subclasses.
286              
287             =head2 strip_ignore ($record_aref)
288              
289             Remove ignored columns from the referenced array. The array has to be the same
290             length as a source record.
291              
292             =head2 write_header($stream)
293              
294             (B<event handler>)
295              
296             =head2 write_row($stream, $record_obj)
297              
298             (B<event handler>)
299              
300             =head2 write_fmt_row($stream, $record_obj)
301              
302             (B<event handler>)
303              
304             =head2 write_summary($stats, $filename)
305              
306             Will be called by L<Spreadsheet::Compare> after completion of all comparisons when
307             L<Spreadsheet::Compare/summary> is set.
308              
309             =cut