File Coverage

lib/Spreadsheet/Reader/ExcelXML/Row.pm
Criterion Covered Total %
statement 54 54 100.0
branch 12 14 85.7
condition n/a
subroutine 13 13 100.0
pod 3 3 100.0
total 82 84 97.6


line stmt bran cond sub pod time code
1             package Spreadsheet::Reader::ExcelXML::Row;
2             our $AUTHORITY = 'cpan:JANDREW';
3 19     19   76 use version; our $VERSION = version->declare('v0.16.8');
  19         27  
  19         105  
4             ###LogSD warn "You uncovered internal logging statements for Spreadsheet::Reader::ExcelXML::Row-$VERSION";
5              
6             $| = 1;
7 19     19   1776 use 5.010;
  19         52  
8 19     19   74 use Moose;
  19         22  
  19         112  
9 19     19   81525 use MooseX::StrictConstructor;
  19         34  
  19         136  
10 19     19   37469 use MooseX::HasDefaults::RO;
  19         30  
  19         156  
11 19     19   59930 use Carp qw( confess );
  19         33  
  19         940  
12 19     19   79 use Clone qw( clone );
  19         24  
  19         742  
13 19     19   75 use Types::Standard qw( ArrayRef Int Bool HashRef );
  19         27  
  19         137  
14 19     19   11597 use lib '../../../../../lib';
  19         30  
  19         124  
15             ###LogSD use Log::Shiras::Telephone;
16              
17             ###LogSD with 'Log::Shiras::LogSpace';
18             ###LogSD sub get_class_space{ 'Row' }
19              
20             #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
21              
22             has row_number =>(
23             isa => Int,
24             reader => 'get_row_number',
25             required => 1,
26             );
27              
28             has row_span =>(
29             isa => ArrayRef[ Int ],
30             traits => ['Array'],
31             writer => 'set_row_span',
32             predicate => 'has_row_span',
33             required => 1,
34             handles =>{
35             get_row_start => [ 'get' => 0 ],
36             get_row_end => [ 'get' => 1 ],
37             },
38             );
39              
40             has row_last_value_column =>(
41             isa => Int,
42             reader => 'get_last_value_column',
43             );
44              
45             has row_formats =>(
46             isa => HashRef,
47             traits => ['Hash'],
48             writer => 'set_row_formts',
49             handles =>{
50             get_row_format => 'get',
51             },
52             );
53              
54             has column_to_cell_translations =>(
55             isa => ArrayRef,
56             traits =>[ 'Array' ],
57             handles =>{
58             get_position_for_column => 'get',
59             },
60             );
61              
62             has row_value_cells =>(
63             isa => ArrayRef,
64             traits =>[ 'Array' ],
65             reader => 'get_row_value_cells',
66             handles =>{
67             get_cell_position => 'get',
68             total_cell_positions => 'count',
69             },
70             );
71              
72             #########1 Public Methods 3#########4#########5#########6#########7#########8#########9
73              
74             sub get_the_column{
75 295     295 1 1902 my ( $self, $desired_column ) = @_;
76 295 50       517 confess "Desired column required" if !defined $desired_column;
77             ###LogSD my $phone = Log::Shiras::Telephone->new( name_space =>
78             ###LogSD ($self->get_all_space . '::get_the_column' ), );
79             ###LogSD $phone->talk( level => 'debug', message =>[
80             ###LogSD "Getting the cell value at column: $desired_column", ] );
81 295         7331 my $max_column = $self->get_row_end;
82 295 100       523 if( $desired_column > $max_column ){
83             ###LogSD $phone->talk( level => 'debug', message =>[
84             ###LogSD "Requested column -$desired_column- is past the end of the row", ] );
85 13         37 return 'EOR';
86             }
87 282         7967 my $value_position = $self->get_position_for_column( $desired_column );
88 282 100       552 if( !defined $value_position ){
89             ###LogSD $phone->talk( level => 'debug', message =>[
90             ###LogSD "No cell value stored for column: $desired_column",
91             ###LogSD "..against final column: " . $self->get_row_end,
92             ###LogSD "..and last data column: " . $self->get_last_value_column ] );
93 92 100       2138 my $return =
    50          
94             $desired_column > $self->get_row_end ? 'EOR' :
95             $desired_column > $self->get_last_value_column ? 'EOD' : undef;
96 92         239 return $return;
97             }
98 190         5039 my $return_cell = $self->get_cell_position( $value_position );
99             ###LogSD $phone->talk( level => 'warn', message =>[
100             ###LogSD "Returning the cell position: $value_position", $return_cell, ] );
101 190         4601 $self->_set_reported_position( $value_position );
102 190         2674 return clone( $return_cell );
103             }
104              
105             sub get_the_next_value_position{
106 101     101 1 1018 my ( $self, ) = @_;
107             ###LogSD my $phone = Log::Shiras::Telephone->new( name_space =>
108             ###LogSD ($self->get_all_space . '::get_the_next_value_column' ), );
109             ###LogSD $phone->talk( level => 'debug', message =>[
110             ###LogSD "Returning the next value position in this row as available", ] );
111 101 100       2787 my $next_position = defined $self->_get_reported_position ? ($self->_get_reported_position + 1) : 0;
112             ###LogSD $phone->talk( level => 'debug', message =>[
113             ###LogSD "Searching for position: $next_position" ] );
114 101 100       2892 if( $next_position == $self->total_cell_positions ){# Counting from zero vs counting from 1
115             ###LogSD $phone->talk( level => 'debug', message =>[
116             ###LogSD "Already reported the last value position" ] );
117 28         78 return 'EOR';
118             }
119 73         2082 my $return_cell = $self->get_cell_position( $next_position );
120 73         1983 $self->_set_reported_position( $next_position );
121             #~ $self->_set_reported_column( $return_cell->{cell_col} );
122             #~ $self->_set_reported_position( $next_position );
123             ###LogSD $phone->talk( level => 'debug', message =>[
124             ###LogSD "Returning the cell:", $return_cell, ] );
125 73         1191 return clone( $return_cell );
126             }
127              
128             sub get_row_all{
129 111     111 1 916 my ( $self, ) = @_;
130             ###LogSD my $phone = Log::Shiras::Telephone->new( name_space =>
131             ###LogSD ($self->get_all_space . '::get_row_all' ), );
132             ###LogSD $phone->talk( level => 'debug', message =>[
133             ###LogSD "Getting an array ref of all the cells in the row by column position - counting from 0", ] );
134              
135 111         138 my $return_ref;
136 111         108 for my $cell ( @{$self->get_row_value_cells} ){
  111         2713  
137 354         3836 $return_ref->[$cell->{cell_col} - 1] = clone $cell;
138             }
139             ###LogSD $phone->talk( level => 'debug', message =>[
140             ###LogSD "Returning the row ref:", $return_ref, ] );
141 111         259 return $return_ref;
142             }
143              
144             #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9
145              
146             has _reported_position =>(
147             isa => Int,
148             reader => '_get_reported_position',
149             writer => '_set_reported_position',
150             );
151              
152             #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
153              
154              
155              
156             #########1 Phinish 3#########4#########5#########6#########7#########8#########9
157              
158 19     19   9274 no Moose;
  19         41  
  19         98  
159             __PACKAGE__->meta->make_immutable;
160              
161             1;
162              
163             #########1 Documentation 3#########4#########5#########6#########7#########8#########9
164             __END__
165              
166             =head1 NAME
167              
168             Spreadsheet::Reader::ExcelXML::Row - ExcelXML Row data class
169              
170             =head1 DESCRIPTION
171              
172             This documentation is written to explain ways to use this module when writing your own excel
173             parser. To use the general package for excel parsing out of the box please review the
174             documentation for L<Workbooks|Spreadsheet::Reader::ExcelXML>,
175             L<Worksheets|Spreadsheet::Reader::ExcelXML::Worksheet>, and
176             L<Cells|Spreadsheet::Reader::ExcelXML::Cell>
177              
178             This module provides the basic storage and manipulation of row data (for worksheet files).
179             It does not provide the final view of a given cell. The final view of the cell is collated
180             with the role (Interface) L<Spreadsheet::Reader::ExcelXML::Worksheet>.
181              
182             I<All positions (row and column places) at this level are stored and returned in count
183             from one mode!>
184              
185             Modification of this module probably means a rework of the Worksheet level module since
186             it L<requires|Spreadsheet::Reader::ExcelXML::Worksheet/requires> several methods from
187             this role. A Row instance is generally built and populated by
188             L<Spreadsheet::Reader::ExcelXML::WorksheetToRow>.
189              
190             =head2 Attributes
191              
192             Data passed to new when creating an instance. For access to the values in these
193             attributes see the listed 'attribute methods'. For general information on attributes see
194             L<Moose::Manual::Attributes>. For ways to manage the instance when opened see the
195             L<Methods|/Methods>.
196              
197             =head3 row_number
198              
199             =over
200              
201             B<Definition:> Stores the row number of the row data in count from 1
202              
203             B<Range:> positive integers > 0
204              
205             B<Required:> yes
206              
207             B<attribute methods> Methods provided to adjust this attribute
208              
209             =over
210              
211             B<get_row_number>
212              
213             =over
214              
215             B<Definition:> return the attribute value
216              
217             =back
218              
219             =back
220              
221             =back
222              
223             =head3 row_span
224              
225             =over
226              
227             B<Definition:> Stores an array ref of two integers representing the
228             start and end columns in count from 1 numbering
229              
230             B<Range:> [ 2 positive integers > 0 ]
231              
232             B<attribute methods> Methods provided to adjust this attribute
233              
234             =over
235              
236             B<set_row_span>
237              
238             =over
239              
240             B<Definition:> sets the attribute
241              
242             =back
243              
244             B<has_row_span>
245              
246             =over
247              
248             B<Definition:> predicate for the attribute
249              
250             =back
251              
252             B<L<Delegated|Moose::Manual::Delegation/NATIVE DELEGATION> methods:>
253             Methods delegated from the instance for conversion type checking.
254             The name delegated to is listed next to a link for the default
255             method delegated from. Where the method is L<curried
256             |Moose::Manual::Delegation/CURRYING> that is shown as well.
257              
258             =over
259              
260             B<get_row_start> => [ L<Moose::Meta::Attribute::Native::Trait::Array/get> => 0 ], # Get the first position
261              
262             B<get_row_end> => [ L<Moose::Meta::Attribute::Native::Trait::Array/get> => 1 ], # Get the second position
263              
264             =back
265              
266             =back
267              
268             =back
269              
270             =head3 row_last_value_column
271              
272             =over
273              
274             B<Definition:> Stores the last column with a value in it in count from 1
275              
276             B<Range:> positive integers > 0
277              
278             B<attribute methods> Methods provided to adjust this attribute
279              
280             =over
281              
282             B<get_last_value_column>
283              
284             =over
285              
286             B<Definition:> return the attribute value
287              
288             =back
289              
290             =back
291              
292             =back
293              
294             =head3 row_formats
295              
296             =over
297              
298             B<Definition:> this is an open ended hashref with format values stored for the row
299              
300             B<Range:> a hash ref
301              
302             B<attribute methods> Methods provided to adjust this attribute
303              
304             =over
305              
306             B<set_row_formats>
307              
308             =over
309              
310             B<Definition:> sets the whole attribute
311              
312             =back
313              
314             B<L<Delegated|Moose::Manual::Delegation/NATIVE DELEGATION> methods:>
315             Methods delegated from the instance for conversion type checking.
316             The name delegated to is listed next to a link for the default
317             method delegated from.
318              
319             =over
320              
321             B<get_row_format> => L<Moose::Meta::Attribute::Native::Trait::Array/get>
322              
323             =back
324              
325             =back
326              
327             =back
328              
329             =head3 row_value_cells
330              
331             =over
332              
333             B<Definition:> Stores an array ref of information about cells with values
334             for that row (in order). The purpose of only storing the values is to allow
335             for 'next_value' calls. The actual position of the cell column is stored in
336             the cell hash and the attribute L<column_to_cell_translations|/column_to_cell_translations>.
337              
338             B<Range:> ArrayRef[HashRef]
339              
340             B<attribute methods> Methods provided to adjust this attribute
341              
342             =over
343              
344             B<get_row_value_cells>
345              
346             =over
347              
348             B<Definition:> gets the whole stored attribute
349              
350             =back
351              
352             B<L<Delegated|Moose::Manual::Delegation/NATIVE DELEGATION> methods:>
353             Methods delegated from the instance for conversion type checking.
354             The name delegated to is listed next to a link for the default
355             method delegated from.
356              
357             =over
358              
359             B<get_cell_position> => L<Moose::Meta::Attribute::Native::Trait::Array/get>
360              
361             B<total_cell_positions> => L<Moose::Meta::Attribute::Native::Trait::Array/count>
362              
363             =back
364              
365             =back
366              
367             =back
368              
369             =head3 column_to_cell_translations
370              
371             =over
372              
373             B<Definition:> only cells with values are stored but you may want to
374             know if a cell has a value based on a column number or you may want to
375             know where the contents of a cell containing values are base on a column
376             number. This attribute stores that lookup table.
377              
378             B<Default:> an ArrayRef with at least one column position set
379              
380             B<L<Delegated|Moose::Manual::Delegation/NATIVE DELEGATION> methods:>
381             Methods delegated from the instance for conversion type checking.
382             The name delegated to is listed next to a link for the default
383             method delegated from.
384              
385             =over
386              
387             B<get_position_for_column> => L<Moose::Meta::Attribute::Native::Trait::Array/get>
388              
389             =back
390              
391             =back
392              
393             =head2 Methods
394              
395             These are the methods provided by this class for use within the package but are not intended
396             to be used by the package end user. Other private methods not listed here are used in the
397             module but not used by the package. If the method is listed here then replacement
398             of this module either requires replacing them or rewriting all the associated connecting
399             roles and classes. I<All methods here are assumed to be in count from 1 mode to since the
400             role instances are meant to be managed in the background for the worksheet.>
401              
402             =head3 get_the_column( $column )
403              
404             =over
405              
406             B<Definition:> This returns the value stored at the desired column position. It also stores
407             this position as the last column retrieved for any 'next_*' calls.
408              
409             B<Accepts:> $column (integer)
410              
411             B<Returns:> a hashref of cell values at that column, undef for no values, or 'EOR' for positions
412             past the end of the row.
413              
414             =back
415              
416             =head3 get_the_next_value_position
417              
418             =over
419              
420             B<Definition:> This returns the next set of cell values or 'EOR' for positions
421             past the end of the row. When a set of cell values is returned (not EOR) the new 'last'
422             position is recorded.
423              
424             B<Accepts:> nothing
425              
426             B<Returns:> a hashref of key value pairs or 'EOR'
427              
428             =back
429              
430             =head3 get_row_all
431              
432             =over
433              
434             B<Definition:> This is a way to get an array of hashrefs that are positioned correctly
435             B<in count from zero> locations for the row data. Just value cells can be returned
436             with L<get_row_value_cells|/get_row_value_cells>. For cells with no value undef
437             is stored. For cells past the last value even if they fall inside the row span no
438             positions are created.
439              
440             B<Accepts:> nothing
441              
442             B<Returns:> an arrayref of hashrefs
443              
444             =back
445              
446             =head1 SUPPORT
447              
448             =over
449              
450             L<github Spreadsheet::Reader::ExcelXML/issues
451             |https://github.com/jandrew/p5-spreadsheet-reader-excelxml/issues>
452              
453             =back
454              
455             =head1 TODO
456              
457             =over
458              
459             B<1.> Nothing L<yet|/SUPPORT>
460              
461             =back
462              
463             =head1 AUTHOR
464              
465             =over
466              
467             =item Jed Lund
468              
469             =item jandrew@cpan.org
470              
471             =back
472              
473             =head1 COPYRIGHT
474              
475             This program is free software; you can redistribute
476             it and/or modify it under the same terms as Perl itself.
477              
478             The full text of the license can be found in the
479             LICENSE file included with this module.
480              
481             This software is copyrighted (c) 2016 by Jed Lund
482              
483             =head1 DEPENDENCIES
484              
485             =over
486              
487             L<Spreadsheet::Reader::ExcelXML> - the package
488              
489             =back
490              
491             =head1 SEE ALSO
492              
493             =over
494              
495             L<Spreadsheet::Read> - generic Spreadsheet reader
496              
497             L<Spreadsheet::ParseExcel> - Excel binary version 2003 and earlier (.xls files)
498              
499             L<Spreadsheet::XLSX> - Excel version 2007 and later
500              
501             L<Spreadsheet::ParseXLSX> - Excel version 2007 and later
502              
503             L<Log::Shiras|https://github.com/jandrew/Log-Shiras>
504              
505             =over
506              
507             All lines in this package that use Log::Shiras are commented out
508              
509             =back
510              
511             =back
512              
513             =cut
514              
515             #########1#########2 main pod documentation end 5#########6#########7#########8#########9