WebService-Validator-HTML-W3C-0.28000755001750001750 011705612370 16575 5ustar00struanstruan000000000000WebService-Validator-HTML-W3C-0.28/MANIFEST000444001750001750 103011705612370 20055 0ustar00struanstruan000000000000Build.PL Changes examples/validate_files_in_dir.pl lib/WebService/Validator/HTML/W3C.pm lib/WebService/Validator/HTML/W3C/Error.pm lib/WebService/Validator/HTML/W3C/Warning.pm Makefile.PL MANIFEST This list of files META.yml README t/01load.t t/02validate.t t/03invalid.t t/04bad_validator.t t/05options.t t/06detailed.t t/07no_xpath.t t/08no_detailed.t t/09scalar.t t/10file.t t/11detailed_soap.t t/12proxy.t t/13soap_wrong_format.t t/14warnings.t t/15alt_interface.t t/99_pod.t t/99_podcover.t t/invalid.html t/valid.html META.json WebService-Validator-HTML-W3C-0.28/META.json000444001750001750 255511705612370 20362 0ustar00struanstruan000000000000{ "abstract" : "Access the W3Cs online HTML validator", "author" : [ "Struan Donald Estruan@cpan.orgE" ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.112150", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "WebService-Validator-HTML-W3C", "prereqs" : { "build" : { "requires" : { "Test::More" : 0 } }, "configure" : { "requires" : { "Module::Build" : "0.38" } }, "runtime" : { "requires" : { "Class::Accessor" : 0, "LWP" : 0 } } }, "provides" : { "WebService::Validator::HTML::W3C" : { "file" : "lib/WebService/Validator/HTML/W3C.pm", "version" : "0.28" }, "WebService::Validator::HTML::W3C::Error" : { "file" : "lib/WebService/Validator/HTML/W3C/Error.pm", "version" : 0 }, "WebService::Validator::HTML::W3C::Warning" : { "file" : "lib/WebService/Validator/HTML/W3C/Warning.pm", "version" : 0 } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.28" } WebService-Validator-HTML-W3C-0.28/README000444001750001750 207711705612370 17620 0ustar00struanstruan000000000000WebService::Validator::HTML::W3C provides access to the W3Cs online HTML validator. It's nothing to do with the W3C so please don't report any problems with it to them. Also, please use it wisely and don't abuse the W3Cs validator service. If you need to do a lot of validation consider downloading and installing the Validator on your own machine. PREREQUISITES Class::Accessor XML::XPath if you want detailed information on errors. INSTALLATION You should be able to install WebService::Validator::HTML::W3C in any of the usual ways: perl -MCPAN -e 'install WebService::Validator::HTML::W3C' or perl -MCPANPLUS -e 'install WebService::Validator::HTML::W3C' or perl Makefile.PL make make test make install or perl Build.PL ./Build ./Build test ./Build install TESTS Some of the tests for this module require a live internet connection. If one isn't present then they'll be skipped. Test::Without:Module is required for one of the tests. If it's not there then that test should be skipped. For everything else see the POD. $Id$ WebService-Validator-HTML-W3C-0.28/Build.PL000444001750001750 233411705612370 20230 0ustar00struanstruan000000000000use strict; use Module::Build; my $filename = "t/SKIPXPATH"; eval { require XML::XPath; }; if ($@) { open( F, ">$filename" ) or die "Can't create $filename"; close F; print <$filename" ) or die "Can't create $filename"; close F; } else { unlink $filename; } $filename = "t/SKIPWARN"; eval { require Test::Warn; }; if ($@) { open( F, ">$filename" ) or die "Can't create $filename"; close F; } else { unlink $filename; } Module::Build ->new( module_name => "WebService::Validator::HTML::W3C", license => 'perl', requires => { 'Class::Accessor' => 0, 'LWP' => '0', }, build_requires => { 'Test::More' => 0, }, ) ->create_build_script; WebService-Validator-HTML-W3C-0.28/META.yml000444001750001750 154111705612370 20204 0ustar00struanstruan000000000000--- abstract: 'Access the W3Cs online HTML validator' author: - 'Struan Donald Estruan@cpan.orgE' build_requires: Test::More: 0 configure_requires: Module::Build: 0.38 dynamic_config: 1 generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.112150' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: WebService-Validator-HTML-W3C provides: WebService::Validator::HTML::W3C: file: lib/WebService/Validator/HTML/W3C.pm version: 0.28 WebService::Validator::HTML::W3C::Error: file: lib/WebService/Validator/HTML/W3C/Error.pm version: 0 WebService::Validator::HTML::W3C::Warning: file: lib/WebService/Validator/HTML/W3C/Warning.pm version: 0 requires: Class::Accessor: 0 LWP: 0 resources: license: http://dev.perl.org/licenses/ version: 0.28 WebService-Validator-HTML-W3C-0.28/Makefile.PL000444001750001750 203011705612370 20677 0ustar00struanstruan000000000000use ExtUtils::MakeMaker; my $filename = "t/SKIPXPATH"; eval { require XML::XPath; }; if ($@) { open( F, ">$filename" ) or die "Can't create $filename"; close F; print <$filename" ) or die "Can't create $filename"; close F; } else { unlink $filename; } $filename = "t/SKIPWARN"; eval { require Test::Warn; }; if ($@) { open( F, ">$filename" ) or die "Can't create $filename"; close F; } else { unlink $filename; } WriteMakefile ('DISTNAME' => 'WebService-Validator-HTML-W3C', 'VERSION' => '0.03', 'PL_FILES' => {}, 'PREREQ_PM' => { 'Class::Accessor' => 0, 'LWP' => '0', 'Test::More' => '0', }, ); WebService-Validator-HTML-W3C-0.28/Changes000444001750001750 726611705612370 20240 0ustar00struanstruan0000000000000.28 Wednesday 18th January 2012 - Fix RT #74123 - Fix RT #69998 0.27 Sunday 31st July 2011 - include patch to use source and explanation from SOAP output - small fixes to author tests 0.26 Monday 7th September 2009 - Suppress and test warning in no XML::XPath installed RT #47960 0.25 Thursday 23rd August 2009 - change proxy port in test to stop clash with default squid port - update columns in detailed output tests run under TST_AUTHOR to match validator change RT #47960 0.24 Monday 25th August 2008 - fix 06detailed.t which was failing when not run under TEST_AUTHOR :( 0.23 Sunday 24th August 2008 - add in msgid and explanation methods to Error object partly courtesy of Matt Ryder - update author tests in line with changes to validator output - made soap12 the default output format. - added few things to make interface more comaptible with CSS validator module 0.22 Tuesday 28th August 2007 - Fixed some typos - thanks to William McKee for pointing them out 0.21 Tuesday 7th August 2007 - updated tests to fix failures when XML::XPath not installed due to trying to skip wrong number of tests. 0.20 Sunday 5th August 2007 - updated tests to use hardcoded responses where possible to stop failures caused by changed error messages - full test suite only run if $ENV{'TEST_AUTHOR'} set - some internals refactoring to support test changes 0.19 Tuesday 17th April 2007 - updated t/14warnings.t in line with changed validator error - also make test a little less likely to break in future - added in examples directory for cpants game related reasons 0.18 Thursday 5th April 2007 - skip the right number of tests for 03invalid.t - make 04bad_validtor.t a bit more robust of can't contact fake validator - update 11detailed_soap.t to reflect changes in validator error messages 0.17 Saturday 13th January 2007 - skip the right number of test of no xpath for 13soap_wrong_format.t 0.16 Saturday 13th January 2007 - Added in custom user agent support courtesy of Chris Dolan 0.15 Monday 18th December 2006 - Updated tests so they don't fail if the validator is unreachable 0.14 Saturday 4th November 2006 - Updated wrong format error tests as non beta validator now supports SOAP - Removes non digits from header error count to work round validator bug 0.13 Tuesday 25th April 2006 - Added in warnings method to use extra info from SOAP output - Makes stab at catching incorrect output for detailed methods 0.12 Sunday 5th March 2006 - added in Proxy support courtesy of Carl Vincent 0.11 Saturday 25th February 2006 - added output option and asociated SOAP output support 0.10 Monday 12th September 2005 - scalar and file tests now skip if no connection - fixed typo also from rt.cpan.org #14480 0.09 Wednesday 7th September 2005 - Added in pod coverage test - fixed doc bug -> rt.cpan.org #14480 0.08 Saturday 27th August 2005 - Fixed broken scalar validation 0.07 Wednesday 17th July 2005 - Fixed broken test 0.06 Tuesday 16th November 2004 - Can now validate scalars and local files - Updated Makefile to check for Test::Warn 0.05 Tuesday 9th November 2004 - Actually document the detailed option :( - Fix a few bugs in the SYNOPSIS code 0.04 Tuesday 9th November 2004 - Update docs to say you should enable detailed if using errors method - Update errors method to do the right thing if detailed not enabled 0.03 Sunday 9th May 2004 - Fix to failing test after new validator release 0.02 Tuesday 13th January 2004 - Some documentation patches and generally tidying up 0.01 Tuesday 15th November 2003 - Initial release WebService-Validator-HTML-W3C-0.28/lib000755001750001750 011705612370 17343 5ustar00struanstruan000000000000WebService-Validator-HTML-W3C-0.28/lib/WebService000755001750001750 011705612370 21401 5ustar00struanstruan000000000000WebService-Validator-HTML-W3C-0.28/lib/WebService/Validator000755001750001750 011705612370 23326 5ustar00struanstruan000000000000WebService-Validator-HTML-W3C-0.28/lib/WebService/Validator/HTML000755001750001750 011705612370 24072 5ustar00struanstruan000000000000WebService-Validator-HTML-W3C-0.28/lib/WebService/Validator/HTML/W3C.pm000444001750001750 4717111705612370 25213 0ustar00struanstruan000000000000# $Id$ package WebService::Validator::HTML::W3C; use strict; use base qw( Class::Accessor ); use LWP::UserAgent; use HTTP::Request::Common 'POST'; use URI::Escape; use WebService::Validator::HTML::W3C::Error; use WebService::Validator::HTML::W3C::Warning; __PACKAGE__->mk_accessors( qw( http_timeout validator_uri proxy ua _http_method is_valid num_errors num_warnings uri _content _output _response ) ); use vars qw( $VERSION $VALIDATOR_URI $HTTP_TIMEOUT ); $VERSION = 0.28; $VALIDATOR_URI = 'http://validator.w3.org/check'; $HTTP_TIMEOUT = 30; =head1 NAME WebService::Validator::HTML::W3C - Access the W3Cs online HTML validator =head1 SYNOPSIS use WebService::Validator::HTML::W3C; my $v = WebService::Validator::HTML::W3C->new( detailed => 1 ); if ( $v->validate("http://www.example.com/") ) { if ( $v->is_valid ) { printf ("%s is valid\n", $v->uri); } else { printf ("%s is not valid\n", $v->uri); foreach my $error ( @{$v->errors} ) { printf("%s at line %d\n", $error->msg, $error->line); } } } else { printf ("Failed to validate the website: %s\n", $v->validator_error); } =head1 DESCRIPTION WebService::Validator::HTML::W3C provides access to the W3C's online Markup validator. As well as reporting on whether a page is valid it also provides access to a detailed list of the errors and where in the validated document they occur. =head1 METHODS =head2 new my $v = WebService::Validator::HTML::W3C->new(); Returns a new instance of the WebService::Validator::HTML::W3C object. There are various options that can be set when creating the Validator object like so: my $v = WebService::Validator::HTML::W3C->new( http_timeout => 20 ); =over 4 =item validator_uri 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. =item ua 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 and C arguments are ignored. =item http_timeout How long (in seconds) to wait for the HTTP connection to timeout when contacting the validator. By default this is 30 seconds. =item detailed 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. =item proxy An HTTP proxy to use when communicating with the validation service. =item output Controls which output format is used. Can be either xml or soap12. The default is soap12 as the XML format is deprecated and is likely to be removed in the future. The default will always work so unless you're using a locally installed Validator you can safely ignore this. =back =cut sub new { my $ref = shift; my $class = ref $ref || $ref; my $obj = {}; bless $obj, $class; $obj->_init(@_); return $obj; } sub _init { my $self = shift; my %args = @_; $self->http_timeout( $args{http_timeout} || $HTTP_TIMEOUT ); $self->validator_uri( $args{validator_uri} || $VALIDATOR_URI ); $self->ua( $args{ua} ); $self->_http_method( $args{detailed} ? 'GET' : 'HEAD' ); $self->_output( $args{output} || 'soap12' ); $self->proxy( $args{proxy} || '' ); } =head2 validate $v->validate( 'http:://www.example.com/' ); Validate a URI. Returns 0 if the validation fails (e.g if the validator cannot be reached), otherwise 1. =head2 validate_file $v->validate_file( './file.html' ); 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. =head2 validate_markup $v->validate_markup( $markup ); Validate a scalar containing HTML. =head2 Alternate interface 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. $v->validate( uri => 'http://example.com/' ); $v->validate( string => $markup ); $v->validate( file => './file.html' ); =cut sub validate_file { my $self = shift; my $file = shift; return $self->validator_error("You need to supply a file to validate") unless $file; return $self->_validate( { file => $file } ); } sub validate_markup { my $self = shift; my $markup = shift; return $self->validator_error("You need to supply markup to validate") unless $markup; return $self->_validate( { markup => $markup } ); } sub validate { my $self = shift; my ( %opts, $uri ); if ( scalar( @_ ) > 1 ) { %opts = @_; if ( $opts{ 'uri' } ) { $uri = $opts{ 'uri' }; } elsif ( $opts{ 'string' } ) { return $self->validate_markup( $opts{ 'string' } ); } elsif( $opts{ 'file' } ) { return $self->validate_file( $opts{ 'file' } ); } else { return $self->validator_error( "You need to provide a uri, string or file to validate" ); } } else { $uri = shift; } return $self->validator_error("You need to supply a URI to validate") unless $uri; return $self->validator_error("You need to supply a URI scheme (e.g http)") unless $uri =~ m(^.*?://); return $self->_validate( $uri ); } sub _validate { my $self = shift; my $uri = shift; my $uri_orig = $uri; $self->uri($uri_orig); my $ua = $self->ua; if ( ! $ua ) { $ua = LWP::UserAgent->new( agent => __PACKAGE__ . "/$VERSION", timeout => $self->http_timeout ); if ( $self->proxy ) { $ua->proxy( 'http', $self->proxy ); } } my $request = $self->_get_request( $uri ); my $response = $ua->request($request); if ( $response->is_success ) # not an error, we could contact the server { # set both valid and error number according to response $self->_response( $response ); my $res = $self->_parse_validator_response(); $self->_content( $response->content() ) if $self->_http_method() !~ /HEAD/; # we know the validator has been able to (in)validate if # $self->valid is not NULL if ( $res ) { return 1; } else { return 0; } } else { return $self->validator_error('Could not contact validator'); } } =head2 is_valid $v->is_valid; Returns true (1) if the URI validated otherwise 0. =head2 uri $v->uri(); Returns the URI of the last page on which validation succeeded. =head2 num_errors $num_errors = $v->num_errors(); Returns the number of errors that the validator encountered. =head2 errorcount Synonym for num_errors. There to match CSS Validator interface. =head2 warningcount $num_errors = $v->warningcount(); Returns the number of warnings that the validator encountered. =head2 errors $errors = $v->errors(); foreach my $err ( @$errors ) { printf("line: %s, col: %s\n\terror: %s\n", $err->line, $err->col, $err->msg); } Returns an array ref of WebService::Validator::HTML::W3C::Error objects. These have line, col and msg methods that return a line number, a column in that line and the error that occurred at that point. Note that you need XML::XPath for this to work and you must have initialised WebService::Validator::HTML::W3C with the detailed option. If you have not set the detailed option a warning will be issued, the detailed option will be set and a second request made to the validator in order to fetch the required information. If there was a problem processing the detailed information then this method will return 0. =head2 warnings $warnings = $v->warnings(); Works exactly the same as errors only returns an array ref of WebService::Validator::HTML::W3C::Warning objects. In all other respects it's the same. =cut sub errors { my $self = shift; return undef unless $self->num_errors(); unless ( $self->_http_method() eq 'GET' ) { warn "You should set detailed when initalising if you intend to use the errors method"; $self->_http_method( 'GET' ); $self->validate( $self->uri() ); } my @errs; eval { require XML::XPath; }; if ($@) { warn "XML::XPath must be installed in order to get detailed errors"; return undef; } my $xp = XML::XPath->new( xml => $self->_content() ); if ( $self->_output eq 'xml' ) { if ( ! $xp->findnodes('/result') ) { return $self->validator_error( 'Result format does not appear to be XML' ); } my @messages = $xp->findnodes('/result/messages/msg'); foreach my $msg (@messages) { my $err = WebService::Validator::HTML::W3C::Error->new({ line => $msg->getAttribute('line'), col => $msg->getAttribute('col'), msg => $msg->getChildNode(1)->getValue(), }); push @errs, $err; } } else { # assume soap... if ( ! $xp->findnodes('/env:Envelope') ) { return $self->validator_error( 'Result format does not appear to be SOAP' ); } my @messages = $xp->findnodes( '/env:Envelope/env:Body/m:markupvalidationresponse/m:errors/m:errorlist/m:error' ); foreach my $msg ( @messages ) { my $err = WebService::Validator::HTML::W3C::Error->new({ line => $xp->find( './m:line', $msg )->get_node(1)->getChildNode(1)->getValue, col => $xp->find( './m:col', $msg )->get_node(1)->getChildNode(1)->getValue, msg => $xp->find( './m:message', $msg )->get_node(1)->getChildNode(1)->getValue, msgid => $xp->find( './m:messageid', $msg )->get_node(1)->getChildNode(1)->getValue, explanation => $xp->find( './m:explanation', $msg )->get_node(1)->getChildNode(1)->getValue, }); if ( $xp->find( './m:source' ) ) { $err->source( $xp->find( './m:source', $msg )->get_node(1)->getChildNode(1)->getValue ); } push @errs, $err; } } return \@errs; } sub errorcount { shift->num_errors; } sub warningcount { shift->num_warnings; } sub warnings { my $self = shift; unless ( $self->_http_method() eq 'GET' ) { warn "You should set detailed when initalising if you intend to use the warnings method"; $self->_http_method( 'GET' ); $self->validate( $self->uri() ); } eval { require XML::XPath; }; if ($@) { warn "XML::XPath must be installed in order to get warnings"; return undef; } my $xp = XML::XPath->new( xml => $self->_content() ); my @warnings; if ( $self->_output eq 'soap12' ) { if ( ! $xp->findnodes('/env:Envelope') ) { return $self->validator_error( 'Result format does not appear to be SOAP' ); } my @messages = $xp->findnodes( '/env:Envelope/env:Body/m:markupvalidationresponse/m:warnings/m:warninglist/m:warning' ); foreach my $msg ( @messages ) { my ($line, $col); if( ($line = $xp->findvalue('./m:line', $msg)) eq "") { $line = undef; } if( ($col = $xp->findvalue('./m:col', $msg)) eq "") { $col = undef; } my $warning = WebService::Validator::HTML::W3C::Warning->new({ line => $line, col => $col, msg => $xp->find( './m:message', $msg )->get_node(1)->getChildNode(1)->getValue, }); # we may not get a source element if, e.g the only error is a # missing doctype so check first if ( $xp->find( './m:source' ) ) { $warning->source( $xp->find( './m:source', $msg )->get_node(1)->getChildNode(1)->getValue ); } push @warnings, $warning; } return \@warnings; } else { return $self->validator_error( 'Warnings only available with SOAP output format' ); } } =head2 validator_error $error = $v->validator_error(); Returns a string indicating why validation may not have occurred. This is not the reason that a webpage was invalid. It is the reason that no meaningful information about the attempted validation could be obtained. This is most likely to be an HTTP error Possible values are: =over 4 =item You need to supply a URI to validate You didn't pass a URI to the validate method =item You need to supply a URI with a scheme The URI you passed to validate didn't have a scheme on the front. The W3C validator can't handle URIs like www.example.com but instead needs URIs of the form http://www.example.com/. =item Not a W3C Validator or Bad URI The URI did not return the headers that WebService::Validator::HTML::W3C relies on so it is likely that there is not a W3C Validator at that URI. The other possibility is that it didn't like the URI you provided. Sadly the Validator doesn't give very useful feedback on this at the moment. =item Could not contact validator WebService::Validator::HTML::W3C could not establish a connection to the URI. =item Did not get a sensible result from the validator Should never happen and most likely indicates a problem somewhere but on the off chance that WebService::Validator::HTML::W3C is unable to make sense of the response from the validator you'll get this error. =item Result format does not appear to be SOAP|XML If you've asked for detailed results and the reponse from the validator isn't in the expected format then you'll get this error. Most likely to happen if you ask for SOAP output from a validator that doesn't support that format. =item You need to provide a uri, string or file to validate You've passed in a hash ( or in fact more than one argument ) to validate but the hash does not contain one of the three expected keys. =back =cut sub validator_error { my $self = shift; my $validator_error = shift; if ( defined $validator_error ) { $self->{'validator_error'} = $validator_error; return 0; } return $self->{'validator_error'}; } =head2 validator_uri $uri = $v->validator_uri(); $v->validator_uri('http://validator.w3.org/check'); Returns or sets the URI of the validator to use. Please note that you need to use the full path to the validator cgi. =head2 http_timeout $timeout = $v->http_timeout(); $v->http_timeout(10); Returns or sets the timeout for the HTTP request. =cut sub _construct_uri { my $self = shift; my $uri_to_validate = shift; # creating the HTTP query string with all parameters my $req_uri = join ( '', "?uri=", uri_escape($uri_to_validate), ";output=", $self->_output ); return $self->validator_uri . $req_uri; } sub _parse_validator_response { my $self = shift; my $response = $self->_response(); my $valid = $response->header('X-W3C-Validator-Status'); my $valid_err_num = $response->header('X-W3C-Validator-Errors'); $self->num_warnings($response->header('X-W3C-Validator-Warnings')); # remove non digits to fix output bug in some versions of validator $valid_err_num =~ s/\D+//g if $valid_err_num; if ( $valid and $valid_err_num ) { $self->is_valid(0); $self->num_errors($valid_err_num); return 1; } elsif ( !defined $valid ) { return $self->validator_error('Not a W3C Validator or Bad URI'); } elsif ( $valid =~ /\bvalid\b/i ) { $self->is_valid(1); $self->num_errors($valid_err_num); return 1; } return $self->validator_error( 'Did not get a sensible result from the Validator'); } sub _get_request { my $self = shift; my $uri = shift; if ( ref $uri ) { if ( $uri->{ file } ) { return POST $self->validator_uri, Content_Type => 'form-data', Content => [ output => $self->_output, uploaded_file => [ $uri->{ file } ], ]; } elsif ( $uri->{ markup } ) { return POST $self->validator_uri, Content_Type => 'form-data', Content => [ output => $self->_output, fragment => $uri->{ markup }, ]; } } else { return new HTTP::Request( $self->_http_method(), $self->_construct_uri( $uri ) ); } } 1; __END__ =head1 OTHER MODULES Please note that there is also an official W3C module that is part of the L distribution. However that module is not very useful outside the constraints of that package. WebService::Validator::HTML::W3C is meant as a more general way to access the W3C Validator. L uses nsgmls to validate against the W3Cs DTDs. You have to fetch the relevant DTDs and so on. There is also the L based L which mostly checks for known tags rather than XML/HTML validity. L provides the same functionality as this module for the W3C's CSS validator. =head1 IMPORTANT This module is not in any way associated with the W3C so please do not report any problems with this module to them. Also please remember that the online Validator is a shared resource so do not abuse it. This means sleeping between requests. If you want to do a lot of testing against it then please consider downloading and installing the Validator software which is available from the W3C. Debian testing users will also find that it is available via apt-get. =head1 BUGS While the interface to the Validator is fairly stable it may be updated. I will endeavour to track any changes with this module so please check on CPAN for new versions if you find things break. Also note that this module is only guaranteed to work with the currently stable version of the validator. It will most likely work with any Beta versions but don't rely on it. If in doubt please try and run the test suite before reporting bugs. Note that in order to run tests against the validator service you will need to have a connection to the internet and also set an environment variable called TEST_AUTHOR. That said I'm very happy to hear about bugs. All the more so if they come with patches ;). Please use L for filing bug reports, and indeed feature requests. The code can also be found on L. =head1 THANKS To the various people on the code review ladder mailing list who provided useful suggestions. Carl Vincent provided a patch to allow for proxy support. Chris Dolan provided a patch to allow for custom user agents. Matt Ryder provided a patch for support of the explanations in the SOAP output. =head1 SUPPORT author email or via L. =head1 AUTHOR Struan Donald Estruan@cpan.orgE L =head1 COPYRIGHT Copyright (C) 2003-2008 Struan Donald. All rights reserved. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO perl(1). =cut WebService-Validator-HTML-W3C-0.28/lib/WebService/Validator/HTML/W3C000755001750001750 011705612370 24466 5ustar00struanstruan000000000000WebService-Validator-HTML-W3C-0.28/lib/WebService/Validator/HTML/W3C/Error.pm000444001750001750 136211705612370 26254 0ustar00struanstruan000000000000# $Id$ package WebService::Validator::HTML::W3C::Error; use strict; use base qw(Class::Accessor); __PACKAGE__->mk_accessors( qw( line col msg msgid explanation source ) ); 1; __END__ =head1 NAME WebService::Validator::HTML::W3C::Error - Error messages from the W3Cs online Validator =head1 DESCRIPTION This is a wee internal module for WebService::Validator::HTML::W3C. It has three methods: line, col and msg which return the line number, column number and the error that occured at that location in a validated page. If you are using the soap output then you get additional information in the msgid and explanation methods. =head1 SEE ALSO L =head1 AUTHOR Struan Donald Estruan@cpan.orgE =cut WebService-Validator-HTML-W3C-0.28/lib/WebService/Validator/HTML/W3C/Warning.pm000444001750001750 124611705612370 26571 0ustar00struanstruan000000000000# $Id: Error.pm 32 2003-11-26 13:52:18Z struan $ package WebService::Validator::HTML::W3C::Warning; use strict; use base qw(Class::Accessor); __PACKAGE__->mk_accessors( qw( line col msg source ) ); 1; __END__ =head1 NAME WebService::Validator::HTML::W3C::Warning - Warning messages from the W3Cs online Validator =head1 DESCRIPTION This is a wee internal module for WebService::Validator::HTML::W3C. It has three methods: line, col and msg which return the line number, column number and the warning that occured at that location in a validated page. =head1 SEE ALSO L =head1 AUTHOR Struan Donald Estruan@cpan.orgE =cut WebService-Validator-HTML-W3C-0.28/t000755001750001750 011705612370 17040 5ustar00struanstruan000000000000WebService-Validator-HTML-W3C-0.28/t/99_podcover.t000444001750001750 40011705612370 21476 0ustar00struanstruan000000000000use Test::More; eval "use Test::Pod::Coverage 0.08"; plan skip_all => "Test::Pod::Coverage 0.08 required for testing POD coverage" if $@; all_pod_coverage_ok( { also_private => [ qr/(?:_end|_start)$/, 'text', 'textflow', 'configure' ] }, 'pod coverage' ); WebService-Validator-HTML-W3C-0.28/t/11detailed_soap.t000444001750001750 663211705612370 22330 0ustar00struanstruan000000000000# $Id: 06detailed.t 41 2004-05-09 13:28:03Z struan $ use Test::More; use WebService::Validator::HTML::W3C; my $test_num = 7; if ( $ENV{ 'TEST_AUTHOR' } ) { $test_num = 8; } plan tests => $test_num; my $v = WebService::Validator::HTML::W3C->new( http_timeout => 10, detailed => 1, output => 'soap12', ); SKIP: { skip "XML::XPath not installed", $test_num if -f 't/SKIPXPATH'; ok($v, 'object created'); if ( $ENV{ 'TEST_AUTHOR' } ) { my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/invalid.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 6; } } ok ($r, 'page validated'); } else { $v->num_errors( 1 ); $v->_content( qq{ http://exo.org.uk/ http://qa-dev.w3.org/wmvs/HEAD/ -//W3C//DTD XHTML 1.0 Strict//EN iso-8859-1 true 1 11 7 end tag for "div" omitted, but OMITTAG NO was specified 70

You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".

]]>
>]]>
1 Character Encoding mismatch!
}); } my $err = $v->errors->[0]; isa_ok($err, 'WebService::Validator::HTML::W3C::Error'); is($err->line, 11, 'Correct line number'); is($err->col, 7, 'Correct column'); is($err->msgid, 70, 'Correct messageid' ); like($err->msg, qr/end tag for "div" omitted, but OMITTAG NO was specified/, 'Correct message'); like($err->explanation, qr/You may have neglected to close an element, or perhaps you meant to/, 'Correct explanation'); } WebService-Validator-HTML-W3C-0.28/t/04bad_validator.t000444001750001750 273211705612370 22325 0ustar00struanstruan000000000000# $Id$ use Test::More tests => 12; use WebService::Validator::HTML::W3C; my $v = WebService::Validator::HTML::W3C->new( validator_uri => 'http://exo.org.uk/cgi-bin/cgi-test.cgi'); ok($v, 'object created'); ok(!$v->validate(), 'fails with no uri passed'); is($v->validator_error(), 'You need to supply a URI to validate', 'you need to supply a uri error'); ok(!$v->validate('exo.org.uk/'), 'fails if no URI scheme'); is($v->validator_error(), 'You need to supply a URI scheme (e.g http)', 'you need to supply a scheme error'); is($v->validator_uri, 'http://exo.org.uk/cgi-bin/cgi-test.cgi', 'correct validator uri'); SKIP: { skip "TEST_AUTHOR environment variable not defined", 2 unless $ENV{ 'TEST_AUTHOR' }; ok(!$v->validate('http://exo.org.uk/code/www-w3c-validator/valid.html'), 'validation fails'); if ($v->validator_error eq "Could not contact validator") { skip "failed to contact bad validator", 1; } is($v->validator_error, 'Not a W3C Validator or Bad URI', 'not a W3C validator error'); } ok($v->validator_uri('http://doa.example.com/'), 'validator address changed'); is($v->validator_uri, 'http://doa.example.com/', 'correct validator uri'); SKIP: { skip "TEST_AUTHOR environment variable not defined", 2 unless $ENV{ 'TEST_AUTHOR' }; ok(!$v->validate('http://exo.org.uk/code/valid.html'), 'validation fails'); is($v->validator_error, 'Could not contact validator', 'validator unreachable error'); }WebService-Validator-HTML-W3C-0.28/t/07no_xpath.t000444001750001750 712311705612370 21354 0ustar00struanstruan000000000000# $Id$ use Test::More; BEGIN { my $num_tests = 3; if ( $ENV{ 'TEST_AUTHOR' } ) { $num_tests = 4; } # XML::XPath must be installed in order to get detailed errors plan tests => $num_tests; SKIP: { skip "no Test::Without::Module", $num_tests, if -f 't/SKIPWITHOUT'; require Test::Without::Module; import Test::Without::Module qw( XML::XPath ); use WebService::Validator::HTML::W3C; my $v = WebService::Validator::HTML::W3C->new( http_timeout => 10, detailed => 1, ); ok($v, 'object created'); if ( $ENV{ 'TEST_AUTHOR' } ) { my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/invalid.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 5; } } ok ($r, 'page validated'); } else { $v->num_errors( 1 ); $v->_content( qq{ http://exo.org.uk/code/www-w3c-validator/invalid.html Sat Oct 4 14:53:18 2003 Apache/1.3.28 (Unix) (Red-Hat/Linux) mod_ssl/2.8.15 OpenSSL/0.9.7a PHP/4.0.6 mod_perl/1.26 FrontPage/4.0.4.3 256 utf-8 -//W3C//DTD XHTML 1.0 Strict//EN <em>Note</em>: The Validator XML support has <a href="http://openjade.sf.net/doc/xml.htm" title="Limitations in Validator XML support">some limitations</a>. This interface is highly experimental and the output *will* change -- probably even several times -- before finished. Do *not* rely on it! See http://validator.w3.org:8001/docs/users.html#api-warning end tag for "div" omitted, but OMITTAG NO was specified start tag was here } ); } { my $warning = ''; local $SIG{__WARN__} = sub { $warning = shift; $warning =~ s/ at .*\n$//; }; $v->errors(); is $warning, "XML::XPath must be installed in order to get detailed errors", "missing XML::XPath error"; ok(!$v->errors(), 'no errors returned if no XML::XPath'); } } } WebService-Validator-HTML-W3C-0.28/t/08no_detailed.t000444001750001750 226111705612370 22002 0ustar00struanstruan000000000000# $Id$ use Test::More tests => 7; BEGIN { eval "use Test::Warn"; } SKIP: { use WebService::Validator::HTML::W3C; my $v = WebService::Validator::HTML::W3C->new( http_timeout => 10, ); skip "TEST_AUTHOR environment variable not defined", 7 unless $ENV{ 'TEST_AUTHOR'}; skip "Test:Warn not install", 7 if -f 't/SKIPWARN'; skip "XML::XPath not installed", 7 if -f 't/SKIPXPATH'; ok($v, 'object created'); my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/invalid.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 6; } } ok ($r, 'page validated'); my $err; warning_is { $err = $v->errors->[0]; } "You should set detailed when initalising if you intend to use the errors method", "set detailed warning"; isa_ok($err, 'WebService::Validator::HTML::W3C::Error'); is($err->line, 11, 'Correct line number'); is($err->col, 7, 'Correct column'); like($err->msg, qr/end tag for "div" omitted, but OMITTAG NO was specified/, 'Correct message'); } WebService-Validator-HTML-W3C-0.28/t/02validate.t000444001750001750 252011705612370 21314 0ustar00struanstruan000000000000# $Id$ use Test::More; use WebService::Validator::HTML::W3C; use HTTP::Response; if ( $ENV{ 'TEST_AUTHOR'} ) { plan tests => 7; } else { plan tests => 5; } my $v = WebService::Validator::HTML::W3C->new( ); ok($v, 'Object created'); is($v->validator_uri(), 'http://validator.w3.org/check', 'correct default validator uri'); if ( $ENV{ 'TEST_AUTHOR'} ) { my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/valid.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 5; } } ok($r, 'validates page'); } else { my $resp = HTTP::Response->parse( <_response( $resp ); $v->_parse_validator_response(); } ok($v->is_valid, 'page is valid'); is($v->num_errors, 0, 'no errors in valid page'); is($v->errors, undef, 'no information on errors returned'); if ( $ENV{ 'TEST_AUTHOR' } ) { is($v->uri, 'http://exo.org.uk/code/www-w3c-validator/valid.html', 'uri correct'); } WebService-Validator-HTML-W3C-0.28/t/14warnings.t000444001750001750 512611705612370 21363 0ustar00struanstruan000000000000# $Id: 06detailed.t 41 2004-05-09 13:28:03Z struan $ use Test::More; use WebService::Validator::HTML::W3C; my $test_num = 9; if ( $ENV{ 'TEST_AUTHOR' } ) { $test_num = 10; } plan tests => $test_num; my $v = WebService::Validator::HTML::W3C->new( http_timeout => 10, detailed => 1, output => 'soap12', ); SKIP: { skip "XML::XPath not installed", $test_num if -f 't/SKIPXPATH'; ok($v, 'object created'); if ( $ENV{ 'TEST_AUTHOR' } ) { my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/warning.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 5; } } ok ($r, 'page validated'); } else { $v->_content( qq{ http://exo.org.uk/code/www-w3c-validator/warning.html http://validator.w3.org/ utf-8 true 0 3 W04No Character Encoding Found! Falling back to UTF-8. W09No DOCTYPE found! Attempting validation with XHTML 1.0 Transitional. W27No Character encoding declared at document level }); } my $err = $v->warnings->[1]; isa_ok($err, 'WebService::Validator::HTML::W3C::Warning'); is($err->line, undef, 'Correct line number'); is($err->col, undef, 'Correct column'); like($err->msg, qr/No DOCTYPE found! Attempting validation with XHTML 1.0/, 'Correct message'); $err = $v->warnings->[2]; isa_ok($err, 'WebService::Validator::HTML::W3C::Warning'); is($err->line, undef, 'Correct line number'); is($err->col, undef, 'Correct column'); like($err->msg, qr/No Character encoding declared at document level/, 'Correct message'); } WebService-Validator-HTML-W3C-0.28/t/invalid.html000444001750001750 40011705612370 21463 0ustar00struanstruan000000000000
WebService-Validator-HTML-W3C-0.28/t/10file.t000444001750001750 215511705612370 20445 0ustar00struanstruan000000000000# $Id$ use Test::More tests => 8; use WebService::Validator::HTML::W3C; my $v = WebService::Validator::HTML::W3C->new( http_timeout => 10, ); SKIP: { skip "TEST_AUTHOR environment variable not defined", 8 unless $ENV{ 'TEST_AUTHOR' }; ok($v, 'object created'); ok( !$v->validate_file(), 'fails if no file' ); is( $v->validator_error(), 'You need to supply a file to validate', 'you need to supply a file error' ); my $r = $v->validate_file( 't/valid.html' ); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 5; } } ok($r, 'validated valid file'); ok($v->is_valid(), 'valid file is valid'); $r = $v->validate_file( 't/invalid.html' ); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 3; } } ok( $r, 'validated invalid file'); ok( !$v->is_valid(), 'invalid file is invalid' ); is( $v->num_errors(), 1, 'correct number of errors'); } WebService-Validator-HTML-W3C-0.28/t/15alt_interface.t000444001750001750 416011705612370 22331 0ustar00struanstruan000000000000# $Id$ use Test::More tests => 9; use WebService::Validator::HTML::W3C; use HTTP::Response; my $v = WebService::Validator::HTML::W3C->new( ); ok ($v, 'object created'); if ( $ENV{ 'TEST_AUTHOR' } ) { my $r = $v->validate( uri => 'http://exo.org.uk/code/www-w3c-validator/invalid.html' ); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 2; } } } else { my $resp = HTTP::Response->parse( <_response( $resp ); $v->_parse_validator_response(); } ok (!$v->is_valid, 'page is not valid'); is ($v->errorcount, 1, 'correct number of errors'); SKIP: { skip "TEST_AUTHOR environment variable not defined", 4 unless $ENV{ 'TEST_AUTHOR' }; my $valid = qq{ }; my $r = $v->validate( string => $valid ); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 2; } } ok($r, 'validated valid scalar'); ok($v->is_valid(), 'valid scalar is valid'); $r = $v->validate( file => 't/valid.html' ); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 2; } } ok($r, 'validated valid file'); ok($v->is_valid(), 'valid file is valid'); } ok( !$v->validate( wrong => 'wrong' ), 'returns false is pass in wrong arguments'); is( $v->validator_error, 'You need to provide a uri, string or file to validate', 'correct error about wrong arguments' ); WebService-Validator-HTML-W3C-0.28/t/09scalar.t000444001750001750 320111705612370 20774 0ustar00struanstruan000000000000# $Id$ use Test::More tests => 8; use WebService::Validator::HTML::W3C; my $valid = qq{ }; my $invalid = qq{
}; my $v = WebService::Validator::HTML::W3C->new( http_timeout => 10, ); SKIP: { skip "TEST_AUTHOR environment variable not defined", 8 unless $ENV{ 'TEST_AUTHOR' }; ok($v, 'object created'); ok( !$v->validate_markup(), 'fails if no markup' ); is( $v->validator_error(), 'You need to supply markup to validate', 'you need to supply markup error' ); my $r = $v->validate_markup( $valid ); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 5; } } ok($r, 'validated valid scalar'); ok($v->is_valid(), 'valid scalar is valid'); $r = $v->validate_markup( $invalid ); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 3; } } ok($r, 'validated invalid scalar'); ok(!$v->is_valid(), 'invalid scalar is invalid'); is( $v->num_errors(), 1, 'correct number of errors'); } WebService-Validator-HTML-W3C-0.28/t/13soap_wrong_format.t000444001750001750 315211705612370 23255 0ustar00struanstruan000000000000# $Id: 06detailed.t 41 2004-05-09 13:28:03Z struan $ use Test::More tests => 9; use WebService::Validator::HTML::W3C; my $v = WebService::Validator::HTML::W3C->new( detailed => 1, output => 'xml', ); SKIP: { skip "TEST_AUTHOR environment variable not defined", 9 unless $ENV{ 'TEST_AUTHOR' }; skip "XML::XPath not installed", 9 if -f 't/SKIPXPATH'; ok($v, 'object created'); my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/invalid.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 8; } } ok ($r, 'page validated'); $v->_output('soap12'); is($v->errors, 0, 'Returned 0 for wrong format with SOAP'); is($v->validator_error, 'Result format does not appear to be SOAP', 'Correct error returned for wrong format with SOAP'); $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/invalid.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 5; } } ok ($r, 'page validated'); $v->_output('xml'); is($v->errors, 0, 'Returned 0 for wrong format with XML'); is($v->validator_error, 'Result format does not appear to be XML', 'Correct error returned for wrong format with XML'); is($v->warnings, 0, 'Returned 0 for wrong format with warnings'); is($v->validator_error, 'Warnings only available with SOAP output format', 'Correct error returned for warnings with xml output'); } WebService-Validator-HTML-W3C-0.28/t/03invalid.t000444001750001750 200211705612370 21145 0ustar00struanstruan000000000000# $Id$ use Test::More tests => 3; use WebService::Validator::HTML::W3C; use HTTP::Response; my $v = WebService::Validator::HTML::W3C->new( ); ok ($v, 'object created'); my $err_count = 4; if ( $ENV{ 'TEST_AUTHOR' } ) { my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/invalid.html'); $err_count = 1; unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 2; } } } else { my $resp = HTTP::Response->parse( <_response( $resp ); $v->_parse_validator_response(); } ok (!$v->is_valid, 'page is not valid'); is ($v->num_errors, $err_count, 'correct number of errors'); WebService-Validator-HTML-W3C-0.28/t/06detailed.t000444001750001750 1304211705612370 21323 0ustar00struanstruan000000000000# $Id$ use Test::More; use WebService::Validator::HTML::W3C; my $test_num = 5; if ( $ENV{ 'TEST_AUTHOR' } ) { $test_num = 6; } plan tests => $test_num; my $v = WebService::Validator::HTML::W3C->new( http_timeout => 10, detailed => 1, ); SKIP: { skip "XML::XPath not installed", $test_num if -f 't/SKIPXPATH'; ok($v, 'object created'); if ( $ENV{ 'TEST_AUTHOR' } ) { my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/invalid.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 5; } } ok ($r, 'page validated'); } else { $v->num_errors( 1 ); $v->_content( qq{ http://exo.org.uk/code/www-w3c-validator/invalid.html http://validator.w3.org/ -//W3C//DTD XHTML 1.0 Strict//EN utf-8 false 4 11 7 end tag for "div" omitted, but OMITTAG NO was specified 70

You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".

]]>
>]]>
11 7 XML Parsing Error: Opening and ending tag mismatch: div line 9 and body xmlwf

]]>
>]]>
12 7 XML Parsing Error: Opening and ending tag mismatch: body line 7 and html xmlwf

]]>
>]]>
12 7 XML Parsing Error: Premature end of data in tag html line 3 xmlwf

]]>
>]]>
1 W26">Mismatch between Public and System identifiers in the DOCTYPE declaration
} ); } my $err = $v->errors->[0]; isa_ok($err, 'WebService::Validator::HTML::W3C::Error'); is($err->line, 11, 'Correct line number'); is($err->col, 7, 'Correct column'); like($err->msg, qr/end tag for "div" omitted, but OMITTAG NO was specified/, 'Correct message'); } WebService-Validator-HTML-W3C-0.28/t/valid.html000444001750001750 36511705612370 21146 0ustar00struanstruan000000000000 WebService-Validator-HTML-W3C-0.28/t/12proxy.t000444001750001750 205711705612370 20712 0ustar00struanstruan000000000000# $Id$ use Test::More tests => 2; use WebService::Validator::HTML::W3C; eval "use HTTP::Proxy 0.16"; SKIP: { skip "TEST_AUTHOR environment variable not defined", 2 unless $ENV{ 'TEST_AUTHOR' }; skip "HTTP::Proxy required for testing proxy", 2 if $@; my $test = Test::Builder->new; # this is to work around tests in forked processes $test->use_numbers(0); $test->no_ending(1); my $p = HTTP::Proxy->new( port => 3228, max_connections => 1 ); $p->init; my $pid = fork; if ( $pid == 0 ) { $p->start; exit 0; } else { sleep 1; # just to make proxy is started my $v = WebService::Validator::HTML::W3C->new( proxy => $p->url ); my $r = $v->validate('http://exo.org.uk/code/www-w3c-validator/valid.html'); unless ($r) { if ($v->validator_error eq "Could not contact validator") { skip "failed to contact validator", 2; } } ok($r, 'validates page'); ok($v->is_valid, 'page is valid'); wait; } } WebService-Validator-HTML-W3C-0.28/t/99_pod.t000444001750001750 27011705612370 20444 0ustar00struanstruan000000000000# $Id: 99_pod.t,v 1.1 2004/01/13 22:34:37 struan Exp $ use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); WebService-Validator-HTML-W3C-0.28/t/05options.t000444001750001750 146311705612370 21226 0ustar00struanstruan000000000000# $Id$ use Test::More tests => 6; use WebService::Validator::HTML::W3C; use LWP::UserAgent; my $ua = LWP::UserAgent->new( agent => "test/1.0" ); my $v = WebService::Validator::HTML::W3C->new( validator_uri => 'http://example.com/', http_timeout => 10, ); ok($v, 'object created'); is($v->validator_uri(), 'http://example.com/', 'correct uri set'); is($v->http_timeout(), 10, 'correct http timeout set'); $v = WebService::Validator::HTML::W3C->new( validator_uri => 'http://example.com/', http_timeout => 10, ua => $ua, ); ok($v, 'object created with custom user agent'); is($v->ua()->agent(), 'test/1.0', 'correct user agent set'); is($v->ua()->timeout(), 180, 'timeout argument not used when user agent set'); WebService-Validator-HTML-W3C-0.28/t/01load.t000444001750001750 37611705612370 20430 0ustar00struanstruan000000000000# $Id: 01load.t,v 1.1 2003/11/11 22:49:12 struan Exp $ use Test::More tests => 3; use_ok( 'WebService::Validator::HTML::W3C' ); my $v = WebService::Validator::HTML::W3C->new; ok($v, 'Object created'); isa_ok($v, 'WebService::Validator::HTML::W3C'); WebService-Validator-HTML-W3C-0.28/examples000755001750001750 011705612370 20413 5ustar00struanstruan000000000000WebService-Validator-HTML-W3C-0.28/examples/validate_files_in_dir.pl000555001750001750 247411705612370 25416 0ustar00struanstruan000000000000#!/usr/bin/perl use strict; use warnings; use WebService::Validator::HTML::W3C; =head1 DESCRIPTION This script takes a directory as an argument and then submits every file in that directory to the W3C validator. It will print out a line for each file stating if it is valid or otherwise. For the invalid files it will also print out the errors returned by the validator. =cut my $v = WebService::Validator::HTML::W3C->new( # you should probably install a local validator if you # are indenting to run this against a lot of files and # then uncomment this line and change the uri # validator_uri => 'http://localhost/w3c-validator/check', detailed => 1 ) or die "failed to init validator object"; my $dir = shift; for my $file ( glob( "$dir/*.html" ) ) { if ( $v->validate_file( $file ) ) { if ( $v->is_valid ) { print "$file: valid\n"; } else { print "$file: invalid\n"; for my $err ( @{ $v->errors } ) { printf(" line: %s, col: %s\n error: %s\n\n", $err->line, $err->col, $err->msg); } } } else { die "failed to validate $file: " . $v->validator_error . "\n"; } print "\n" . '-' x 60 . "\n"; # sleep between files so as not to hammer the validator sleep 1; }