File Coverage

blib/lib/Spreadsheet/Reader/Format.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1             package Spreadsheet::Reader::Format;
2             our $AUTHORITY = 'cpan:JANDREW';
3 1     1   492 use version 0.77; our $VERSION = version->declare('v0.6.4');
  1         24  
  1         7  
4             ###LogSD warn "You uncovered internal logging statements for Spreadsheet::Reader::Format-$VERSION";
5              
6 1     1   91 use 5.010;
  1         2  
7 1     1   3 use Moose::Role;
  1         1  
  1         6  
8             requires qw(
9             get_excel_region has_target_encoding
10             get_target_encoding set_target_encoding
11             change_output_encoding set_defined_excel_formats
12             get_defined_conversion parse_excel_format_string
13             set_cache_behavior set_date_behavior
14             set_european_first set_workbook_inst
15             );
16              
17             #########1 Dispatch Tables & Package Variables 5#########6#########7#########8#########9
18              
19              
20              
21             #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
22              
23              
24              
25             #########1 Public Methods 3#########4#########5#########6#########7#########8#########9
26              
27             ###LogSD sub get_class_space{ 'ExcelFormatInterface' }
28              
29             #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9
30              
31              
32              
33             #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
34              
35              
36              
37             #########1 Phinish 3#########4#########5#########6#########7#########8#########9
38              
39 1     1   3801 no Moose::Role;
  1         1  
  1         3  
40              
41             1;
42              
43             #########1 Documentation 3#########4#########5#########6#########7#########8#########9
44             __END__
45              
46             =head1 NAME
47              
48             Spreadsheet::Reader::Format - Formatting for various spreadsheet readers
49              
50             =begin html
51              
52             <a href="https://www.perl.org">
53             <img src="https://img.shields.io/badge/perl-5.10+-brightgreen.svg" alt="perl version">
54             </a>
55              
56             <a href="https://travis-ci.org/jandrew/p5-spreadsheet-reader-format">
57             <img alt="Build Status" src="https://travis-ci.org/jandrew/p5-spreadsheet-reader-format.png?branch=master" alt='Travis Build'/>
58             </a>
59              
60             <a href='https://coveralls.io/github/jandrew/p5-spreadsheet-reader-format?branch=master'>
61             <img src='https://coveralls.io/repos/github/jandrew/p5-spreadsheet-reader-format/badge.svg?branch=master' alt='Coverage Status' />
62             </a>
63              
64             <a href='https://github.com/jandrew/p5-spreadsheet-reader-format'>
65             <img src="https://img.shields.io/github/tag/jandrew/p5-spreadsheet-reader-format.svg?label=github version" alt="github version"/>
66             </a>
67              
68             <a href="https://metacpan.org/pod/Spreadsheet::Reader::Format">
69             <img src="https://badge.fury.io/pl/Spreadsheet-Reader-Format.svg?label=cpan version" alt="CPAN version" height="20">
70             </a>
71              
72             <a href='http://cpants.cpanauthors.org/dist/Spreadsheet-Reader-Format'>
73             <img src='http://cpants.cpanauthors.org/dist/Spreadsheet-Reader-Format.png' alt='kwalitee' height="20"/>
74             </a>
75              
76             =end html
77              
78             =head1 SYNOPSYS
79              
80             #!/usr/bin/env perl
81             use MooseX::ShortCut::BuildInstance 'build_instance';
82             use Spreadsheet::Reader::Format;
83             use Spreadsheet::Reader::Format::FmtDefault;
84             use Spreadsheet::Reader::Format::ParseExcelFormatStrings;
85             use Spreadsheet::Reader::ExcelXML;
86             my $formatter = build_instance(
87             package => 'FormatInstance',
88             # The base United State localization settings - Inject your customized format class here
89             superclasses => [ 'Spreadsheet::Reader::Format::FmtDefault' ],
90             # ParseExcelFormatStrings => The Excel string parser generation engine
91             # Format => The top level interface defining minimum compatability requirements
92             add_roles_in_sequence =>[qw(
93             Spreadsheet::Reader::Format::ParseExcelFormatStrings
94             Spreadsheet::Reader::Format
95             )],
96             target_encoding => 'latin1',# Adjust the string output encoding here
97             datetime_dates => 1,
98             );
99              
100             # Use in a standalone manner
101             my $date_string = 'yyyy-mm-dd';
102             my $time = 55.0000102311;
103             # Build a coercion with excel format string: $date_string
104             my $coercion = $formatter->parse_excel_format_string( $date_string );
105             # Checking that a DateTime object was returned
106             print ref( $coercion->assert_coerce( $time ) ) . "\n";
107             # Checking that the date and time are presented correctly: 1904-02-25T00:00:01
108             print $coercion->assert_coerce( $time ) . "\n";
109              
110             # Set specific default custom formats here (for use in an excel parser)
111             $formatter->set_defined_excel_formats( 0x2C => 'MyCoolFormatHere' );
112              
113             # Use the formatter like Spreadsheet::ParseExcel
114             my $parser = Spreadsheet::Reader::ExcelXML->new;
115             my $workbook = $parser->parse( '../t/test_files/TestBook.xlsx', $formatter );
116              
117              
118             =head1 DESCRIPTION
119              
120             In general a completly built formatter class as shown in the SYNOPSYS is already used
121             by the package L<Spreadsheet::Reader::ExcelXML> to turn unformatted data into formatted
122             data. The purpose is to allow the Excel equivalent of localization of the output. The
123             general localization options are mostly found at the workbook level. Individual cells
124             also contain information about how that cell data should be formatted.
125              
126             It is possible to insert alternate roles in the Formatter build or use methods
127             to customize the defaults used by the formatter for use in the Spreadsheet reader. It
128             is also possible to use the formatter to output custom format code for post processing
129             output..
130              
131             =head2 Module Description
132              
133             This module is written to be an L<Interface
134             |http://www.codeproject.com/Articles/22769/Introduction-to-Object-Oriented-Programming-Concep#Interface>
135             for the Formatter class used in L<Spreadsheet::Reader::ExcelXML> so that the core
136             L<parsing engine|Spreadsheet::Reader::Format::ParseExcelFormatStrings> and the
137             L<regional formatting settings|Spreadsheet::Reader::Format::FmtDefault> for the
138             parser can easily be swapped. This interface really only defines method requirements for
139             the undlerlying instance since the engine it uses was custom-built for
140             L<Spreadsheet::Reader::ExcelXML>. However, adding a shim to this package so it can
141             be used by L<Spreadsheet::ParseExcel> (for example) should be easier because of the
142             abstraction.
143              
144             This module does not provide unique methods. It just requires methods and provides a
145             uniform interface for the workbook package. Additional attributes and methods provided
146             by the sub modules may be available to the instance but are not in the strictest sence
147             required.
148              
149             =head2 Methods
150              
151             These are the methods required by this interface. Links to the default implementation
152             of each method are provided but any customization of the formatter instance for Spreadsheet
153             parsing will as a minimum require these methods.
154              
155             =head3 parse_excel_format_string( $string, $name )
156              
157             =over
158              
159             B<Definition:> This is the method to convert Excel format strings to code that will
160             translate raw data from the file to formatted output in the form defined by the string.
161             It is possible to pass a format name that will be incorperated so that the method
162             $coercion->display_name returns $name.
163              
164             B<Default source:> L<Spreadsheet::Reader::Format::ParseExcelFormatStrings/parse_excel_format_string( $string, $name )>
165              
166             =back
167              
168             =head3 get_defined_conversion( $position )
169              
170             =over
171              
172             B<Definition:> This method returns the code for string conversion for a pre-defined
173             conversion by position.
174              
175             B<Default source:> L<Spreadsheet::Reader::Format::ParseExcelFormatStrings/get_defined_conversion( $position )>
176              
177             =back
178              
179             =head3 set_target_encoding( $encoding )
180              
181             =over
182              
183             B<Definition:> This sets the output $encoding for strings.
184              
185             B<Default source:> L<Spreadsheet::Reader::Format::FmtDefault/set_target_encoding( $encoding )>
186              
187             =back
188              
189             =head3 get_target_encoding
190              
191             =over
192              
193             B<Definition:> This returns the output encoding definition for strings.
194              
195             B<Default source:> L<Spreadsheet::Reader::Format::FmtDefault/get_target_encoding>
196              
197             =back
198              
199             =head3 has_target_encoding
200              
201             =over
202              
203             B<Definition:> It is possible to not set a target encoding in which case any call to decode
204             data acts like a pass through. This returns true if the target encoding is set.
205              
206             B<Default source:> L<Spreadsheet::Reader::Format::FmtDefault/has_target_encoding>
207              
208             =back
209              
210             =head3 change_output_encoding( $string )
211              
212             =over
213              
214             B<Definition:> This is the method call that implements the output encoding change for $string.
215              
216             B<Default source:> L<Spreadsheet::Reader::Format::FmtDefault/change_output_encoding( $string )>
217              
218             =back
219              
220             =head3 get_excel_region
221              
222             =over
223              
224             B<Definition:> It may be useful for this instance to self identify it's target output.
225             This method returns that value
226              
227             B<Default source:> L<Spreadsheet::Reader::Format::FmtDefault/get_excel_region>
228              
229             =back
230              
231             =head3 set_defined_excel_formats( %args )
232              
233             =over
234              
235             B<Definition:> This allows for adjustment and or addition to the output format lookup table.
236             The default implementation allows for multiple ways to do this so please review that documentation
237             for details.
238              
239             B<Default source:> L<Spreadsheet::Reader::Format::FmtDefault/set_defined_excel_formats( %args )>
240              
241             =back
242              
243             =head3 set_cache_behavior( $bool )
244              
245             =over
246              
247             B<Definition:> This sets the flag that turns on caching of built format conversion code sets
248              
249             B<Default source:> L<Spreadsheet::Reader::Format::ParseExcelFormatStrings/set_cache_behavior( $bool )>
250              
251             =back
252              
253             =head3 set_date_behavior( $bool )
254              
255             =over
256              
257             B<Definition:> This sets the flag that interrupts the date formatting to return a datetime object rather
258             than a date string
259              
260             B<Default source:> L<Spreadsheet::Reader::Format::ParseExcelFormatStrings/set_date_behavior( $bool )>
261              
262             =back
263              
264             =head3 set_european_first( $bool )
265              
266             =over
267              
268             B<Definition:> This also sets a flag dealing with dates. The date behavior that is affected here
269             involves parsing date strings (not excel date numbers) and checks the DD-MM-YY form before it
270             checkes the MM-DD-YY form when attempting to parse date strings.
271              
272             B<Default source:> L<Spreadsheet::Reader::Format::ParseExcelFormatStrings/set_european_first( $bool )>
273              
274             =back
275              
276             =head3 set_workbook_inst( $instance )
277              
278             =over
279              
280             B<Definition:> This sets the workbook instance in the Formatter instance.
281             L<Spreadsheet::Reader::ExcelXML> should do this automatically and will overwrite this attribute
282             if the end-user sets it. The purpose of this instance is for the formatter to see some of the
283             workbook level methods;
284              
285             B<Delegates:>
286              
287             =over
288              
289             L<Spreadsheet::Reader::ExcelXML/set_error>
290              
291             L<Spreadsheet::Reader::ExcelXML/get_epoch_year>
292              
293             =back
294              
295             B<Default source:> L<Spreadsheet::Reader::Format::ParseExcelFormatStrings/set_workbook_inst( $instance )>
296              
297             =back
298              
299             =head1 SUPPORT
300              
301             =over
302              
303             L<github Spreadsheet::Reader::Format/issues
304             |https://github.com/jandrew/p5-spreadsheet-reader-format/issues>
305              
306             =back
307              
308             =head1 TODO
309              
310             =over
311              
312             B<1.> Nothing yet
313              
314             =back
315              
316             =head1 AUTHOR
317              
318             =over
319              
320             =item Jed Lund
321              
322             =item jandrew@cpan.org
323              
324             =back
325              
326             =head1 COPYRIGHT
327              
328             This program is free software; you can redistribute
329             it and/or modify it under the same terms as Perl itself.
330              
331             The full text of the license can be found in the
332             LICENSE file included with this module.
333              
334             This software is copyrighted (c) 2016, 2017 by Jed Lund
335              
336             =head1 DEPENDENCIES
337              
338             =over
339              
340             L<version> - 0.77
341              
342             L<perl 5.010|perl/5.10.0>
343              
344             L<Encode> - decode
345              
346             L<Moose> 2.1213
347              
348             L<Carp> - confess
349              
350             L<Type::Tiny> - 1.000
351              
352             L<DateTimeX::Format::Excel> - 0.012
353              
354             L<DateTime::Format::Flexible>
355              
356             L<Clone> - clone
357              
358             =back
359              
360             =head1 SEE ALSO
361              
362             =over
363              
364             L<Spreadsheet::ParseExcel> - Excel 2003 and earlier
365              
366             L<Spreadsheet::XLSX> - 2007+
367              
368             L<Spreadsheet::ParseXLSX> - 2007+
369              
370             L<Log::Shiras|https://github.com/jandrew/Log-Shiras>
371              
372             =over
373              
374             All lines in this package that use Log::Shiras are commented out
375              
376             =back
377              
378             =back
379              
380             =begin html
381              
382             <a href="http://www.perlmonks.org/?node_id=706986">
383             <img src="http://www.perlmonksflair.com/jandrew.jpg" alt="perl monks">
384             </a>
385              
386             =end html
387              
388             =cut
389              
390             #########1#########2 main pod documentation end 5#########6#########7#########8#########9