PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/perl/vendor/lib/XML/LibXML/Error.pod

http://github.com/dwimperl/perl-5.14.2.1-32bit-windows
Unknown | 257 lines | 144 code | 113 blank | 0 comment | 0 complexity | 8fa17d8e2d52939fc89473a75b40e050 MD5 | raw file
Possible License(s): LGPL-3.0, Unlicense, GPL-2.0, LGPL-2.0, BSD-3-Clause, LGPL-2.1, AGPL-1.0, GPL-3.0
  1. =head1 NAME
  2. XML::LibXML::Error - Structured Errors
  3. =head1 SYNOPSIS
  4. eval { ... };
  5. if (ref($@)) {
  6. # handle a structured error (XML::LibXML::Error object)
  7. } elsif ($@) {
  8. # error, but not an XML::LibXML::Error object
  9. } else {
  10. # no error
  11. }
  12. $XML::LibXML::Error::WARNINGS=1;
  13. $message = $@->as_string();
  14. print $@->dump();
  15. $error_domain = $@->domain();
  16. $error_code = $@->code();
  17. $error_message = $@->message();
  18. $error_level = $@->level();
  19. $filename = $@->file();
  20. $line = $@->line();
  21. $nodename = $@->nodename();
  22. $error_str1 = $@->str1();
  23. $error_str2 = $@->str2();
  24. $error_str3 = $@->str3();
  25. $error_num1 = $@->num1();
  26. $error_num2 = $@->num2();
  27. $string = $@->context();
  28. $offset = $@->column();
  29. $previous_error = $@->_prev();
  30. =head1 DESCRIPTION
  31. The XML::LibXML::Error class is a tiny frontend to I<<<<<< libxml2 >>>>>>'s structured error support. If XML::LibXML is compiled with structured error
  32. support, all errors reported by libxml2 are transformed to XML::LibXML::Error
  33. objects. These objects automatically serialize to the corresponding error
  34. messages when printed or used in a string operation, but as objects, can also
  35. be used to get a detailed and structured information about the error that
  36. occurred.
  37. Unlike most other XML::LibXML objects, XML::LibXML::Error doesn't wrap an
  38. underlying I<<<<<< libxml2 >>>>>> structure directly, but rather transforms it to a blessed Perl hash reference
  39. containing the individual fields of the structured error information as hash
  40. key-value pairs. Individual items (fields) of a structured error can either be
  41. obtained directly as $@->{field}, or using autoloaded methods such as as
  42. $@->field() (where field is the field name). XML::LibXML::Error objects have
  43. the following fields: domain, code, level, file, line, nodename, message, str1,
  44. str2, str3, num1, num2, and _prev (some of them may be undefined).
  45. =over 4
  46. =item $XML::LibXML::Error::WARNINGS
  47. $XML::LibXML::Error::WARNINGS=1;
  48. Traditionally, XML::LibXML was suppressing parser warnings by setting libxml2's
  49. global variable xmlGetWarningsDefaultValue to 0. Since 1.70 we do not change
  50. libxml2's global variables anymore; for backward compatibility, XML::LibXML
  51. suppresses warnings. This variable can be set to 1 to enable reporting of these
  52. warnings via Perl C<<<<<< warn >>>>>> and to 2 to report hem via C<<<<<< die >>>>>>.
  53. =item as_string
  54. $message = $@->as_string();
  55. This function serializes an XML::LibXML::Error object to a string containing
  56. 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
  57. overload "" operator on XML::LibXML::Error, so it is automatically called
  58. whenever XML::LibXML::Error object is treated as a string (e.g. in print $@).
  59. =item dump
  60. print $@->dump();
  61. This function serializes an XML::LibXML::Error to a string displaying all
  62. fields of the error structure individually on separate lines of the form 'name'
  63. => 'value'.
  64. =item domain
  65. $error_domain = $@->domain();
  66. Returns string containing information about what part of the library raised the
  67. error. Can be one of: "parser", "tree", "namespace", "validity", "HTML parser",
  68. "memory", "output", "I/O", "ftp", "http", "XInclude", "XPath", "xpointer",
  69. "regexp", "Schemas datatype", "Schemas parser", "Schemas validity", "Relax-NG
  70. parser", "Relax-NG validity", "Catalog", "C14N", "XSLT", "validity".
  71. =item code
  72. $error_code = $@->code();
  73. Returns the actual libxml2 error code. The XML::LibXML::ErrNo module defines
  74. constants for individual error codes. Currently libxml2 uses over 480 different
  75. error codes.
  76. =item message
  77. $error_message = $@->message();
  78. Returns a human-readable informative error message.
  79. =item level
  80. $error_level = $@->level();
  81. Returns an integer value describing how consequent is the error.
  82. XML::LibXML::Error defines the following constants:
  83. =over 4
  84. =item *
  85. XML_ERR_NONE = 0
  86. =item *
  87. XML_ERR_WARNING = 1 : A simple warning.
  88. =item *
  89. XML_ERR_ERROR = 2 : A recoverable error.
  90. =item *
  91. XML_ERR_FATAL = 3 : A fatal error.
  92. =back
  93. =item file
  94. $filename = $@->file();
  95. Returns the filename of the file being processed while the error occurred.
  96. =item line
  97. $line = $@->line();
  98. The line number, if available.
  99. =item nodename
  100. $nodename = $@->nodename();
  101. Name of the node where error occurred, if available. When this field is
  102. non-empty, libxml2 actually returned a physical pointer to the specified node.
  103. Due to memory management issues, it is very difficult to implement a way to
  104. expose the pointer to the Perl level as a XML::LibXML::Node. For this reason,
  105. XML::LibXML::Error currently only exposes the name the node.
  106. =item str1
  107. $error_str1 = $@->str1();
  108. Error specific. Extra string information.
  109. =item str2
  110. $error_str2 = $@->str2();
  111. Error specific. Extra string information.
  112. =item str3
  113. $error_str3 = $@->str3();
  114. Error specific. Extra string information.
  115. =item num1
  116. $error_num1 = $@->num1();
  117. Error specific. Extra numeric information.
  118. =item num2
  119. $error_num2 = $@->num2();
  120. In recent libxml2 versions, this value contains a column number of the error or
  121. 0 if N/A.
  122. =item context
  123. $string = $@->context();
  124. For parsing errors, this field contains about 80 characters of the XML near the
  125. place where the error occurred. The field C<<<<<< $@->column() >>>>>> contains the corresponding offset. Where N/A, the field is undefined.
  126. =item column
  127. $offset = $@->column();
  128. See C<<<<<< $@->column() >>>>>> above.
  129. =item _prev
  130. $previous_error = $@->_prev();
  131. This field can possibly hold a reference to another XML::LibXML::Error object
  132. representing an error which occurred just before this error.
  133. =back
  134. =head1 AUTHORS
  135. Matt Sergeant,
  136. Christian Glahn,
  137. Petr Pajas
  138. =head1 VERSION
  139. 1.88
  140. =head1 COPYRIGHT
  141. 2001-2007, AxKit.com Ltd.
  142. 2002-2006, Christian Glahn.
  143. 2006-2009, Petr Pajas.
  144. =cut