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