1#!/usr/bin/perl 2 3use strict; 4use warnings; 5use WebService::Validator::HTML::W3C; 6 7=head1 DESCRIPTION 8 9This script takes files as arguments and then submits those file 10to the W3C validator. It will print out a line for each 11file stating if it is valid or otherwise. For the invalid files it will 12also print out the errors returned by the validator. 13 14=cut 15 16my $v = WebService::Validator::HTML::W3C->new( 17 # you should probably install a local validator if you 18 # are indenting to run this against a lot of files and 19 # then uncomment this line and change the uri 20 # validator_uri => 'http://localhost/w3c-validator/check', 21 detailed => 1 22) or die "failed to init validator object"; 23 24my $invalid_found = 0 ; 25 26for my $file ( @ARGV ) { 27 if ( $v->validate_file( $file ) ) { 28 if ( $v->is_valid ) { 29 print "$file: valid\n"; 30 } else { 31 $invalid_found = 1 ; 32 print "$file: invalid\n"; 33 for my $err ( @{ $v->errors } ) { 34 printf(" line: %s, col: %s\n error: %s\n\n", 35 $err->line, $err->col, $err->msg); 36 } 37 } 38 } else { 39 die "failed to validate $file: " . $v->validator_error . "\n"; 40 } 41 print "\n" . '-' x 60 . "\n"; 42 # sleep between files so as not to hammer the validator 43 sleep 1; 44} 45 46exit( $invalid_found ) ; 47 48