line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::HTML5::Parser::Error; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
195
|
use 5.008001; |
|
10
|
|
|
|
|
35
|
|
|
10
|
|
|
|
|
617
|
|
4
|
10
|
|
|
10
|
|
96
|
use strict; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
1543
|
|
5
|
10
|
|
|
10
|
|
51
|
use warnings; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
859
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.301'; |
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
37955
|
use overload '""' => \&to_string; |
|
10
|
|
|
|
|
14225
|
|
|
10
|
|
|
|
|
92
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
{ |
13
|
0
|
|
|
0
|
1
|
|
my ($class, %args) = @_; |
14
|
0
|
|
|
|
|
|
bless \%args, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub level |
18
|
|
|
|
|
|
|
{ |
19
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
return { |
21
|
0
|
|
0
|
|
|
|
m => 'MUST', |
22
|
|
|
|
|
|
|
s => 'SHOULD', |
23
|
|
|
|
|
|
|
w => 'WARN', |
24
|
|
|
|
|
|
|
i => 'INFO', |
25
|
|
|
|
|
|
|
u => undef, |
26
|
|
|
|
|
|
|
}->{$self->{level}} || undef; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub layer |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
|
0
|
|
|
|
return $self->{layer} || undef; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub type |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
38
|
0
|
|
0
|
|
|
|
return $self->{type}||undef; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub tag_name |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
0
|
0
|
0
|
|
|
|
return undef unless $self->{token} && exists $self->{token}{tag_name}; |
45
|
0
|
|
|
|
|
|
return $self->{token}{tag_name}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub source_line |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if (wantarray) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
|
return ($self->{line}, $self->{column}); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
|
return $self->{line}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub to_string |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $msg = $self->type; |
67
|
0
|
|
|
|
|
|
my $level = $self->level; |
68
|
0
|
|
|
|
|
|
my $tag = $self->tag_name; |
69
|
0
|
|
|
|
|
|
my ($l, $c) = $self->source_line; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my @details; |
72
|
0
|
0
|
|
|
|
|
push @details, sprintf('complicance: %s', $level) if defined $level; |
73
|
0
|
0
|
|
|
|
|
push @details, sprintf('line: %d', $l) if defined $l; |
74
|
0
|
0
|
|
|
|
|
push @details, sprintf('column: %d', $c) if defined $c; |
75
|
0
|
0
|
|
|
|
|
push @details, sprintf('tag: %s', $tag) if defined $tag; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if (@details) |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
|
|
|
$msg .= " ["; |
80
|
0
|
|
|
|
|
|
$msg .= join '; ', @details; |
81
|
0
|
|
|
|
|
|
$msg .= "]"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $msg; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
HTML::HTML5::Parser::Error - an error that occurred during parsing |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The C<error_handler> and C<errors> methods of C<HTML::HTML5::Parser> generate |
96
|
|
|
|
|
|
|
C<HTML::HTML5::Parser::Error> objects. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
C<HTML::HTML5::Parser::Error> overloads stringification, so can be printed, |
99
|
|
|
|
|
|
|
matched against regular expressions, etc. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Note that L<HTML::HTML5::Parser> is not a validation tool, and there are many |
102
|
|
|
|
|
|
|
classes of error that it does not care about, so will not raise. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 Constructor |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item C<< new(level=>$level, type=>$type, token=>$token, ...) >> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Constructs a new C<HTML::HTML5::Parser::Error> object. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 Methods |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item C<level> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Returns the level of error. ('MUST', 'SHOULD', 'WARN', 'INFO' or undef.) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item C<layer> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns the parsing layer involved, often undef. e.g. 'encode'. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item C<type> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns the type of error as a string. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item C<tag_name> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns the tag name (if any). |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item C<source_line> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
($line, $col) = $error->source_line(); |
137
|
|
|
|
|
|
|
$line = $error->source_line; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
In scalar context, C<source_line> returns the line number of the |
140
|
|
|
|
|
|
|
source code that triggered the error. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
In list context, returns a line/column pair. (Tab characters count as |
143
|
|
|
|
|
|
|
one column, not eight.) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item C<to_string> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns a friendly error string. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 SEE ALSO |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L<HTML::HTML5::Parser>. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 AUTHOR |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Toby Inkster, E<lt>tobyink@cpan.orgE<gt> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Copyright (C) 2011-2012 by Toby Inkster |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
164
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
169
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
170
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
171
|
|
|
|
|
|
|
|