XHTML/WAI.pm

filter: Statementstmt 14.0% 31 / 220 Branchbran 0.8% 1 / 122 Conditioncond 0.0% 0 / 56 MC/DCmcdc 0.0% 0 / 36 Subroutinesub 23.5% 8 / 34 Podpod 100% 7 / 7 totaltotal 9.8% 47 / 475 CC 89 SCAR 49.9
CC
89
Cov
8%
_process_checks
506.0
_check_object
272.0
_check_form_control
90.0
CRAP 146.9
↑ Summary XHTML/Critic.pm »
1 package Test::XHTML::WAI;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $VERSION = '0.13';
8  
9 #----------------------------------------------------------------------------
10  
11 =head1 NAME
12  
13 Test::XHTML::WAI - Basic WAI compliance checks.
14  
15 =head1 SYNOPSIS
16  
17 my $txw = Test::XHTML::WAI->new();
18  
19 $txw->validate($content); # run compliance checks
20 my $results = $txw->results(); # retrieve results
21  
22 $txw->clear(); # clear all current errors and results
23 $txw->errors(); # all current errors reported
24 $txw->errstr(); # basic error message
25  
26 $txw->logfile($file); # logfile for verbose messages
27 $txw->logclean(1); # 1 = overwrite, 0 = append (default)
28  
29 =head1 DESCRIPTION
30  
31 This module attempts to check WAI compliance. Currently only basic checks are
32 implemented, but more comprehensive checks are planned.
33  
34 =cut
35  
36 # -------------------------------------
37 # Library Modules
38  
39 2 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 ▶use HTML::TokeParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 # -------------------------------------
46 # Variables
47  
48 2 my @RESULTS = qw( PASS FAIL );
49  
50 2 ▶my $FIXED = $HTML::TokeParser::VERSION >= 3.69 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$HTML::TokeParser::VERSION >= 3.69 ? : 2 0 2
51  
52 # For a full list of valid W3C DTD types, please see
53 # http://www.w3.org/QA/2002/04/valid-dtd-list.html
54 2 my %declarations = (
55 'xhtml1-strict.dtd' => 2,
56 'xhtml1-transitional.dtd' => 2,
57 'xhtml1-frameset.dtd' => 2,
58 'html401-strict.dtd' => 1,
59 'html401-loose.dtd' => 1,
60 'html401-frameset.dtd' => 1,
61 );
62  
63 2 my @TAGS = (
64 # list taken from http://www.w3schools.com/tags/default.asp
65 'a', 'abbr', 'acronym', 'address', 'applet', 'area',
66 'b', 'base', 'basefont', 'bdo', 'big', 'blockquote', 'body', 'br', 'button',
67 'caption', 'center', 'cite', 'code', 'col', 'colgroup',
68 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt',
69 'em',
70 'fieldset', 'font', 'form', 'frame', 'framset',
71 'head', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'html',
72 'i', 'iframe', 'img', 'input', 'ins',
73 'kbd',
74 'label', 'legend', 'li', 'link',
75 'map', 'menu', 'meta',
76 'noframes', 'noscript',
77 'object', 'ol', 'optgroup', 'option',
78 'p', 'param', 'pre',
79 'q',
80 's', 'samp', 'script', 'select', 'small', 'span', 'strike', 'strong', 'style', 'sub',
81 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt',
82 'u', 'ul',
83 'var',
84  
85 '/form'
86 );
87  
88 # -------------------------------------
89 # Public Methods
90  
91 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
92 0 my $proto = shift; # get the class name
93 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
94  
95 # private data
96 0 my $self = {level => 1, dtdtype => 0};
97 0 $self->{RESULTS}{$_} = 0 for(@RESULTS);
98  
99 0 bless ($self, $class);
100 0 return $self;
101 }
102  
103 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
104 0 my $self = shift;
105 }
106  
107 2 __PACKAGE__->mk_accessors(qw( logfile logclean ));
108  
109 0 ▶sub validate { _process_checks(@_); }
Subroutine validate: not called CC=1 SCAR=6.9
Pod documented
110 0 ▶sub results { _process_results(@_); }
Subroutine results: not called CC=1 SCAR=6.9
Pod documented
111  
112 0 ▶sub clear { my $self = shift; $self->{ERRORS} = undef; $self->_reset_results(); }
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
113 0 ▶sub errors { my $self = shift; return $self->{ERRORS}; }
Subroutine errors: not called CC=1 SCAR=6.9
Pod documented
114 0 ▶sub errstr { my $self = shift; return $self->_print_errors(); }
Subroutine errstr: not called CC=1 SCAR=6.9
Pod documented
115  
116 0 ▶sub level {
Subroutine level: not called CC=3 SCAR=24.8
Pod documented
117 0 my ($self,$level) = @_;
118 0 ▶ $self->{level} = $level if(defined $level && $level =~ /^[123]$/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $level and $level =~ /^[123]$/ 0 0 0
Condition0%0/3
defined $level and $level =~ /^[123]$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $level and $level =~ /^[123]$/
defined $level $level =~ /^[123]$/
Truth table0%0/3
A and B
A= defined $levelB= $level =~ /^[123]$/
ABresult
0X0
100
111
119 0 return $self->{level};
120 }
121  
122 # -------------------------------------
123 # Private Methods
124  
125 0 ▶sub _process_results {
Subroutine _process_results: not called CC=2 SCAR=17.9
126 0 my $self = shift;
127 0 my %results = map {$_ => $self->{RESULTS}{$_}} @RESULTS;
128 0 $self->_log( sprintf "%8s%d\n", "$_:", $results{$_} ) for(@RESULTS);
129 0 return \%results;
130 }
131  
132 0 ▶sub _reset_results {
Subroutine _reset_results: not called CC=2 SCAR=17.9
133 0 my $self = shift;
134 0 $self->{RESULTS}{$_} = 0 for(@RESULTS);
135 }
136  
137 0 ▶sub _print_errors {
Subroutine _print_errors: not called CC=6 SCAR=37.4
138 0 my $self = shift;
139 0 my $str = "\nErrors:\n" ;
140 0 my $i = 1;
141 0 for my $error (@{$self->{ERRORS}}) {
142 0 $str .= "$i. $error->{error}: $error->{message}";
143 0 ▶ $str .= " [$error->{ref}]" if($error->{ref});
Branch: 1 branch
BranchTrueFalseTotal
if $error->{"ref"} 0 0 0
144 0 ▶ $str .= " [row $error->{row}, column $error->{col}]" if($error->{row} && $error->{col} && $FIXED);
Branch: 1 branch
BranchTrueFalseTotal
if $error->{"row"} and $error->{"col"} and $FIXED 0 0 0
Condition0%0/6
$error->{"row"} and $error->{"col"} and $FIXED
!ll&&!rl&&r
000
$error->{"row"} and $error->{"col"}
!ll&&!rl&&r
000
MC/DC0%0/3
$error->{"row"} and $error->{"col"} and $FIXED
$error->{"row"} $error->{"col"} $FIXED
Truth table0%0/4
A and B and C
A= $error->{"row"}B= $error->{"col"}C= $FIXED
ABCresult
0XX0
10X0
1100
1111
145 0 $str .= "\n";
146 0 $i++;
147 }
148 0 return $str;
149 }
150  
151 # -------------------------------------
152 # Subroutines
153  
154 # TODO
155 # (AA) check for absolute rather than relative table cell values
156 # (A) label associated with each input id
157  
158 0 ▶sub _process_checks {
Subroutine _process_checks: not called CC=22 SCAR=62.3
159 0 my $self = shift;
160 0 my $html = shift;
161  
162 # clear data from previous tests.
163 0 $self->{$_} = undef for(qw(input label form links));
164  
165 #push @{ $self->{ERRORS} }, {
166 # error => "debug",
167 # message => "VERSION=$HTML::TokeParser::VERSION, FIXED=$FIXED"
168 #};
169  
170 #use Data::Dumper;
171 #print STDERR "#html=".Dumper($html);
172  
173 0 ▶ if($html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html) { } 0 0 0
174 0 ▶ my $p = $FIXED
Branch: 1 branch
BranchTrueFalseTotal
$FIXED ? : 0 0 0
175 ? HTML::TokeParser->new( \$html,
176 start => "'S',tagname,attr,attrseq,text,line,column",
177 end => "'E',tagname,text,line,column"
178 )
179 : HTML::TokeParser->new( \$html );
180  
181 #print STDERR "#p=".Dumper($p);
182  
183 # determine declaration and the case requirements
184 0 my $token = $p->get_token();
185 0 ▶ if($token && $token->[0] eq 'D') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token and $token->[0] eq 'D') { } 0 0 0
Condition0%0/3
$token and $token->[0] eq "D"
!ll&&!rl&&r
000
MC/DC0%0/2
$token and $token->[0] eq "D"
$token $token->[0] eq "D"
Truth table0%0/3
A and B
A= $tokenB= $token->[0] eq "D"
ABresult
0X0
100
111
186 0 my $declaration = $token->[1];
187 0 $declaration =~ s/\s+/ /sg;
188 0 for my $type (keys %declarations) {
189 0 ▶ if($declaration =~ /$type/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($declaration =~ /$type/) 0 0 0
190 0 $self->{dtdtype} = $declarations{$type};
191 0 last;
192 }
193 }
194 } else {
195 0 $p->unget_token($token);
196 }
197  
198 0 ▶ while( my $tag = $p->get_tag( @TAGS ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tag = $p->get_tag(@TAGS)) 0 0 0
199  
200 # force lower case
201 0 $tag->[0] = lc $tag->[0];
202  
203 0 ▶ if($tag->[0] eq 'form') {
Branch: 11 branches
BranchTrueFalseTotal
if ($tag->[0] eq 'form') { } 0 0 0
elsif ($tag->[0] eq '/form') { } 0 0 0
elsif ($tag->[0] eq 'input') { } 0 0 0
elsif ($tag->[0] =~ /^(select|textarea)$/) { } 0 0 0
elsif ($tag->[0] eq 'label') { } 0 0 0
elsif ($tag->[0] eq 'object') { } 0 0 0
elsif ($tag->[0] eq 'img') { } 0 0 0
elsif ($tag->[0] eq 'a') { } 0 0 0
elsif ($tag->[0] =~ /^(i|b)$/) { } 0 0 0
elsif ($tag->[0] eq 'table') { } 0 0 0
elsif ($tag->[0] =~ /^(th|td)$/) { } 0 0 0
204 0 ▶ $self->{form} = { id => ($tag->[1]{id} || $tag->[1]{name}) };
Condition0%0/3
$tag->[1]{'id'} || $tag->[1]{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag->[1]{'id'} || $tag->[1]{'name'}
$tag->[1]{'id'} $tag->[1]{'name'}
Truth table0%0/3
A || B
A= $tag->[1]{'id'}B= $tag->[1]{'name'}
ABresult
1X1
011
000
205 } elsif($tag->[0] eq '/form') {
206 0 $self->_check_form($tag);
207 0 $self->{form} = undef;
208  
209 } elsif($tag->[0] eq 'input') {
210 0 $self->_check_form_submit($tag);
211 0 $self->_check_form_control($tag);
212 } elsif($tag->[0] =~ /^(select|textarea)$/) {
213 0 $self->_check_form_control($tag);
214 } elsif($tag->[0] eq 'label') {
215 0 $self->_check_label($tag);
216  
217 } elsif($tag->[0] eq 'object') {
218 0 $self->_check_object($tag,$p);
219 } elsif($tag->[0] eq 'img') {
220 0 $self->_check_image($tag);
221 } elsif($tag->[0] eq 'a') {
222 0 $self->_check_link($tag);
223 } elsif($tag->[0] =~ /^(i|b)$/) {
224 0 $self->_check_format($tag);
225  
226 # need to confirm
227 #} elsif($tag->[0] eq 'map') {
228 # $self->_check_title($tag);
229  
230 } elsif($tag->[0] eq 'table') {
231 0 $self->_check_title_summary($tag);
232 0 $self->_check_width($tag);
233 0 $self->_check_height($tag);
234 } elsif($tag->[0] =~ /^(th|td)$/) {
235 0 $self->_check_width($tag);
236 0 $self->_check_height($tag);
237 }
238 }
239  
240 0 $self->_check_labelling();
241  
242 } else {
243 0 push @{ $self->{ERRORS} }, {
244 #ref => 'Best Practices Recommedation only',
245 error => "missing content",
246 message => 'no XHTML content found'
247 };
248 }
249  
250 0 ▶ if($self->{ERRORS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ERRORS'}) { } 0 0 0
251 0 $self->_log( "FAIL\n" );
252 0 $self->{RESULTS}{FAIL}++;
253 } else {
254 0 $self->_log( "PASS\n" );
255 0 $self->{RESULTS}{PASS}++;
256 }
257 }
258  
259 # -------------------------------------
260 # Private Methods : Check Routines
261  
262 0 ▶sub _check_form {
Subroutine _check_form: not called CC=3 SCAR=24.8
263 0 my ($self,$tag) = @_;
264  
265 0 ▶ if(!$self->{form}{submit}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"form"}{"submit"}) 0 0 0
266 0 ▶ push @{ $self->{ERRORS} }, {
Condition0%0/2
$self->{'form'}{'id'} || ''
l!l
00
MC/DC0%0/1
$self->{'form'}{'id'} || ''
$self->{'form'}{'id'}
Truth table0%0/2
A
A= $self->{'form'}{'id'}
Aresult
11
00
267 ref => 'WCAG v2 3.2.2 (A)', #E872
268 error => "W001",
269 0 message => 'no submit button in form (' . ( $self->{form}{id} || '' ) . ')',
270 row => $tag->[2],
271 col => $tag->[3]
272 };
273 }
274 }
275  
276 0 ▶sub _check_form_control {
Subroutine _check_form_control: not called CC=9 SCAR=45.0
277 0 my ($self,$tag) = @_;
278  
279 0 ▶ if($tag->[1]{id}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tag->[1]{'id'}) { } 0 0 0
elsif ($tag->[1]{'type'} and $tag->[1]{'type'} =~ /hidden|submit|reset|button/) { } 0 0 0
elsif (not $tag->[1]{'title'}) { } 0 0 0
280 0 ▶ if($self->{input}{ $tag->[1]{id} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'input'}{$tag->[1]{'id'}}) { } 0 0 0
281 0 push @{ $self->{ERRORS} }, {
282 ref => 'WCAG v2 4.1.1 (A)', #894
283 error => "W002",
284 message => "all <$tag->[0]> tags require a unique id ($tag->[1]{id})",
285 row => $tag->[4],
286 col => $tag->[5]
287 };
288 } else {
289 0 ▶ $self->{input}{ $tag->[1]{id} }{type} = ($tag->[0] =~ /select|textarea/ ? $tag->[0] : $tag->[1]{type});
Branch: 1 branch
BranchTrueFalseTotal
$tag->[0] =~ /select|textarea/ ? : 0 0 0
290 0 $self->{input}{ $tag->[1]{id} }{title} = $tag->[1]{title};
291 0 $self->{input}{ $tag->[1]{id} }{row} = $tag->[4];
292 0 $self->{input}{ $tag->[1]{id} }{column} = $tag->[5];
293 0 ▶ $self->{input}{ $tag->[1]{id} }{active} = ($tag->[1]{disabled} || $tag->[1]{readonly} ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$tag->[1]{'disabled'} || $tag->[1]{'readonly'} ? : 0 0 0
Condition0%0/3
$tag->[1]{"disabled"} or $tag->[1]{"readonly"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag->[1]{"disabled"} or $tag->[1]{"readonly"}
$tag->[1]{"disabled"} $tag->[1]{"readonly"}
Truth table0%0/3
A or B
A= $tag->[1]{"disabled"}B= $tag->[1]{"readonly"}
ABresult
1X1
011
000
294 }
295  
296 ▶ } elsif($tag->[1]{type} && $tag->[1]{type} =~ /hidden|submit|reset|button/) {
Condition0%0/3
$tag->[1]{"type"} and $tag->[1]{"type"} =~ /hidden|submit|reset|button/
!ll&&!rl&&r
000
MC/DC0%0/2
$tag->[1]{"type"} and $tag->[1]{"type"} =~ /hidden|submit|reset|button/
$tag->[1]{"type"} $tag->[1]{"type"} =~ /hidden|submit|reset|button/
Truth table0%0/3
A and B
A= $tag->[1]{"type"}B= $tag->[1]{"type"} =~ /hidden|submit|reset|button/
ABresult
0X0
100
111
297 0 return;
298  
299 #} elsif($tag->[1]{disabled} || $tag->[1]{readonly}) {
300 # return;
301  
302 } elsif(!$tag->[1]{title}) {
303 0 push @{ $self->{ERRORS} }, {
304 ref => 'WCAG v2 1.1.1 (A)', #E866
305 error => "W003",
306 message => "all <$tag->[0]> tags require a <label> or a title attribute ($tag->[1]{name})",
307 row => $tag->[4],
308 col => $tag->[5]
309 };
310 }
311 }
312  
313 0 ▶sub _check_form_submit {
Subroutine _check_form_submit: not called CC=4 SCAR=30.0
314 0 my ($self,$tag) = @_;
315  
316 0 ▶ if($tag->[1]{type} && $tag->[1]{type} eq 'submit') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->[1]{"type"} and $tag->[1]{"type"} eq "submit") 0 0 0
Condition0%0/3
$tag->[1]{"type"} and $tag->[1]{"type"} eq "submit"
!ll&&!rl&&r
000
MC/DC0%0/2
$tag->[1]{"type"} and $tag->[1]{"type"} eq "submit"
$tag->[1]{"type"} $tag->[1]{"type"} eq "submit"
Truth table0%0/3
A and B
A= $tag->[1]{"type"}B= $tag->[1]{"type"} eq "submit"
ABresult
0X0
100
111
317 0 ▶ if(%{$self->{form}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$self->{'form'};}) { } 0 0 0
318 0 $self->{form}{submit} = 1;
319 } else {
320 0 push @{ $self->{ERRORS} }, {
321 #ref => 'Best Practices Recommedation only',
322 error => "CW001",
323 message => 'submit button should be associated with a form',
324 row => $tag->[4],
325 col => $tag->[5]
326 };
327 }
328 }
329 }
330  
331 0 ▶sub _check_label {
Subroutine _check_label: not called CC=3 SCAR=24.8
332 0 my ($self,$tag) = @_;
333  
334 0 ▶ if($tag->[1]{for}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->[1]{'for'}) { } 0 0 0
335 0 ▶ if($self->{label}{ $tag->[1]{for} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'label'}{$tag->[1]{'for'}}) { } 0 0 0
336 0 push @{ $self->{ERRORS} }, {
337 #ref => 'Best Practices Recommedation only',
338 error => "CW002",
339 message => "all <$tag->[0]> tags should reference a unique id ($tag->[1]{for})",
340 row => $tag->[4],
341 col => $tag->[5]
342 };
343 } else {
344 0 $self->{label}{ $tag->[1]{for} }{type} = 'label';
345 0 $self->{label}{ $tag->[1]{for} }{row} = $tag->[4];
346 0 $self->{label}{ $tag->[1]{for} }{column} = $tag->[5];
347 }
348 } else {
349 0 push @{ $self->{ERRORS} }, {
350 ref => 'WCAG v2 1.3.1 (A)', #885
351 error => "W004",
352 message => "all <$tag->[0]> tags must reference an <input> tag id",
353 row => $tag->[4],
354 col => $tag->[5]
355 };
356 }
357 }
358  
359 0 ▶sub _check_image {
Subroutine _check_image: not called CC=2 SCAR=17.9
360 0 my ($self,$tag) = @_;
361  
362 0 ▶ return if(defined $tag->[1]{alt});
Branch: 1 branch
BranchTrueFalseTotal
if defined $tag->[1]{"alt"} 0 0 0
363  
364 0 push @{ $self->{ERRORS} }, {
365 ref => 'WCAG v2 1.1.1 (A)', #E860
366 error => "W005",
367 message => "no alt attribute in <$tag->[0]> tag ($tag->[1]{src})",
368 row => $tag->[4],
369 col => $tag->[5]
370 };
371 }
372  
373 0 ▶sub _check_link {
Subroutine _check_link: not called CC=5 SCAR=34.0
374 0 my ($self,$tag) = @_;
375  
376 0 ▶ return unless(defined $tag->[1]{href}); # ignore named anchors
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag->[1]{"href"} 0 0 0
377  
378 0 ▶ if($tag->[1]{title}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->[1]{"title"}) 0 0 0
379 0 ▶ if($self->{links}{ $tag->[1]{href} } && $self->{links}{ $tag->[1]{href} } ne $tag->[1]{title}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'links'}{$tag->[1]{'href'}} and $self->{'links'}{$tag->[1]{'href'}} ne $tag->[1]{'title'}) { } 0 0 0
Condition0%0/3
$self->{"links"}{$tag->[1]{"href"}} and $self->{"links"}{$tag->[1]{"href"}} ne $tag->[1]{"title"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"links"}{$tag->[1]{"href"}} and $self->{"links"}{$tag->[1]{"href"}} ne $tag->[1]{"title"}
$self->{"links"}{$tag->[1]{"href"}} $self->{"links"}{$tag->[1]{"href"}} ne $tag->[1]{"title"}
Truth table0%0/3
A and B
A= $self->{"links"}{$tag->[1]{"href"}}B= $self->{"links"}{$tag->[1]{"href"}} ne $tag->[1]{"title"}
ABresult
0X0
100
111
380 0 push @{ $self->{ERRORS} }, {
381 ref => 'WCAG v2 2.4.4 (A)', #E898
382 error => "W006",
383 message => "repeated links should use the same titles ($tag->[1]{href}, '$self->{links}{ $tag->[1]{href} }' => '$tag->[1]{title}')",
384 row => $tag->[4],
385 col => $tag->[5]
386 };
387 } else {
388 0 $self->{links}{ $tag->[1]{href} } = $tag->[1]{title};
389 }
390 0 return;
391 }
392  
393 0 push @{ $self->{ERRORS} }, {
394 ref => 'WCAG v2 1.1.1 (A)', #E871
395 error => "W007",
396 message => "no title attribute in a tag ($tag->[1]{href}, '$tag->[3]')",
397 row => $tag->[4],
398 col => $tag->[5]
399 };
400 }
401  
402 0 ▶sub _check_format {
Subroutine _check_format: not called CC=2 SCAR=17.9
403 0 my ($self,$tag) = @_;
404  
405 0 my %formats = (
406 'i' => 'em',
407 'b' => 'strong'
408 );
409  
410 0 ▶ return unless($formats{$tag->[0]});
Branch: 1 branch
BranchTrueFalseTotal
unless $formats{$tag->[0]} 0 0 0
411  
412 0 push @{ $self->{ERRORS} }, {
413 ref => 'WCAG v2 1.3.1 (A)', #E892
414 error => "W008",
415 message => "use CSS for presentation effects, or use <$formats{$tag->[0]}> for emphasis not <$tag->[0]> tag",
416 row => $tag->[4],
417 col => $tag->[5]
418 };
419 }
420  
421 0 ▶sub _check_title {
Subroutine _check_title: not called CC=2 SCAR=17.9
422 0 my ($self,$tag) = @_;
423  
424 0 ▶ return if(defined $tag->[1]{title});
Branch: 1 branch
BranchTrueFalseTotal
if defined $tag->[1]{"title"} 0 0 0
425  
426 0 push @{ $self->{ERRORS} }, {
427 #ref => 'WCAG v2 1.1.1 (A)',
428 error => "W009",
429 message => "no title attribute in <$tag->[0]> tag",
430 row => $tag->[4],
431 col => $tag->[5]
432 };
433 }
434  
435 0 ▶sub _check_title_summary {
Subroutine _check_title_summary: not called CC=3 SCAR=24.8
436 0 my ($self,$tag) = @_;
437  
438 0 ▶ return if(defined $tag->[1]{title} || defined $tag->[1]{summary});
Branch: 1 branch
BranchTrueFalseTotal
if defined $tag->[1]{"title"} or defined $tag->[1]{"summary"} 0 0 0
Condition0%0/3
defined $tag->[1]{"title"} or defined $tag->[1]{"summary"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $tag->[1]{"title"} or defined $tag->[1]{"summary"}
defined $tag->[1]{"title"} defined $tag->[1]{"summary"}
Truth table0%0/3
A or B
A= defined $tag->[1]{"title"}B= defined $tag->[1]{"summary"}
ABresult
1X1
011
000
439  
440 0 push @{ $self->{ERRORS} }, {
441 ref => 'WCAG v2 1.3.1 (A)', #E879
442 error => "W010",
443 message => "no title or summary attribute in <$tag->[0]> tag",
444 row => $tag->[4],
445 col => $tag->[5]
446 };
447 }
448  
449 0 ▶sub _check_width {
Subroutine _check_width: not called CC=4 SCAR=30.0
450 0 my ($self,$tag) = @_;
451  
452 0 ▶ return unless($self->{level} > 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"level"} > 1 0 0 0
453 0 ▶ return unless(defined $tag->[1]{width} && $tag->[1]{width} =~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag->[1]{"width"} and $tag->[1]{"width"} =~ /^\d+$/ 0 0 0
Condition0%0/3
defined $tag->[1]{"width"} and $tag->[1]{"width"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tag->[1]{"width"} and $tag->[1]{"width"} =~ /^\d+$/
defined $tag->[1]{"width"} $tag->[1]{"width"} =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $tag->[1]{"width"}B= $tag->[1]{"width"} =~ /^\d+$/
ABresult
0X0
100
111
454  
455 0 push @{ $self->{ERRORS} }, {
456 ref => 'WCAG v2 1.4.4 (AA)', #E910
457 error => "W011",
458 message => "use relative (or CSS), rather than absolute units for width attribute in <$tag->[0]> tag",
459 row => $tag->[4],
460 col => $tag->[5]
461 };
462 }
463  
464 0 ▶sub _check_height {
Subroutine _check_height: not called CC=4 SCAR=30.0
465 0 my ($self,$tag) = @_;
466  
467 0 ▶ return unless($self->{level} > 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"level"} > 1 0 0 0
468 0 ▶ return unless(defined $tag->[1]{height} && $tag->[1]{height} =~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag->[1]{"height"} and $tag->[1]{"height"} =~ /^\d+$/ 0 0 0
Condition0%0/3
defined $tag->[1]{"height"} and $tag->[1]{"height"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tag->[1]{"height"} and $tag->[1]{"height"} =~ /^\d+$/
defined $tag->[1]{"height"} $tag->[1]{"height"} =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $tag->[1]{"height"}B= $tag->[1]{"height"} =~ /^\d+$/
ABresult
0X0
100
111
469  
470 0 push @{ $self->{ERRORS} }, {
471 ref => 'WCAG v2 1.4.4 (AA)', #E910
472 error => "W012",
473 message => "use relative (or CSS), rather than absolute units for height attribute in <$tag->[0]> tag",
474 row => $tag->[4],
475 col => $tag->[5]
476 };
477 }
478  
479 0 ▶sub _check_object {
Subroutine _check_object: not called CC=16 SCAR=56.1
480 0 my ($self,$tag,$p) = @_;
481  
482 # do we have simple text?
483 0 my $x = $p->get_text();
484 0 $x =~ s/\s+//gs;
485 0 ▶ return if($x);
Branch: 1 branch
BranchTrueFalseTotal
if $x 0 0 0
486  
487 0 my @token;
488 my $found;
489 0 ▶ while( my $t = $p->get_token() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $p->get_token) 0 0 0
490 0 unshift @token, $t;
491 0 ▶ next unless($t->[0] eq 'S' || $t->[0] eq 'E');
Branch: 1 branch
BranchTrueFalseTotal
unless $t->[0] eq "S" or $t->[0] eq "E" 0 0 0
Condition0%0/3
$t->[0] eq "S" or $t->[0] eq "E"
l!l&&r!l&&!r
000
MC/DC0%0/2
$t->[0] eq "S" or $t->[0] eq "E"
$t->[0] eq "S" $t->[0] eq "E"
Truth table0%0/3
A or B
A= $t->[0] eq "S"B= $t->[0] eq "E"
ABresult
1X1
011
000
492  
493 0 ▶ if($t->[0] eq 'E' && $t->[1] eq 'object') {
Branch: 3 branches
BranchTrueFalseTotal
if ($t->[0] eq 'E' and $t->[1] eq 'object') { } 0 0 0
elsif ($t->[0] eq 'S' and $t->[1] eq 'p') { } 0 0 0
elsif ($t->[0] eq 'S' and $t->[1] eq 'img') { } 0 0 0
Condition0%0/3
$t->[0] eq "E" and $t->[1] eq "object"
!ll&&!rl&&r
000
MC/DC0%0/2
$t->[0] eq "E" and $t->[1] eq "object"
$t->[0] eq "E" $t->[1] eq "object"
Truth table0%0/3
A and B
A= $t->[0] eq "E"B= $t->[1] eq "object"
ABresult
0X0
100
111
494 0 last;
495 ▶ } elsif($t->[0] eq 'S' && $t->[1] eq 'p') {
Condition0%0/3
$t->[0] eq "S" and $t->[1] eq "p"
!ll&&!rl&&r
000
MC/DC0%0/2
$t->[0] eq "S" and $t->[1] eq "p"
$t->[0] eq "S" $t->[1] eq "p"
Truth table0%0/3
A and B
A= $t->[0] eq "S"B= $t->[1] eq "p"
ABresult
0X0
100
111
496 0 $x = $p->get_text();
497 0 $x =~ s/\s+//gs;
498 0 ▶ $found = 1 if($x);
Branch: 1 branch
BranchTrueFalseTotal
if $x 0 0 0
499 ▶ } elsif($t->[0] eq 'S' && $t->[1] eq 'img') {
Condition0%0/3
$t->[0] eq "S" and $t->[1] eq "img"
!ll&&!rl&&r
000
MC/DC0%0/2
$t->[0] eq "S" and $t->[1] eq "img"
$t->[0] eq "S" $t->[1] eq "img"
Truth table0%0/3
A and B
A= $t->[0] eq "S"B= $t->[1] eq "img"
ABresult
0X0
100
111
500 0 ▶ $found = 1 if($t->[2]{alt});
Branch: 1 branch
BranchTrueFalseTotal
if $t->[2]{"alt"} 0 0 0
501 }
502  
503 0 ▶ last if($found);
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
504 }
505  
506 # put back tokens
507 0 $p->unget_token($_) for(@token);
508  
509 0 ▶ return if($found);
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
510  
511 0 push @{ $self->{ERRORS} }, {
512 ref => 'WCAG v2 1.1.1 (A)', #E865
513 error => "W013",
514 message => qq{No alternative text (e.g. <p> or <img alt="">) found for <object> tag},
515 row => $tag->[4],
516 col => $tag->[5]
517 };
518 }
519  
520 0 ▶sub _check_labelling {
Subroutine _check_labelling: not called CC=8 SCAR=42.8
521 0 my ($self) = @_;
522  
523 0 for my $input (keys %{$self->{input}}) {
524 0 ▶ next if($self->{input}{$input}{type} && $self->{input}{$input}{type} =~ /hidden|submit|reset|button/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"input"}{$input}{"type"} and $self->{"input"}{$input}{"type"} =~ /hidden|submit|reset|button/ 0 0 0
Condition0%0/3
$self->{"input"}{$input}{"type"} and $self->{"input"}{$input}{"type"} =~ /hidden|submit|reset|button/
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"input"}{$input}{"type"} and $self->{"input"}{$input}{"type"} =~ /hidden|submit|reset|button/
$self->{"input"}{$input}{"type"} $self->{"input"}{$input}{"type"} =~ /hidden|submit|reset|button/
Truth table0%0/3
A and B
A= $self->{"input"}{$input}{"type"}B= $self->{"input"}{$input}{"type"} =~ /hidden|submit|reset|button/
ABresult
0X0
100
111
525 0 ▶ next if($self->{label}{$input});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"label"}{$input} 0 0 0
526 0 ▶ next if($self->{input}{$input}{title});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"input"}{$input}{"title"} 0 0 0
527 #next if($self->{input}{$input}{active} == 0);
528  
529 0 push @{ $self->{ERRORS} }, {
530 ref => 'WCAG v2 1.1.1 (A)', #E866
531 error => "W014",
532 message => "all <$self->{input}{$input}{type}> tags require a unique <label> tag or a title attribute ($input)",
533 row => $self->{input}{$input}{row},
534 col => $self->{input}{$input}{column}
535 0 };
536 }
537  
538 0 for my $input (keys %{$self->{label}}) {
539 0 ▶ next if($self->{input}{$input});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"input"}{$input} 0 0 0
540  
541 0 push @{ $self->{ERRORS} }, {
542 ref => 'WCAG v2 1.3.1 (A)', #E895
543 error => "W015",
544 message => "all <label> tags should reference a unique <input> tag ($input)",
545 row => $self->{label}{$input}{row},
546 col => $self->{label}{$input}{column}
547 0 };
548 }
549 }
550  
551 # -------------------------------------
552 # Private Methods : Other
553  
554 0 ▶sub _log {
Subroutine _log: not called CC=5 SCAR=34.0
555 0 my $self = shift;
556 0 ▶ my $log = $self->logfile or return;
Branch: 1 branch
BranchTrueFalseTotal
my $log = $self->logfile or return 0 0 0
557 0 ▶ mkpath(dirname($log)) unless(-f $log);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $log 0 0 0
558  
559 0 ▶ my $mode = $self->logclean ? 'w+' : 'a+';
Branch: 1 branch
BranchTrueFalseTotal
$self->logclean ? : 0 0 0
560 0 $self->logclean(0);
561  
562 0 ▶ my $fh = IO::File->new($log,$mode) or die "Cannot write to log file [$log]: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($log, $mode) or die "Cannot write to log file [$log]: $!\n" 0 0 0
563 0 print $fh @_;
564 0 $fh->close;
565 }
566  
567 2 1;
568  
569 __END__
↑ Summary XHTML/Critic.pm »