Debian Codegraph @

lib/XML/LibXML/Error.pod

raw
1 =head1 NAME
2
3 XML::LibXML::Error - Structured Errors
4
5 =head1 SYNOPSIS
6
7
8
9 eval { ... };
10 if (ref($@)) {
11 # handle a structured error (XML::LibXML::Error object)
12 } elsif ($@) {
13 # error, but not an XML::LibXML::Error object
14 } else {
15 # no error
16 }
17
18 $XML::LibXML::Error::WARNINGS=1;
19 $message = $@->as_string();
20 print $@->dump();
21 $error_domain = $@->domain();
22 $error_code = $@->code();
23 $error_message = $@->message();
24 $error_level = $@->level();
25 $filename = $@->file();
26 $line = $@->line();
27 $nodename = $@->nodename();
28 $error_str1 = $@->str1();
29 $error_str2 = $@->str2();
30 $error_str3 = $@->str3();
31 $error_num1 = $@->num1();
32 $error_num2 = $@->num2();
33 $string = $@->context();
34 $offset = $@->column();
35 $previous_error = $@->_prev();
36
37 =head1 DESCRIPTION
38
39 The XML::LibXML::Error class is a tiny frontend to I<<<<<< libxml2 >>>>>>'s structured error support. If XML::LibXML is compiled with structured error
40 support, all errors reported by libxml2 are transformed to XML::LibXML::Error
41 objects. These objects automatically serialize to the corresponding error
42 messages when printed or used in a string operation, but as objects, can also
43 be used to get a detailed and structured information about the error that
44 occurred.
45
46 Unlike most other XML::LibXML objects, XML::LibXML::Error doesn't wrap an
47 underlying I<<<<<< libxml2 >>>>>> structure directly, but rather transforms it to a blessed Perl hash reference
48 containing the individual fields of the structured error information as hash
49 key-value pairs. Individual items (fields) of a structured error can either be
50 obtained directly as $@->{field}, or using autoloaded methods such as
51 $@->field() (where field is the field name). XML::LibXML::Error objects have
52 the following fields: domain, code, level, file, line, nodename, message, str1,
53 str2, str3, num1, num2, and _prev (some of them may be undefined).
54
55 =over 4
56
57 =item $XML::LibXML::Error::WARNINGS
58
59 $XML::LibXML::Error::WARNINGS=1;
60
61 Traditionally, XML::LibXML was suppressing parser warnings by setting libxml2's
62 global variable xmlGetWarningsDefaultValue to 0. Since 1.70 we do not change
63 libxml2's global variables anymore; for backward compatibility, XML::LibXML
64 suppresses warnings. This variable can be set to 1 to enable reporting of these
65 warnings via Perl C<<<<<< warn >>>>>> and to 2 to report hem via C<<<<<< die >>>>>>.
66
67
68 =item as_string
69
70 $message = $@->as_string();
71
72 This function serializes an XML::LibXML::Error object to a string containing
73 the full error message close to the message produced by I<<<<<< libxml2 >>>>>> default error handlers and tools like xmllint. This method is also used to
74 overload "" operator on XML::LibXML::Error, so it is automatically called
75 whenever XML::LibXML::Error object is treated as a string (e.g. in print $@).
76
77
78 =item dump
79
80 print $@->dump();
81
82 This function serializes an XML::LibXML::Error to a string displaying all
83 fields of the error structure individually on separate lines of the form 'name'
84 => 'value'.
85
86
87 =item domain
88
89 $error_domain = $@->domain();
90
91 Returns string containing information about what part of the library raised the
92 error. Can be one of: "parser", "tree", "namespace", "validity", "HTML parser",
93 "memory", "output", "I/O", "ftp", "http", "XInclude", "XPath", "xpointer",
94 "regexp", "Schemas datatype", "Schemas parser", "Schemas validity", "Relax-NG
95 parser", "Relax-NG validity", "Catalog", "C14N", "XSLT", "validity".
96
97
98 =item code
99
100 $error_code = $@->code();
101
102 Returns the actual libxml2 error code. The XML::LibXML::ErrNo module defines
103 constants for individual error codes. Currently libxml2 uses over 480 different
104 error codes.
105
106
107 =item message
108
109 $error_message = $@->message();
110
111 Returns a human-readable informative error message.
112
113
114 =item level
115
116 $error_level = $@->level();
117
118 Returns an integer value describing how consequent is the error.
119 XML::LibXML::Error defines the following constants:
120
121
122 =over 4
123
124 =item *
125
126 XML_ERR_NONE = 0
127
128
129
130 =item *
131
132 XML_ERR_WARNING = 1 : A simple warning.
133
134
135
136 =item *
137
138 XML_ERR_ERROR = 2 : A recoverable error.
139
140
141
142 =item *
143
144 XML_ERR_FATAL = 3 : A fatal error.
145
146
147
148 =back
149
150
151 =item file
152
153 $filename = $@->file();
154
155 Returns the filename of the file being processed while the error occurred.
156
157
158 =item line
159
160 $line = $@->line();
161
162 The line number, if available.
163
164
165 =item nodename
166
167 $nodename = $@->nodename();
168
169 Name of the node where error occurred, if available. When this field is
170 non-empty, libxml2 actually returned a physical pointer to the specified node.
171 Due to memory management issues, it is very difficult to implement a way to
172 expose the pointer to the Perl level as a XML::LibXML::Node. For this reason,
173 XML::LibXML::Error currently only exposes the name the node.
174
175
176 =item str1
177
178 $error_str1 = $@->str1();
179
180 Error specific. Extra string information.
181
182
183 =item str2
184
185 $error_str2 = $@->str2();
186
187 Error specific. Extra string information.
188
189
190 =item str3
191
192 $error_str3 = $@->str3();
193
194 Error specific. Extra string information.
195
196
197 =item num1
198
199 $error_num1 = $@->num1();
200
201 Error specific. Extra numeric information.
202
203
204 =item num2
205
206 $error_num2 = $@->num2();
207
208 In recent libxml2 versions, this value contains a column number of the error or
209 0 if N/A.
210
211
212 =item context
213
214 $string = $@->context();
215
216 For parsing errors, this field contains about 80 characters of the XML near the
217 place where the error occurred. The field C<<<<<< $@-E<gt>column() >>>>>> contains the corresponding offset. Where N/A, the field is undefined.
218
219
220 =item column
221
222 $offset = $@->column();
223
224 See C<<<<<< $@-E<gt>column() >>>>>> above.
225
226
227 =item _prev
228
229 $previous_error = $@->_prev();
230
231 This field can possibly hold a reference to another XML::LibXML::Error object
232 representing an error which occurred just before this error.
233
234
235
236 =back
237
238 =head1 AUTHORS
239
240 Matt Sergeant,
241 Christian Glahn,
242 Petr Pajas
243
244
245 =head1 VERSION
246
247 2.0134
248
249 =head1 COPYRIGHT
250
251 2001-2007, AxKit.com Ltd.
252
253 2002-2006, Christian Glahn.
254
255 2006-2009, Petr Pajas.
256
257 =cut
258
259
260 =head1 LICENSE
261
262 This program is free software; you can redistribute it and/or modify it under
263 the same terms as Perl itself.
264