W3C.pm

filter: Statementstmt 42.5% 74 / 174 Branchbran 26.3% 19 / 72 Conditioncond 62.5% 10 / 16 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 68.1% 15 / 22 Podpod 100% 9 / 9 totaltotal 42.5% 129 / 303 CC 46 SCAR 35.0
CC
46
Cov
39%
errors
90.5
warnings
90.0
_validate
42.0
CRAP 33.2
↑ Summary W3C/Error.pm »
1 # $Id$
2  
3 package WebService::Validator::HTML::W3C;
4  
5 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use base qw( Class::Accessor );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use HTTP::Request::Common 'POST';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use WebService::Validator::HTML::W3C::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use WebService::Validator::HTML::W3C::Warning;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 16 __PACKAGE__->mk_accessors(
14 qw( http_timeout validator_uri proxy ua _http_method
15 is_valid num_errors num_warnings uri _content _output _response ) );
16  
17 16 ▶use vars qw( $VERSION $VALIDATOR_URI $HTTP_TIMEOUT );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 16 $VERSION = 0.28;
20 16 $VALIDATOR_URI = 'http://validator.w3.org/check';
21 16 $HTTP_TIMEOUT = 30;
22  
23 =head1 NAME
24  
25 WebService::Validator::HTML::W3C - Access the W3Cs online HTML validator
26  
27 =head1 SYNOPSIS
28  
29 use WebService::Validator::HTML::W3C;
30  
31 my $v = WebService::Validator::HTML::W3C->new(
32 detailed => 1
33 );
34  
35 if ( $v->validate("http://www.example.com/") ) {
36 if ( $v->is_valid ) {
37 printf ("%s is valid\n", $v->uri);
38 } else {
39 printf ("%s is not valid\n", $v->uri);
40 foreach my $error ( @{$v->errors} ) {
41 printf("%s at line %d\n", $error->msg,
42 $error->line);
43 }
44 }
45 } else {
46 printf ("Failed to validate the website: %s\n", $v->validator_error);
47 }
48  
49 =head1 DESCRIPTION
50  
51 WebService::Validator::HTML::W3C provides access to the W3C's online
52 Markup validator. As well as reporting on whether a page is valid it
53 also provides access to a detailed list of the errors and where in
54 the validated document they occur.
55  
56 =head1 METHODS
57  
58 =head2 new
59  
60 my $v = WebService::Validator::HTML::W3C->new();
61  
62 Returns a new instance of the WebService::Validator::HTML::W3C object.
63  
64 There are various options that can be set when creating the Validator
65 object like so:
66  
67 my $v = WebService::Validator::HTML::W3C->new( http_timeout => 20 );
68  
69 =over 4
70  
71 =item validator_uri
72  
73 The URI of the validator to use. By default this accesses the W3Cs validator at http://validator.w3.org/check. If you have a local installation of the validator ( recommended if you wish to do a lot of testing ) or wish to use a validator at another location then you can use this option. Please note that you need to use the full path to the validator cgi.
74  
75 =item ua
76  
77 The user agent to use. Should be an LWP::UserAgent object or something that provides the same interface. If this argument is provided, the C<http_timeout> and C<proxy> arguments are ignored.
78  
79 =item http_timeout
80  
81 How long (in seconds) to wait for the HTTP connection to timeout when
82 contacting the validator. By default this is 30 seconds.
83  
84 =item detailed
85  
86 This fetches the XML response from the validator in order to provide information for the errors method. You should set this to true if you intend to use the errors method.
87  
88 =item proxy
89  
90 An HTTP proxy to use when communicating with the validation service.
91  
92 =item output
93  
94 Controls which output format is used. Can be either xml or soap12.
95  
96 The default is soap12 as the XML format is deprecated and is likely to be removed in the future.
97  
98 The default will always work so unless you're using a locally installed Validator you can safely ignore this.
99  
100 =back
101  
102 =cut
103  
104 14 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
105 14 my $ref = shift;
106 14 ▶ my $class = ref $ref || $ref;
Condition33%1/3
ref $ref || $ref
l!l&&r!l&&!r
0140
MC/DC0%0/2
ref $ref || $ref
ref $ref $ref
Truth table33%1/3
A || B
A= ref $refB= $ref
ABresult
1X1
011
000
107 14 my $obj = {};
108 14 bless $obj, $class;
109 14 $obj->_init(@_);
110 14 return $obj;
111 }
112  
113 14 ▶sub _init {
Subroutine _init: called CC=6 SCAR=18.1
114 14 my $self = shift;
115 14 my %args = @_;
116  
117 14 ▶ $self->http_timeout( $args{http_timeout} || $HTTP_TIMEOUT );
Condition66%2/3
$args{'http_timeout'} || $WebService::Validator::HTML::W3C::HTTP_TIMEOUT
l!l&&r!l&&!r
860
MC/DC0%0/2
$args{'http_timeout'} || $WebService::Validator::HTML::W3C::HTTP_TIMEOUT
$args{'http_timeout'} $WebService::Validator::HTML::W3C::HTTP_TIMEOUT
Truth table66%2/3
A || B
A= $args{'http_timeout'}B= $WebService::Validator::HTML::W3C::HTTP_TIMEOUT
ABresult
1X1
011
000
118 14 ▶ $self->validator_uri( $args{validator_uri} || $VALIDATOR_URI );
Condition66%2/3
$args{'validator_uri'} || $WebService::Validator::HTML::W3C::VALIDATOR_URI
l!l&&r!l&&!r
3110
MC/DC0%0/2
$args{'validator_uri'} || $WebService::Validator::HTML::W3C::VALIDATOR_URI
$args{'validator_uri'} $WebService::Validator::HTML::W3C::VALIDATOR_URI
Truth table66%2/3
A || B
A= $args{'validator_uri'}B= $WebService::Validator::HTML::W3C::VALIDATOR_URI
ABresult
1X1
011
000
119 14 $self->ua( $args{ua} );
120 14 ▶ $self->_http_method( $args{detailed} ? 'GET' : 'HEAD' );
Branch: 1 branch
BranchTrueFalseTotal
$args{'detailed'} ? : 4 10 14
121 14 ▶ $self->_output( $args{output} || 'soap12' );
Condition100%2/2
$args{'output'} || 'soap12'
l!l
311
MC/DC100%1/1
$args{'output'} || 'soap12'
$args{'output'}
Truth table100%2/2
A
A= $args{'output'}
Aresult
11
00
122 14 ▶ $self->proxy( $args{proxy} || '' );
Condition50%1/2
$args{'proxy'} || ''
l!l
014
MC/DC0%0/1
$args{'proxy'} || ''
$args{'proxy'}
Truth table50%1/2
A
A= $args{'proxy'}
Aresult
11
00
123 }
124  
125 =head2 validate
126  
127 $v->validate( 'http:://www.example.com/' );
128  
129 Validate a URI. Returns 0 if the validation fails (e.g if the
130 validator cannot be reached), otherwise 1.
131  
132 =head2 validate_file
133  
134 $v->validate_file( './file.html' );
135  
136 Validate a file by uploading it to the W3C Validator. NB This has only been tested on a Linux box so may not work on non unix machines.
137  
138 =head2 validate_markup
139  
140 $v->validate_markup( $markup );
141  
142 Validate a scalar containing HTML.
143  
144 =head2 Alternate interface
145  
146 You can also pass a hash in to specify what you wish to validate. This is provided to ensure compatibility with the CSS validator module.
147  
148 $v->validate( uri => 'http://example.com/' );
149 $v->validate( string => $markup );
150 $v->validate( file => './file.html' );
151
152 =cut
153  
154 0 ▶sub validate_file {
Subroutine validate_file: not called CC=2 SCAR=17.9
Pod documented
155 0 my $self = shift;
156 0 my $file = shift;
157  
158 0 ▶ return $self->validator_error("You need to supply a file to validate")
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
159 unless $file;
160  
161 0 return $self->_validate( { file => $file } );
162 }
163  
164 0 ▶sub validate_markup {
Subroutine validate_markup: not called CC=2 SCAR=17.9
Pod documented
165 0 my $self = shift;
166 0 my $markup = shift;
167  
168 0 ▶ return $self->validator_error("You need to supply markup to validate")
Branch: 1 branch
BranchTrueFalseTotal
unless $markup 0 0 0
169 unless $markup;
170  
171 0 return $self->_validate( { markup => $markup } );
172 }
173  
174 3 ▶sub validate {
Subroutine validate: called CC=7 SCAR=21.5
Pod documented
175 3 my $self = shift;
176  
177 3 my ( %opts, $uri );
178 3 ▶ if ( scalar( @_ ) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 1 2 3
179 1 %opts = @_;
180
181 1 ▶ if ( $opts{ 'uri' } ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($opts{'uri'}) { } 0 1 1
elsif ($opts{'string'}) { } 0 1 1
elsif ($opts{'file'}) { } 0 1 1
182 0 $uri = $opts{ 'uri' };
183 } elsif ( $opts{ 'string' } ) {
184 0 return $self->validate_markup( $opts{ 'string' } );
185 } elsif( $opts{ 'file' } ) {
186 0 return $self->validate_file( $opts{ 'file' } );
187 } else {
188 1 return $self->validator_error( "You need to provide a uri, string or file to validate" );
189 }
190 } else {
191 2 $uri = shift;
192 }
193  
194 2 ▶ return $self->validator_error("You need to supply a URI to validate")
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 1 1 2
195 unless $uri;
196  
197 1 ▶ return $self->validator_error("You need to supply a URI scheme (e.g http)")
Branch: 1 branch
BranchTrueFalseTotal
unless $uri =~ m[^.*?://] 1 0 1
198 unless $uri =~ m(^.*?://);
199  
200 0 return $self->_validate( $uri );
201 }
202  
203 0 ▶sub _validate {
Subroutine _validate: not called CC=6 SCAR=37.4
204 0 my $self = shift;
205 0 my $uri = shift;
206  
207 0 my $uri_orig = $uri;
208  
209 0 $self->uri($uri_orig);
210  
211 0 my $ua = $self->ua;
212 0 ▶ if ( ! $ua ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ua) 0 0 0
213 0 $ua = LWP::UserAgent->new( agent => __PACKAGE__ . "/$VERSION",
214 timeout => $self->http_timeout );
215  
216 0 ▶ if ( $self->proxy ) { $ua->proxy( 'http', $self->proxy ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->proxy) 0 0 0
217 }
218  
219 0 my $request = $self->_get_request( $uri );
220  
221 0 my $response = $ua->request($request);
222  
223 0 ▶ if ( $response->is_success ) # not an error, we could contact the server
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
224 {
225  
226 # set both valid and error number according to response
227  
228 0 $self->_response( $response );
229
230 0 my $res = $self->_parse_validator_response();
231 0 ▶ $self->_content( $response->content() )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_http_method =~ /HEAD/ 0 0 0
232 if $self->_http_method() !~ /HEAD/;
233  
234 # we know the validator has been able to (in)validate if
235 # $self->valid is not NULL
236  
237 0 ▶ if ( $res ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) { } 0 0 0
238 0 return 1;
239 } else {
240 0 return 0;
241 }
242 }
243 else {
244 0 return $self->validator_error('Could not contact validator');
245 }
246 }
247  
248 =head2 is_valid
249  
250 $v->is_valid;
251  
252 Returns true (1) if the URI validated otherwise 0.
253  
254  
255 =head2 uri
256  
257 $v->uri();
258  
259 Returns the URI of the last page on which validation succeeded.
260  
261  
262 =head2 num_errors
263  
264 $num_errors = $v->num_errors();
265  
266 Returns the number of errors that the validator encountered.
267  
268 =head2 errorcount
269  
270 Synonym for num_errors. There to match CSS Validator interface.
271  
272 =head2 warningcount
273  
274 $num_errors = $v->warningcount();
275  
276 Returns the number of warnings that the validator encountered.
277  
278 =head2 errors
279  
280 $errors = $v->errors();
281
282 foreach my $err ( @$errors ) {
283 printf("line: %s, col: %s\n\terror: %s\n",
284 $err->line, $err->col, $err->msg);
285 }
286  
287 Returns an array ref of WebService::Validator::HTML::W3C::Error objects.
288 These have line, col and msg methods that return a line number, a column
289 in that line and the error that occurred at that point.
290  
291 Note that you need XML::XPath for this to work and you must have initialised
292 WebService::Validator::HTML::W3C with the detailed option. If you have not
293 set the detailed option a warning will be issued, the detailed option will
294 be set and a second request made to the validator in order to fetch the
295 required information.
296  
297 If there was a problem processing the detailed information then this method
298 will return 0.
299  
300 =head2 warnings
301  
302 $warnings = $v->warnings();
303  
304 Works exactly the same as errors only returns an array ref of
305 WebService::Validator::HTML::W3C::Warning objects. In all other respects it's the same.
306  
307 =cut
308  
309 1 ▶sub errors {
Subroutine errors: called CC=10 SCAR=45.1
Pod documented
310 1 my $self = shift;
311  
312 1 ▶ return undef unless $self->num_errors();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->num_errors 1 0 1
313  
314 0 ▶ unless ( $self->_http_method() eq 'GET' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_http_method eq "GET") 0 0 0
315 0 warn "You should set detailed when initalising if you intend to use the errors method";
316 0 $self->_http_method( 'GET' );
317 0 $self->validate( $self->uri() );
318 }
319  
320 0 my @errs;
321  
322 0 eval { require XML::XPath; };
323 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
324 0 warn "XML::XPath must be installed in order to get detailed errors";
325 0 return undef;
326 }
327  
328 0 my $xp = XML::XPath->new( xml => $self->_content() );
329  
330 0 ▶ if ( $self->_output eq 'xml' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_output eq 'xml') { } 0 0 0
331 0 ▶ if ( ! $xp->findnodes('/result') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xp->findnodes("/result")) 0 0 0
332 0 return $self->validator_error( 'Result format does not appear to be XML' );
333 }
334 0 my @messages = $xp->findnodes('/result/messages/msg');
335  
336 0 foreach my $msg (@messages) {
337 0 my $err = WebService::Validator::HTML::W3C::Error->new({
338 line => $msg->getAttribute('line'),
339 col => $msg->getAttribute('col'),
340 msg => $msg->getChildNode(1)->getValue(),
341 });
342  
343 0 push @errs, $err;
344 }
345 } else { # assume soap...
346 0 ▶ if ( ! $xp->findnodes('/env:Envelope') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xp->findnodes("/env:Envelope")) 0 0 0
347 0 return $self->validator_error( 'Result format does not appear to be SOAP' );
348 }
349 0 my @messages = $xp->findnodes( '/env:Envelope/env:Body/m:markupvalidationresponse/m:errors/m:errorlist/m:error' );
350  
351 0 foreach my $msg ( @messages ) {
352 0 my $err = WebService::Validator::HTML::W3C::Error->new({
353 line => $xp->find( './m:line', $msg )->get_node(1)->getChildNode(1)->getValue,
354 col => $xp->find( './m:col', $msg )->get_node(1)->getChildNode(1)->getValue,
355 msg => $xp->find( './m:message', $msg )->get_node(1)->getChildNode(1)->getValue,
356 msgid => $xp->find( './m:messageid', $msg )->get_node(1)->getChildNode(1)->getValue,
357 explanation => $xp->find( './m:explanation', $msg )->get_node(1)->getChildNode(1)->getValue,
358 });
359
360 0 ▶ if ( $xp->find( './m:source' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xp->find("./m:source")) 0 0 0
361 0 $err->source( $xp->find( './m:source', $msg )->get_node(1)->getChildNode(1)->getValue );
362 }
363  
364 0 push @errs, $err;
365 }
366 }
367  
368 0 return \@errs;
369 }
370  
371 1 ▶sub errorcount {
Subroutine errorcount: called CC=1 SCAR=0.0
Pod documented
372 1 shift->num_errors;
373 }
374  
375 0 ▶sub warningcount {
Subroutine warningcount: not called CC=1 SCAR=6.9
Pod documented
376 0 shift->num_warnings;
377 }
378  
379 0 ▶sub warnings {
Subroutine warnings: not called CC=9 SCAR=45.0
Pod documented
380 0 my $self = shift;
381  
382 0 ▶ unless ( $self->_http_method() eq 'GET' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_http_method eq "GET") 0 0 0
383 0 warn "You should set detailed when initalising if you intend to use the warnings method";
384 0 $self->_http_method( 'GET' );
385 0 $self->validate( $self->uri() );
386 }
387  
388  
389 0 eval { require XML::XPath; };
390 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
391 0 warn "XML::XPath must be installed in order to get warnings";
392 0 return undef;
393 }
394  
395 0 my $xp = XML::XPath->new( xml => $self->_content() );
396  
397 0 my @warnings;
398  
399 0 ▶ if ( $self->_output eq 'soap12' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_output eq 'soap12') { } 0 0 0
400 0 ▶ if ( ! $xp->findnodes('/env:Envelope') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xp->findnodes("/env:Envelope")) 0 0 0
401 0 return $self->validator_error( 'Result format does not appear to be SOAP' );
402 }
403 0 my @messages = $xp->findnodes( '/env:Envelope/env:Body/m:markupvalidationresponse/m:warnings/m:warninglist/m:warning' );
404  
405 0 foreach my $msg ( @messages ) {
406 0 my ($line, $col);
407  
408 0 ▶ if( ($line = $xp->findvalue('./m:line', $msg)) eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if (($line = $xp->findvalue("./m:line", $msg)) eq "") 0 0 0
409 0 $line = undef;
410 }
411  
412 0 ▶ if( ($col = $xp->findvalue('./m:col', $msg)) eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if (($col = $xp->findvalue("./m:col", $msg)) eq "") 0 0 0
413 0 $col = undef;
414 }
415  
416 0 my $warning = WebService::Validator::HTML::W3C::Warning->new({
417 line => $line,
418 col => $col,
419 msg => $xp->find( './m:message', $msg )->get_node(1)->getChildNode(1)->getValue,
420 });
421  
422 # we may not get a source element if, e.g the only error is a
423 # missing doctype so check first
424 0 ▶ if ( $xp->find( './m:source' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xp->find("./m:source")) 0 0 0
425 0 $warning->source( $xp->find( './m:source', $msg )->get_node(1)->getChildNode(1)->getValue );
426 }
427  
428 0 push @warnings, $warning;
429 }
430 0 return \@warnings;
431 } else {
432 0 return $self->validator_error( 'Warnings only available with SOAP output format' );
433  
434 }
435 }
436  
437 =head2 validator_error
438  
439 $error = $v->validator_error();
440  
441 Returns a string indicating why validation may not have occurred. This is not
442 the reason that a webpage was invalid. It is the reason that no meaningful
443 information about the attempted validation could be obtained. This is most
444 likely to be an HTTP error
445  
446 Possible values are:
447  
448 =over 4
449  
450 =item You need to supply a URI to validate
451  
452 You didn't pass a URI to the validate method
453  
454 =item You need to supply a URI with a scheme
455  
456 The URI you passed to validate didn't have a scheme on the front. The
457 W3C validator can't handle URIs like www.example.com but instead
458 needs URIs of the form http://www.example.com/.
459  
460 =item Not a W3C Validator or Bad URI
461  
462 The URI did not return the headers that WebService::Validator::HTML::W3C
463 relies on so it is likely that there is not a W3C Validator at that URI.
464 The other possibility is that it didn't like the URI you provided. Sadly
465 the Validator doesn't give very useful feedback on this at the moment.
466  
467 =item Could not contact validator
468  
469 WebService::Validator::HTML::W3C could not establish a connection to the URI.
470  
471 =item Did not get a sensible result from the validator
472  
473 Should never happen and most likely indicates a problem somewhere but
474 on the off chance that WebService::Validator::HTML::W3C is unable to make
475 sense of the response from the validator you'll get this error.
476  
477 =item Result format does not appear to be SOAP|XML
478  
479 If you've asked for detailed results and the reponse from the validator
480 isn't in the expected format then you'll get this error. Most likely to
481 happen if you ask for SOAP output from a validator that doesn't
482 support that format.
483  
484 =item You need to provide a uri, string or file to validate
485  
486 You've passed in a hash ( or in fact more than one argument ) to validate
487 but the hash does not contain one of the three expected keys.
488  
489 =back
490  
491 =cut
492  
493 6 ▶sub validator_error {
Subroutine validator_error: called CC=2 SCAR=6.9
Pod documented
494 6 my $self = shift;
495 6 my $validator_error = shift;
496  
497 6 ▶ if ( defined $validator_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $validator_error) 3 3 6
498 3 $self->{'validator_error'} = $validator_error;
499 3 return 0;
500 }
501  
502 3 return $self->{'validator_error'};
503 }
504  
505 =head2 validator_uri
506  
507 $uri = $v->validator_uri();
508 $v->validator_uri('http://validator.w3.org/check');
509  
510 Returns or sets the URI of the validator to use. Please note that you need
511 to use the full path to the validator cgi.
512  
513  
514 =head2 http_timeout
515  
516 $timeout = $v->http_timeout();
517 $v->http_timeout(10);
518  
519 Returns or sets the timeout for the HTTP request.
520  
521 =cut
522  
523 0 ▶sub _construct_uri {
Subroutine _construct_uri: not called CC=1 SCAR=6.9
524 0 my $self = shift;
525 0 my $uri_to_validate = shift;
526  
527 # creating the HTTP query string with all parameters
528 0 my $req_uri =
529 join ( '', "?uri=", uri_escape($uri_to_validate), ";output=", $self->_output );
530  
531 0 return $self->validator_uri . $req_uri;
532 }
533  
534 3 ▶sub _parse_validator_response {
Subroutine _parse_validator_response: called CC=6 SCAR=18.3
535 3 my $self = shift;
536 3 my $response = $self->_response();
537  
538 3 my $valid = $response->header('X-W3C-Validator-Status');
539 3 my $valid_err_num = $response->header('X-W3C-Validator-Errors');
540 3 $self->num_warnings($response->header('X-W3C-Validator-Warnings'));
541  
542 # remove non digits to fix output bug in some versions of validator
543 3 ▶ $valid_err_num =~ s/\D+//g if $valid_err_num;
Branch: 1 branch
BranchTrueFalseTotal
if $valid_err_num 2 1 3
544  
545 3 ▶ if ( $valid and $valid_err_num ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($valid and $valid_err_num) { } 2 1 3
elsif (not defined $valid) { } 0 1 1
elsif ($valid =~ /\bvalid\b/i) { } 1 0 1
Condition66%2/3
$valid and $valid_err_num
!ll&&!rl&&r
012
MC/DC50%1/2
$valid and $valid_err_num
$valid $valid_err_num
Truth table66%2/3
A and B
A= $validB= $valid_err_num
ABresult
0X0
100
111
546 2 $self->is_valid(0);
547 2 $self->num_errors($valid_err_num);
548 2 return 1;
549 }
550 elsif ( !defined $valid ) {
551 0 return $self->validator_error('Not a W3C Validator or Bad URI');
552 }
553 elsif ( $valid =~ /\bvalid\b/i ) {
554 1 $self->is_valid(1);
555 1 $self->num_errors($valid_err_num);
556 1 return 1;
557 }
558  
559 0 return $self->validator_error(
560 'Did not get a sensible result from the Validator');
561 }
562  
563 0 ▶sub _get_request {
Subroutine _get_request: not called CC=4 SCAR=30.0
564 0 my $self = shift;
565 0 my $uri = shift;
566  
567 0 ▶ if ( ref $uri ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $uri) { } 0 0 0
568 0 ▶ if ( $uri->{ file } ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($uri->{'file'}) { } 0 0 0
elsif ($uri->{'markup'}) { } 0 0 0
569 return POST $self->validator_uri,
570 Content_Type => 'form-data',
571 Content => [
572 output => $self->_output,
573 0 uploaded_file => [ $uri->{ file } ],
574 ];
575 } elsif ( $uri->{ markup } ) {
576 return POST $self->validator_uri,
577 Content_Type => 'form-data',
578 Content => [
579 output => $self->_output,
580 fragment => $uri->{ markup },
581 0 ];
582 }
583 } else {
584 0 return new HTTP::Request( $self->_http_method(), $self->_construct_uri( $uri ) );
585 }
586 }
587
588 16 1;
589  
590 __END__
↑ Summary W3C/Error.pm »