File Coverage

blib/lib/Spreadsheet/XLSX/Reader/LibXML/Error.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 36 36 100.0


line stmt bran cond sub pod time code
1             package Spreadsheet::XLSX::Reader::LibXML::Error;
2             our $AUTHORITY = 'cpan:JANDREW';
3 8     8   2928251 use version; our $VERSION = qv('v0.38.18');
  8         1836  
  8         68  
4             ###LogSD warn "You uncovered internal logging statements for Spreadsheet::XLSX::Reader::LibXML::Error-$VERSION";
5              
6 8     8   1539 use Moose;
  8         313872  
  8         61  
7 8     8   49515 use Carp qw( cluck );
  8         20  
  8         534  
8 8     8   4884 use MooseX::StrictConstructor;
  8         174144  
  8         50  
9 8     8   60422 use MooseX::HasDefaults::RO;
  8         42165  
  8         44  
10 8         94 use Types::Standard qw(
11             Str
12             Bool
13 8     8   65417 );
  8         61811  
14 8     8   6190 use lib '../../../../../lib',;
  8         19  
  8         70  
15 8     8   5525 use Spreadsheet::XLSX::Reader::LibXML::Types qw( ErrorString );
  8         29  
  8         115  
16             ###LogSD with 'Log::Shiras::LogSpace';
17             ###LogSD use Log::Shiras::TapWarn qw( re_route_warn restore_warn );
18             ###LogSD use Log::Shiras::Telephone;
19              
20             #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
21              
22             has error_string =>(
23             isa => ErrorString,
24             clearer => 'clear_error',
25             reader => 'error',
26             writer => 'set_error',
27             init_arg => undef,
28             coerce => 1,
29             trigger => sub{
30             my ( $self, $error ) = @_;
31             ###LogSD my $phone = Log::Shiras::Telephone->new(
32             ###LogSD name_space => $self->get_all_space . '::set_error', );
33             if( $self->if_warn ){
34             ###LogSD $phone->talk( level => 'debug', message => [ $error ] );
35             ###LogSD re_route_warn();
36             cluck $error;
37             ###LogSD restore_warn;
38             }else{
39             ###LogSD $phone->talk( level => 'debug', message => [
40             ###LogSD $error . " line " .
41             ###LogSD (((caller(2))[2])? ((caller(2))[2]) : ((caller(1))[2]) ) ] );
42             }
43             },
44             );
45              
46             has should_warn =>(
47             isa => Bool,
48             default => 0,
49             writer => 'set_warnings',
50             reader => 'if_warn',
51             );
52              
53             #########1 Public Methods 3#########4#########5#########6#########7#########8#########9
54              
55              
56              
57             #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9
58              
59              
60              
61             #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
62              
63              
64              
65             #########1 Phinish 3#########4#########5#########6#########7#########8#########9
66              
67 8     8   9433 no Moose;
  8         19  
  8         111  
68             __PACKAGE__->meta->make_immutable;
69            
70             1;
71              
72             #########1 Documentation 3#########4#########5#########6#########7#########8#########9
73              
74             __END__
75              
76             =head1 NAME
77              
78             Spreadsheet::XLSX::Reader::LibXML::Error - Moose class for remembering the last error
79              
80             =head1 SYNOPSIS
81            
82             #!/usr/bin/env perl
83             $|=1;
84             use MooseX::ShortCut::BuildInstance qw( build_instance );
85             use Spreadsheet::XLSX::Reader::LibXML::Error;
86              
87             my $action = build_instance(
88             add_attributes =>{
89             error_inst =>{
90             handles =>[ qw( error set_error clear_error set_warnings if_warn ) ],
91             },
92             },
93             error_inst => Spreadsheet::XLSX::Reader::LibXML::Error->new(
94             should_warn => 1,# 0 to turn off cluck when the error is set
95             ),
96             );
97             print $action->dump;
98             $action->set_error( "You did something wrong" );
99             print $action->dump;
100             print $action->error . "\n";
101            
102             ##############################################################################
103             # SYNOPSIS Screen Output
104             # 01: $VAR1 = bless( {
105             # 02: 'error_inst' => bless( {
106             # 03: 'should_warn' => 1,
107             # 04: 'log_space' => 'Spreadsheet::XLSX::Reader::LogSpace'
108             # 04: }, 'Spreadsheet::XLSX::Reader::Error' )
109             # 05: }, 'ANONYMOUS_SHIRAS_MOOSE_CLASS_1' );
110             # 06: You did something wrong at ~~lib/Spreadsheet/XLSX/Reader/LibXML/Error.pm line 31.
111             # 08: Spreadsheet::XLSX::Reader::Error::__ANON__('Spreadsheet::XLSX::Reader::Error=HASH(0x45e818)', 'You did something wrong') called at writer Spreadsheet::XLSX::Reader::Error::set_error of attribute error_string (defined at ../lib/Spreadsheet/XLSX/Reader/Error.pm line 42) line 13
112             # 09: Spreadsheet::XLSX::Reader::Error::set_error('Spreadsheet::XLSX::Reader::Error'=HASH(0x45e818)', 'You did something wrong') called at C:/strawberry/perl/site/lib/Moose/Meta/Method/Delegation.pm line 110
113             # 10: ANONYMOUS_SHIRAS_MOOSE_CLASS_1::set_error('ANONYMOUS_SHIRAS_MOOSE_CLASS_1=HASH(0x45e890)', 'You did something wrong') called at error_example.pl line 18
114             # 11: $VAR1 = bless( {
115             # 12: 'error_inst' => bless( {
116             # 13: 'should_warn' => 1,
117             # 14: 'error_string' => 'You did something wrong'
118             # 15: }, 'Spreadsheet::XLSX::Reader::Error' )
119             # 16: }, 'ANONYMOUS_SHIRAS_MOOSE_CLASS_1' );
120             # 17: You did something wrong
121             ##############################################################################
122            
123             =head1 DESCRIPTION
124              
125             This documentation is written to explain ways to use this module when writing your own excel
126             parser. To use the general package for excel parsing out of the box please review the
127             documentation for L<Workbooks|Spreadsheet::XLSX::Reader::LibXML>,
128             L<Worksheets|Spreadsheet::XLSX::Reader::LibXML::Worksheet>, and
129             L<Cells|Spreadsheet::XLSX::Reader::LibXML::Cell>
130              
131             This L<Moose> class contains two L<attributes|Moose::Manual::Attributes>. It is intended
132             to be used through (by) L<delegation|Moose::Manual::Delegation> in other classes. The first
133             attribute is used to store the current error string. The second, is set to turn on or off
134             pushing the error string to STDERR when the first attribute is (re)set.
135              
136             =head2 Attributes
137              
138             Data passed to new when creating an instance. For modification of
139             these attributes see the listed 'attribute methods'. For more information on
140             attributes see L<Moose::Manual::Attributes>.
141              
142             =head3 error_string
143              
144             =over
145              
146             B<Definition:> This stores an error string for recall later.
147              
148             B<Default> undef (init_arg = undef)
149              
150             B<Range> any string (error objects with the 'as_string' or 'message' are auto coerced to
151             a string)
152              
153             B<attribute methods> Methods provided to adjust this attribute
154            
155             =back
156              
157             =head4 error
158              
159             =over
160              
161             B<Definition:> returns the currently stored error string
162              
163             =back
164              
165             =head4 clear_error
166              
167             =over
168              
169             B<Definition:> clears the currently stored error string
170              
171             =back
172              
173             =head4 set_error( $error_string )
174              
175             =over
176              
177             B<Definition:> sets the attribute with $error_string.
178              
179             =back
180              
181             =head3 should_warn
182              
183             =over
184              
185             B<Definition:> This determines if the package will L<cluck|CARP> and
186             return a stack trace when the error_string attribute is set.
187              
188             B<Default> 1 -> it will cluck
189              
190             B<Range> Boolean values
191              
192             B<attribute methods> Methods provided to adjust this attribute
193            
194             =back
195              
196             =head4 set_warnings( $bool )
197              
198             =over
199              
200             B<Definition:> Turn clucked warnings on or off
201              
202             =back
203              
204             =head4 if_warn
205              
206             =over
207              
208             B<Definition:> Returns the current setting of this attribute
209              
210             =back
211              
212             =head1 SUPPORT
213              
214             =over
215              
216             L<github Spreadsheet::XLSX::Reader::LibXML/issues
217             |https://github.com/jandrew/Spreadsheet-XLSX-Reader-LibXML/issues>
218              
219             =back
220              
221             =head1 TODO
222              
223             =over
224              
225             B<1.> get clases in this package to return error numbers and or error strings and
226             then provide opportunity for this class to localize.
227              
228             =back
229              
230             =head1 AUTHOR
231              
232             =over
233              
234             Jed Lund
235              
236             jandrew@cpan.org
237              
238             =back
239              
240             =head1 COPYRIGHT
241              
242             This program is free software; you can redistribute
243             it and/or modify it under the same terms as Perl itself.
244              
245             The full text of the license can be found in the
246             LICENSE file included with this module.
247              
248             This software is copyrighted (c) 2014, 2015 by Jed Lund
249              
250             =head1 DEPENDENCIES
251              
252             =over
253              
254             L<version> - 0.77
255              
256             L<Moose>
257              
258             L<Carp> - cluck
259              
260             L<MooseX::StrictConstructor>
261              
262             L<MooseX::HasDefaults::RO>
263              
264             L<Types::Standard>
265              
266             L<Spreadsheet::XLSX::Reader::LibXML::Types> - v0.34
267              
268             =back
269              
270             =head1 SEE ALSO
271              
272             =over
273              
274             L<Spreadsheet::ParseExcel> - Excel 2003 and earlier
275              
276             L<Spreadsheet::XLSX> - 2007+
277              
278             L<Spreadsheet::ParseXLSX> - 2007+
279              
280             L<Log::Shiras|https://github.com/jandrew/Log-Shiras>
281              
282             =over
283              
284             All lines in this package that use Log::Shiras are commented out
285              
286             =back
287              
288             =back
289              
290             =cut
291              
292             #########1#########2 main pod documentation end 5#########6#########7#########8#########9