| 1 | # $Id: Error.pm,v 1.1.2.1 2004/04/20 20:09:48 pajas Exp $ | ||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||
| 3 | # This is free software, you may use it and distribute it under the same terms as | ||||||||||||||||||||||||||||||||
| 4 | # Perl itself. | ||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||
| 6 | # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas | ||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||
| 9 | package XML::LibXML::Error; | ||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 69 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 69 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | # To avoid a "Deep recursion on subroutine as_string" warning | ||||||||||||||||||||||||||||||||
| 15 | 69 | ▶ | no warnings 'recursion'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 69 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 69 | ▶ | use vars qw(@error_domains $VERSION $WARNINGS); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | use overload | ||||||||||||||||||||||||||||||||
| 21 | '""' => \&as_string, | ||||||||||||||||||||||||||||||||
| 22 | 'eq' => sub { | ||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | ("$_[0]" eq "$_[1]") | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||||||
| 25 | 'cmp' => sub { | ||||||||||||||||||||||||||||||||
| 26 | 13 | ▶ | ("$_[0]" cmp "$_[1]") | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||||||
| 28 | 69 | ▶ | fallback => 1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 69 | $WARNINGS = 0; # 0: suppress, 1: report via warn, 2: report via die | |||||||||||||||||||||||||||||||
| 31 | 69 | $VERSION = "2.0210"; # VERSION TEMPLATE: DO NOT CHANGE | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 69 | ▶ | use constant XML_ERR_NONE => 0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | 69 | ▶ | use constant XML_ERR_WARNING => 1; # A simple warning | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 35 | 69 | ▶ | use constant XML_ERR_ERROR => 2; # A recoverable error | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 36 | 69 | ▶ | use constant XML_ERR_FATAL => 3; # A fatal error | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 69 | ▶ | use constant XML_ERR_FROM_NONE => 0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 39 | 69 | ▶ | use constant XML_ERR_FROM_PARSER => 1; # The XML parser | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 40 | 69 | ▶ | use constant XML_ERR_FROM_TREE => 2; # The tree module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 41 | 69 | ▶ | use constant XML_ERR_FROM_NAMESPACE => 3; # The XML Namespace module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 42 | 69 | ▶ | use constant XML_ERR_FROM_DTD => 4; # The XML DTD validation | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 43 | 69 | ▶ | use constant XML_ERR_FROM_HTML => 5; # The HTML parser | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 44 | 69 | ▶ | use constant XML_ERR_FROM_MEMORY => 6; # The memory allocator | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 45 | 69 | ▶ | use constant XML_ERR_FROM_OUTPUT => 7; # The serialization code | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 46 | 69 | ▶ | use constant XML_ERR_FROM_IO => 8; # The Input/Output stack | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 47 | 69 | ▶ | use constant XML_ERR_FROM_FTP => 9; # The FTP module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 48 | 69 | ▶ | use constant XML_ERR_FROM_HTTP => 10; # The FTP module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 49 | 69 | ▶ | use constant XML_ERR_FROM_XINCLUDE => 11; # The XInclude processing | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 50 | 69 | ▶ | use constant XML_ERR_FROM_XPATH => 12; # The XPath module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 51 | 69 | ▶ | use constant XML_ERR_FROM_XPOINTER => 13; # The XPointer module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 52 | 69 | ▶ | use constant XML_ERR_FROM_REGEXP => 14; # The regular expressions module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 53 | 69 | ▶ | use constant XML_ERR_FROM_DATATYPE => 15; # The W3C XML Schemas Datatype module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 54 | 69 | ▶ | use constant XML_ERR_FROM_SCHEMASP => 16; # The W3C XML Schemas parser module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 55 | 69 | ▶ | use constant XML_ERR_FROM_SCHEMASV => 17; # The W3C XML Schemas validation module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 56 | 69 | ▶ | use constant XML_ERR_FROM_RELAXNGP => 18; # The Relax-NG parser module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 57 | 69 | ▶ | use constant XML_ERR_FROM_RELAXNGV => 19; # The Relax-NG validator module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 58 | 69 | ▶ | use constant XML_ERR_FROM_CATALOG => 20; # The Catalog module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 59 | 69 | ▶ | use constant XML_ERR_FROM_C14N => 21; # The Canonicalization module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 60 | 69 | ▶ | use constant XML_ERR_FROM_XSLT => 22; # The XSLT engine from libxslt | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 61 | 69 | ▶ | use constant XML_ERR_FROM_VALID => 23; # The DTD validation module with valid context | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 62 | 69 | ▶ | use constant XML_ERR_FROM_CHECK => 24; # The error-checking module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 63 | 69 | ▶ | use constant XML_ERR_FROM_WRITER => 25; # The xmlwriter module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 64 | 69 | ▶ | use constant XML_ERR_FROM_MODULE => 26; # The dynamically-loaded module module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 65 | 69 | ▶ | use constant XML_ERR_FROM_I18N => 27; # The module handling character conversion | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 66 | 69 | ▶ | use constant XML_ERR_FROM_SCHEMATRONV=> 28; # The Schematron validator module | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 69 | @error_domains = ("", "parser", "tree", "namespace", "validity", | |||||||||||||||||||||||||||||||
| 69 | "HTML parser", "memory", "output", "I/O", "ftp", | ||||||||||||||||||||||||||||||||
| 70 | "http", "XInclude", "XPath", "xpointer", "regexp", | ||||||||||||||||||||||||||||||||
| 71 | "Schemas datatype", "Schemas parser", "Schemas validity", | ||||||||||||||||||||||||||||||||
| 72 | "Relax-NG parser", "Relax-NG validity", | ||||||||||||||||||||||||||||||||
| 73 | "Catalog", "C14N", "XSLT", "validity", "error-checking", | ||||||||||||||||||||||||||||||||
| 74 | "xmlwriter", "dynamic loading", "i18n", | ||||||||||||||||||||||||||||||||
| 75 | "Schematron validity"); | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 69 | my $MAX_ERROR_PREV_DEPTH = 100; | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 69 | for my $field (qw<code _prev level file line nodename message column context | |||||||||||||||||||||||||||||||
| 80 | str1 str2 str3 num1 num2 __prev_depth>) { | ||||||||||||||||||||||||||||||||
| 81 | 162 | ▶ | my $method = sub { $_[0]{$field} }; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 82 | 69 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 83 | 1035 | *$field = $method; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | sub new { | ||||||||||||||||||||||||||||||||
| 89 | 339 | ▶ | my ($class,$xE) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 90 | 339 | my $terr; | |||||||||||||||||||||||||||||||
| 91 | 339 | ▶ | if (ref($xE)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | 338 | my ($context,$column) = $xE->context_and_column(); | |||||||||||||||||||||||||||||||
| 93 | 338 | ▶ | $terr =bless { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | domain => $xE->domain(), | ||||||||||||||||||||||||||||||||
| 95 | level => $xE->level(), | ||||||||||||||||||||||||||||||||
| 96 | code => $xE->code(), | ||||||||||||||||||||||||||||||||
| 97 | message => $xE->message(), | ||||||||||||||||||||||||||||||||
| 98 | file => $xE->file(), | ||||||||||||||||||||||||||||||||
| 99 | line => $xE->line(), | ||||||||||||||||||||||||||||||||
| 100 | str1 => $xE->str1(), | ||||||||||||||||||||||||||||||||
| 101 | str2 => $xE->str2(), | ||||||||||||||||||||||||||||||||
| 102 | str3 => $xE->str3(), | ||||||||||||||||||||||||||||||||
| 103 | num1 => $xE->num1(), | ||||||||||||||||||||||||||||||||
| 104 | num2 => $xE->num2(), | ||||||||||||||||||||||||||||||||
| 105 | __prev_depth => 0, | ||||||||||||||||||||||||||||||||
| 106 | (defined($context) ? | ||||||||||||||||||||||||||||||||
| 107 | ( | ||||||||||||||||||||||||||||||||
| 108 | context => $context, | ||||||||||||||||||||||||||||||||
| 109 | column => $column, | ||||||||||||||||||||||||||||||||
| 110 | ) : ()), | ||||||||||||||||||||||||||||||||
| 111 | }, $class; | ||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||
| 113 | # !!!! problem : got a flat error | ||||||||||||||||||||||||||||||||
| 114 | # warn("PROBLEM: GOT A FLAT ERROR $xE\n"); | ||||||||||||||||||||||||||||||||
| 115 | 1 | $terr =bless { | |||||||||||||||||||||||||||||||
| 116 | domain => 0, | ||||||||||||||||||||||||||||||||
| 117 | level => 2, | ||||||||||||||||||||||||||||||||
| 118 | code => -1, | ||||||||||||||||||||||||||||||||
| 119 | message => $xE, | ||||||||||||||||||||||||||||||||
| 120 | file => undef, | ||||||||||||||||||||||||||||||||
| 121 | line => undef, | ||||||||||||||||||||||||||||||||
| 122 | str1 => undef, | ||||||||||||||||||||||||||||||||
| 123 | str2 => undef, | ||||||||||||||||||||||||||||||||
| 124 | str3 => undef, | ||||||||||||||||||||||||||||||||
| 125 | num1 => undef, | ||||||||||||||||||||||||||||||||
| 126 | num2 => undef, | ||||||||||||||||||||||||||||||||
| 127 | __prev_depth => 0, | ||||||||||||||||||||||||||||||||
| 128 | }, $class; | ||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | 339 | return $terr; | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | sub _callback_error { | ||||||||||||||||||||||||||||||||
| 134 | #print "CALLBACK\n"; | ||||||||||||||||||||||||||||||||
| 135 | 338 | ▶ | my ($xE,$prev) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_callback_error: called CC=8 SCAR=21.9
| |||||||||||||||||||||||||||||||||
| 136 | 338 | my $terr; | |||||||||||||||||||||||||||||||
| 137 | 338 | $terr=XML::LibXML::Error->new($xE); | |||||||||||||||||||||||||||||||
| 138 | 338 | ▶ | if ($terr->{level} == XML_ERR_WARNING and $WARNINGS!=2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$terr->{"level"} == 1 and $XML::LibXML::Error::WARNINGS != 2
MC/DC50%1/2
$terr->{"level"} == 1 and $XML::LibXML::Error::WARNINGS != 2
$terr->{"level"} == 1
$XML::LibXML::Error::WARNINGS != 2
Truth table66%2/3
A and B
A= $terr->{"level"} == 1B= $XML::LibXML::Error::WARNINGS != 2
| |||||||||||||||||||||||||||||||||
| 139 | 106 | ▶ | warn $terr if $WARNINGS; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 140 | 106 | return $prev; | |||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | #unless ( defined $terr->{file} and length $terr->{file} ) { | ||||||||||||||||||||||||||||||||
| 143 | # this would make it easier to recognize parsed strings | ||||||||||||||||||||||||||||||||
| 144 | # but it breaks old implementations | ||||||||||||||||||||||||||||||||
| 145 | # [CG] $terr->{file} = 'string()'; | ||||||||||||||||||||||||||||||||
| 146 | #} | ||||||||||||||||||||||||||||||||
| 147 | #warn "Saving the error ",$terr->dump; | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 232 | ▶ | if (ref($prev)) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||||||
| 151 | 79 | ▶ | if ($prev->__prev_depth() >= $MAX_ERROR_PREV_DEPTH) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||
| 153 | 0 | return $prev; | |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | 79 | $terr->{_prev} = $prev; | |||||||||||||||||||||||||||||||
| 156 | 79 | $terr->{__prev_depth} = $prev->__prev_depth() + 1; | |||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | else | ||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||
| 160 | 153 | ▶ | $terr->{_prev} = defined($prev) && length($prev) ? XML::LibXML::Error->new($prev) : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $prev and length $prev
MC/DC0%0/2
defined $prev and length $prev
defined $prev
length $prev
Truth table33%1/3
A and B
A= defined $prevB= length $prev
| |||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||
| 162 | 232 | return $terr; | |||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | sub _instant_error_callback { | ||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $xE = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_instant_error_callback: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 166 | 0 | my $terr= XML::LibXML::Error->new($xE); | |||||||||||||||||||||||||||||||
| 167 | 0 | print "Reporting an instanteous error ",$terr->dump; | |||||||||||||||||||||||||||||||
| 168 | 0 | die $terr; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | sub _report_warning { | ||||||||||||||||||||||||||||||||
| 171 | 1 | ▶ | my ($saved_error) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_report_warning: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||
| 172 | #print "CALLBACK WARN\n"; | ||||||||||||||||||||||||||||||||
| 173 | 1 | ▶ | if ( defined $saved_error ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 174 | #print "reporting a warning ",$saved_error->dump; | ||||||||||||||||||||||||||||||||
| 175 | 1 | warn $saved_error; | |||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | sub _report_error { | ||||||||||||||||||||||||||||||||
| 179 | 151 | ▶ | my ($saved_error) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_report_error: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||
| 180 | #print "CALLBACK ERROR: $saved_error\n"; | ||||||||||||||||||||||||||||||||
| 181 | 151 | ▶ | if ( defined $saved_error ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 182 | 151 | die $saved_error; | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | # backward compatibility | ||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub int1 { $_[0]->num1 } | ||||||||||||||||||||||||||||||
|
Subroutine
int1: not called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub int2 { $_[0]->num2 } | ||||||||||||||||||||||||||||||
|
Subroutine
int2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | sub domain { | ||||||||||||||||||||||||||||||||
| 193 | 578 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||
|
Subroutine
domain: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 194 | 578 | ▶ | return undef unless ref($self); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 195 | 578 | my $domain = $self->{domain}; | |||||||||||||||||||||||||||||||
| 196 | # Newer versions of libxml2 might yield errors in domains that aren't | ||||||||||||||||||||||||||||||||
| 197 | # listed above. Invent something reasonable in that case. | ||||||||||||||||||||||||||||||||
| 198 | 578 | ▶ | return $domain < @error_domains ? $error_domains[$domain] : "domain_$domain"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | sub as_string { | ||||||||||||||||||||||||||||||||
| 202 | 575 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=15 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 203 | 575 | my $msg = ""; | |||||||||||||||||||||||||||||||
| 204 | 575 | my $level; | |||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 575 | ▶ | if (defined($self->{_prev})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 207 | 192 | $msg = $self->{_prev}->as_string; | |||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 575 | ▶ | if ($self->{level} == XML_ERR_NONE) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 211 | 0 | $level = ""; | |||||||||||||||||||||||||||||||
| 212 | } elsif ($self->{level} == XML_ERR_WARNING) { | ||||||||||||||||||||||||||||||||
| 213 | 0 | $level = "warning"; | |||||||||||||||||||||||||||||||
| 214 | ▶ | } elsif ($self->{level} == XML_ERR_ERROR || | |||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"level"} == 2 or $self->{"level"} == 3
MC/DC0%0/2
$self->{"level"} == 2 or $self->{"level"} == 3
$self->{"level"} == 2
$self->{"level"} == 3
Truth table66%2/3
A or B
A= $self->{"level"} == 2B= $self->{"level"} == 3
| |||||||||||||||||||||||||||||||||
| 215 | $self->{level} == XML_ERR_FATAL) { | ||||||||||||||||||||||||||||||||
| 216 | 575 | $level = "error"; | |||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | 575 | my $where=""; | |||||||||||||||||||||||||||||||
| 219 | 575 | ▶ | if (defined($self->{file})) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 220 | 450 | $where="$self->{file}:$self->{line}"; | |||||||||||||||||||||||||||||||
| 221 | ▶ | } elsif (($self->{domain} == XML_ERR_FROM_PARSER) | |||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"domain"} == 1 and $self->{"line"}
MC/DC50%1/2
$self->{"domain"} == 1 and $self->{"line"}
$self->{"domain"} == 1
$self->{"line"}
Truth table66%2/3
A and B
A= $self->{"domain"} == 1B= $self->{"line"}
| |||||||||||||||||||||||||||||||||
| 222 | and | ||||||||||||||||||||||||||||||||
| 223 | $self->{line}) { | ||||||||||||||||||||||||||||||||
| 224 | 48 | $where="Entity: line $self->{line}"; | |||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | 575 | ▶ | if ($self->{nodename}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 227 | 0 | $where.=": element ".$self->{nodename}; | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | 575 | ▶ | $msg.=$where.": " if $where ne ""; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 230 | 575 | $msg.=$self->domain." ".$level." :"; | |||||||||||||||||||||||||||||||
| 231 | 575 | ▶ | my $str=$self->{message}||""; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'message'} || ''
MC/DC0%0/1
$self->{'message'} || ''
$self->{'message'}
Truth table50%1/2
A
A= $self->{'message'}
| |||||||||||||||||||||||||||||||||
| 232 | 575 | chomp($str); | |||||||||||||||||||||||||||||||
| 233 | 575 | $msg.=" ".$str."\n"; | |||||||||||||||||||||||||||||||
| 234 | 575 | ▶ | if (($self->{domain} == XML_ERR_FROM_XPATH) and | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$self->{"domain"} == 12 and defined $self->{"str1"}
MC/DC100%2/2
$self->{"domain"} == 12 and defined $self->{"str1"}
$self->{"domain"} == 12
defined $self->{"str1"}
Truth table100%3/3
A and B
A= $self->{"domain"} == 12B= defined $self->{"str1"}
| |||||||||||||||||||||||||||||||||
| 235 | defined($self->{str1})) { | ||||||||||||||||||||||||||||||||
| 236 | 20 | $msg.=$self->{str1}."\n"; | |||||||||||||||||||||||||||||||
| 237 | 20 | $msg.=(" " x $self->{num1})."^\n"; | |||||||||||||||||||||||||||||||
| 238 | } elsif (defined $self->{context}) { | ||||||||||||||||||||||||||||||||
| 239 | # If the error relates to character-encoding problems in the context, | ||||||||||||||||||||||||||||||||
| 240 | # then doing textual operations on it will spew warnings that | ||||||||||||||||||||||||||||||||
| 241 | # XML::LibXML can do nothing to fix. So just disable all such | ||||||||||||||||||||||||||||||||
| 242 | # warnings. This has the pleasing benefit of making the test suite | ||||||||||||||||||||||||||||||||
| 243 | # run warning-free. | ||||||||||||||||||||||||||||||||
| 244 | 69 | ▶ | no warnings 'utf8'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 245 | 464 | my $context = Encode::encode('UTF-8', $self->{context}); | |||||||||||||||||||||||||||||||
| 246 | 464 | $msg.=$context."\n"; | |||||||||||||||||||||||||||||||
| 247 | 464 | $context = substr($context,0,$self->{column}); | |||||||||||||||||||||||||||||||
| 248 | 464 | $context=~s/[^\t]/ /g; | |||||||||||||||||||||||||||||||
| 249 | 464 | $msg.=$context."^\n"; | |||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||
| 251 | 575 | return $msg; | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | sub dump { | ||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 256 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||
| 257 | 0 | return Data::Dumper->new([$self],['error'])->Dump; | |||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | 69 | 1; | |||||||||||||||||||||||||||||||