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