File Coverage

lib/Spreadsheet/Reader/ExcelXML/Error.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 40 40 100.0


line stmt bran cond sub pod time code
1             package Spreadsheet::Reader::ExcelXML::Error;
2             our $AUTHORITY = 'cpan:JANDREW';
3 36     36   5871058 use version; our $VERSION = version->declare('v0.16.8');
  36         1542  
  36         221  
4             ###LogSD warn "You uncovered internal logging statements for Spreadsheet::Reader::ExcelXML::Error-$VERSION";
5              
6 36     36   3439 use Moose;
  36         218707  
  36         204  
7 36     36   156674 use Carp qw( cluck longmess );
  36         53  
  36         1980  
8 36     36   1485 use MooseX::StrictConstructor;
  36         42616  
  36         268  
9 36     36   85828 use MooseX::HasDefaults::RO;
  36         14126  
  36         257  
10 36     36   125533 use Types::Standard qw( Str Bool );
  36         48461  
  36         308  
11 36     36   18715 use lib '../../../../lib',;
  36         49  
  36         254  
12 36     36   13144 use Spreadsheet::Reader::ExcelXML::Types qw( ErrorString );
  36         91  
  36         346  
13             ###LogSD with 'Log::Shiras::LogSpace';
14 1     1   708 ###LogSD use Log::Shiras::Telephone;
  1         2  
  1         202  
15              
16             #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
17              
18             has error_string =>(
19             isa => ErrorString,
20             clearer => 'clear_error',
21             reader => 'error',
22             writer => 'set_error',
23             predicate => 'has_error',
24             init_arg => undef,
25             coerce => 1,
26             trigger => sub{
27             my ( $self, $error ) = @_;
28             ###LogSD my $phone = Log::Shiras::Telephone->new(
29             ###LogSD name_space => $self->get_all_space . '::set_error', );
30             my $error_string;
31             ###LogSD $error_string = "In name_space: " . $self->get_all_space . "\n";
32             if( $self->spewing_longmess ){
33             $error_string .= longmess( $error );
34             }else{
35             $error_string .= $error;
36             }
37             ###LogSD $phone->talk( level => 'warn', message => [ $error_string . "\n------------------------------\n" ] );
38             if( $self->if_warn ){
39             warn "$error_string\n";
40             }
41             },
42             );
43              
44             has should_warn =>(
45             isa => Bool,
46             default => 0,
47             writer => 'set_warnings',
48             reader => 'if_warn',
49             );
50              
51             has spew_longmess =>(
52             isa => Bool,
53             default => 1,
54             writer => 'should_spew_longmess',
55             reader => 'spewing_longmess',
56             );
57              
58             #########1 Public Methods 3#########4#########5#########6#########7#########8#########9
59              
60              
61              
62             #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9
63              
64              
65              
66             #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
67              
68              
69              
70             #########1 Phinish 3#########4#########5#########6#########7#########8#########9
71              
72 36     36   30112 no Moose;
  36         73  
  36         240  
73             __PACKAGE__->meta->make_immutable;
74              
75             1;
76              
77             #########1 Documentation 3#########4#########5#########6#########7#########8#########9
78              
79             __END__
80              
81             =head1 NAME
82              
83             Spreadsheet::Reader::ExcelXML::Error - Moose class for remembering the last error
84              
85             =head1 SYNOPSIS
86              
87             #!/usr/bin/env perl
88             $|=1;
89             use MooseX::ShortCut::BuildInstance qw( build_instance );
90             use Spreadsheet::Reader::ExcelXML::Error;
91              
92             my $action = build_instance(
93             add_attributes =>{
94             error_inst =>{
95             handles =>[ qw( error set_error clear_error set_warnings if_warn ) ],
96             },
97             },
98             error_inst => Spreadsheet::Reader::ExcelXML::Error->new(
99             should_warn => 1,# 0 to turn off cluck when the error is set
100             ),
101             );
102             print $action->dump;
103             $action->set_error( "You did something wrong" );
104             print $action->dump;
105             print $action->error . "\n";
106              
107             ##############################################################################
108             # SYNOPSIS Screen Output
109             # 01: $VAR1 = bless( {
110             # 02: 'error_inst' => bless( {
111             # 03: 'should_warn' => 1,
112             # 04: 'spew_longmess' => 1
113             # 04: }, 'Spreadsheet::Reader::ExcelXML::Error' )
114             # 05: }, 'ANONYMOUS_SHIRAS_MOOSE_CLASS_1' );
115             # 06: You did something wrong at ~~error_string (defined at ../../../../lib/Spreadsheet/Reader/ExcelXML/Error.pm line 43) line 13.
116             # 08: Spreadsheet::Reader::ExcelXML::Error::::set_error(Spreadsheet::Reader::ExcelXML::Error=HASH(0x31e398), "You did something wrong") called at ~~ line 110
117             # 09: ANONYMOUS_SHIRAS_MOOSE_CLASS_1::set_error(ANONYMOUS_SHIRAS_MOOSE_CLASS_1=HASH(0x3300f0), "You did something wrong") called at error_example.pl line 18
118             # 10: $VAR1 = bless( {
119             # 11: 'error_inst' => bless( {
120             # 12: 'should_warn' => 1,
121             # 13: 'error_string' => 'You did something wrong'
122             # 14: 'spew_longmess' => 1,
123             # 15: }, 'Spreadsheet::Reader::ExcelXML::Error' )
124             # 16: }, 'ANONYMOUS_SHIRAS_MOOSE_CLASS_1' );
125             # 17: You did something wrong
126             ##############################################################################
127              
128             =head1 DESCRIPTION
129              
130             This documentation is written to explain ways to use this module when writing your own excel
131             parser. To use the general package for excel parsing out of the box please review the
132             documentation for L<Workbooks|Spreadsheet::Reader::ExcelXML>,
133             L<Worksheets|Spreadsheet::Reader::ExcelXML::Worksheet>, and
134             L<Cells|Spreadsheet::Reader::ExcelXML::Cell>
135              
136             This L<Moose> class contains two L<attributes|Moose::Manual::Attributes>. It is intended
137             to be used through (by) L<delegation|Moose::Manual::Delegation> in other classes. The first
138             attribute is used to store the current error string. The second, is set to turn on or off
139             pushing the error string to STDERR when the first attribute is (re)set.
140              
141             =head2 Attributes
142              
143             Data passed to new when creating an instance. For modification of
144             these attributes see the listed 'attribute methods'. For more information on
145             attributes see L<Moose::Manual::Attributes>.
146              
147             =head3 error_string
148              
149             =over
150              
151             B<Definition:> This stores an error string for recall later.
152              
153             B<Default> undef (init_arg = undef)
154              
155             B<Range> any string (error objects with the 'as_string' or 'message' are auto coerced to
156             a string)
157              
158             B<attribute methods> Methods provided to adjust this attribute
159              
160             =back
161              
162             =head4 error
163              
164             =over
165              
166             B<Definition:> returns the currently stored error string
167              
168             =back
169              
170             =head4 clear_error
171              
172             =over
173              
174             B<Definition:> clears the currently stored error string
175              
176             =back
177              
178             =head4 set_error( $error_string )
179              
180             =over
181              
182             B<Definition:> sets the attribute with $error_string.
183              
184             =back
185              
186             =head3 should_warn
187              
188             =over
189              
190             B<Definition:> This determines if the package will push any low level errors logged
191             during processing to STDERR when they occur. (rather than just made available) It
192             should be noted that failures that kill the package should push to STDERR by default.
193             If your Excel sheet is malformed it can error without failing. Sometimes this package
194             will handle those cases correctly and sometimes it wont. If you want to know more
195             behind the scenes about the unexpected behaviour of the sheet then turn this attribute
196             on.
197              
198             B<Default> 1 -> it will push to STDERR
199              
200             B<Range> Boolean values
201              
202             B<attribute methods> Methods provided to adjust this attribute
203              
204             =back
205              
206             =head4 set_warnings( $bool )
207              
208             =over
209              
210             B<Definition:> Turn pushed warnings on or off
211              
212             =back
213              
214             =head4 if_warn
215              
216             =over
217              
218             B<Definition:> Returns the current setting of this attribute
219              
220             =back
221              
222             =head3 spew_longmess
223              
224             =over
225              
226             B<Definition:> This (the Error) class is capable of pulling the L<Carp/longmess>
227             for each error in order to understand what happened. If that is just too much
228             you can change the behaviour
229              
230             B<Default> 1 -> it will pull the longmess (using Carp);
231              
232             B<Range> Boolean values
233              
234             B<attribute methods> Methods provided to adjust this attribute
235              
236             =back
237              
238             =head4 should_spew_longmess( $bool )
239              
240             =over
241              
242             B<Definition:> add the longmess to errors
243              
244             =back
245              
246             =head4 spewing_longmess
247              
248             =over
249              
250             B<Definition:> Returns the current setting of this attribute
251              
252             =back
253              
254             =head1 SUPPORT
255              
256             =over
257              
258             L<github Spreadsheet::Reader::ExcelXML/issues
259             |https://github.com/jandrew/p5-spreadsheet-reader-excelxml/issues>
260              
261             =back
262              
263             =head1 TODO
264              
265             =over
266              
267             B<1.> get clases in this package to return error numbers and or error strings and
268             then provide opportunity for this class to localize.
269              
270             B<2.> Get the @CARP_NOT section to work and skip most of the Moose level reporting
271              
272             =back
273              
274             =head1 AUTHOR
275              
276             =over
277              
278             Jed Lund
279              
280             jandrew@cpan.org
281              
282             =back
283              
284             =head1 COPYRIGHT
285              
286             This program is free software; you can redistribute
287             it and/or modify it under the same terms as Perl itself.
288              
289             The full text of the license can be found in the
290             LICENSE file included with this module.
291              
292             This software is copyrighted (c) 2016 by Jed Lund
293              
294             =head1 DEPENDENCIES
295              
296             =over
297              
298             L<Spreadsheet::Reader::ExcelXML> - the package
299              
300             =back
301              
302             =head1 SEE ALSO
303              
304             =over
305              
306             L<Spreadsheet::Read> - generic Spreadsheet reader
307              
308             L<Spreadsheet::ParseExcel> - Excel binary version 2003 and earlier (.xls files)
309              
310             L<Spreadsheet::XLSX> - Excel version 2007 and later
311              
312             L<Spreadsheet::ParseXLSX> - Excel version 2007 and later
313              
314             L<Log::Shiras|https://github.com/jandrew/Log-Shiras>
315              
316             =over
317              
318             All lines in this package that use Log::Shiras are commented out
319              
320             =back
321              
322             =back
323              
324             =cut
325              
326             #########1#########2 main pod documentation end 5#########6#########7#########8#########9