File Coverage

lib/Spreadsheet/XLSX/Reader/LibXML/Row.pm
Criterion Covered Total %
statement 29 53 54.7
branch 0 10 0.0
condition n/a
subroutine 10 13 76.9
pod 3 3 100.0
total 42 79 53.1


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