blib/lib/HTML/HTML5/Parser/Error.pm

filter: Statementstmt 34.8% 15 / 43 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 45.4% 5 / 11 Podpod 100% 7 / 7 totaltotal 30.3% 27 / 89 CC 12 SCAR 27.4
CC
12
Cov
23%
to_string
42.0
tag_name
12.0
level
6.0
CRAP 15.5
« lib/HTML/HTML5/Parser/UA.pm ↑ Summary blib/lib/HTML/HTML5/Parser/Charset/UnicodeChecker.pm »
1 package HTML::HTML5::Parser::Error;
2  
3 11 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 our $VERSION = '0.991';
8  
9 11 ▶use overload '""' => \&to_string;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new
12 {
13 2147 ▶ my ($class, %args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
14 2147 bless \%args, $class;
15 }
16  
17 sub level
18 {
19 0 ▶ my $self = shift;
Subroutine level: not called CC=2 SCAR=17.9
Pod documented
20 return {
21 m => 'MUST',
22 s => 'SHOULD',
23 w => 'WARN',
24 i => 'INFO',
25 u => undef,
26 0 ▶ }->{$self->{level}} || undef;
Condition0%0/2
{'m', 'MUST', 's', 'SHOULD', 'w', 'WARN', 'i', 'INFO', 'u', undef}->{$self->{'level'}} || undef
l!l
00
MC/DC0%0/1
{'m', 'MUST', 's', 'SHOULD', 'w', 'WARN', 'i', 'INFO', 'u', undef}->{$self->{'level'}} || undef
{'m', 'MUST', 's', 'SHOULD', 'w', 'WARN', 'i', 'INFO', 'u', undef}->{$self->{'level'}}
Truth table0%0/2
A
A= {'m', 'MUST', 's', 'SHOULD', 'w', 'WARN', 'i', 'INFO', 'u', undef}->{$self->{'level'}}
Aresult
11
00
27 }
28  
29 sub layer
30 {
31 0 ▶ my $self = shift;
Subroutine layer: not called CC=2 SCAR=17.9
Pod documented
32 0 ▶ return $self->{layer} || undef;
Condition0%0/2
$self->{'layer'} || undef
l!l
00
MC/DC0%0/1
$self->{'layer'} || undef
$self->{'layer'}
Truth table0%0/2
A
A= $self->{'layer'}
Aresult
11
00
33 }
34  
35 sub type
36 {
37 0 ▶ my $self = shift;
Subroutine type: not called CC=2 SCAR=17.9
Pod documented
38 0 ▶ return $self->{type}||undef;
Condition0%0/2
$self->{'type'} || undef
l!l
00
MC/DC0%0/1
$self->{'type'} || undef
$self->{'type'}
Truth table0%0/2
A
A= $self->{'type'}
Aresult
11
00
39 }
40  
41 sub tag_name
42 {
43 0 ▶ my $self = shift;
Subroutine tag_name: not called CC=3 SCAR=24.8
Pod documented
44 0 ▶ return undef unless $self->{token} && exists $self->{token}{tag_name};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"token"} and exists $self->{"token"}{"tag_name"} 0 0 0
Condition0%0/3
$self->{"token"} and exists $self->{"token"}{"tag_name"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"token"} and exists $self->{"token"}{"tag_name"}
$self->{"token"} exists $self->{"token"}{"tag_name"}
Truth table0%0/3
A and B
A= $self->{"token"}B= exists $self->{"token"}{"tag_name"}
ABresult
0X0
100
111
45 0 return $self->{token}{tag_name};
46 }
47  
48 sub source_line
49 {
50 0 ▶ my $self = shift;
Subroutine source_line: not called CC=2 SCAR=17.9
Pod documented
51
52 0 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
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 ▶ my $self = shift;
Subroutine to_string: not called CC=6 SCAR=37.4
Pod documented
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 ▶ push @details, sprintf('complicance: %s', $level) if defined $level;
Branch: 1 branch
BranchTrueFalseTotal
if defined $level 0 0 0
73 0 ▶ push @details, sprintf('line: %d', $l) if defined $l;
Branch: 1 branch
BranchTrueFalseTotal
if defined $l 0 0 0
74 0 ▶ push @details, sprintf('column: %d', $c) if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 0 0 0
75 0 ▶ push @details, sprintf('tag: %s', $tag) if defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tag 0 0 0
76  
77 0 ▶ if (@details)
Branch: 1 branch
BranchTrueFalseTotal
if (@details) 0 0 0
78 {
79 0 $msg .= " [";
80 0 $msg .= join '; ', @details;
81 0 $msg .= "]";
82 }
83
84 0 return $msg;
85 }
86  
87 11 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  
« lib/HTML/HTML5/Parser/UA.pm ↑ Summary blib/lib/HTML/HTML5/Parser/Charset/UnicodeChecker.pm »