- From: Olivier Thereaux via cvs-syncmail <cvsmail@w3.org>
- Date: Mon, 05 May 2008 06:41:58 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/perl/modules/W3C/LogValidator/lib/W3C/LogValidator In directory hutz:/tmp/cvs-serv28982/lib/W3C/LogValidator Modified Files: CSSValidator.pm Log Message: SOAP::Lite is having hiccups in CPAN lately, which thus breaks any installation via CPAN of WebService::Validator::CSS::W3C, and thus the logvalidator. Working around this issue by using the HTTP response of the CSS validator, instead of the full SOAP output. Index: CSSValidator.pm =================================================================== RCS file: /sources/public/perl/modules/W3C/LogValidator/lib/W3C/LogValidator/CSSValidator.pm,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- CSSValidator.pm 4 Dec 2007 07:15:33 -0000 1.20 +++ CSSValidator.pm 5 May 2008 06:41:56 -0000 1.21 @@ -9,7 +9,7 @@ package W3C::LogValidator::CSSValidator; use strict; use warnings; -use WebService::Validator::CSS::W3C 0.2; + require Exporter; @@ -45,9 +45,11 @@ { $self->{AUTH_EXT} = ".css"; } + $config{ValidatorMethod} = "HEAD" ; $config{ValidatorHost} = "jigsaw.w3.org" if (! exists $config{ValidatorHost}); $config{ValidatorPort} = "80" if (!exists $config{ValidatorPort}); $config{ValidatorString} = "/css-validator/validator" if (!exists $config{ValidatorString}); + $config{ValidatorString} .= "?uri="; # by default, report invalid documents $config{ShowInvalid} = "Yes" if (!exists $config{ShowInvalid}); $config{ShowAborted} = "No" if (!exists $config{ShowAborted}); @@ -94,6 +96,12 @@ if (@_) { $self->{VALID_SUCCESS} = shift } return $self->{VALID_SUCCESS}; } +sub valid_head +{ + my $self = shift; + if (@_) { $self->{VALID_HEAD} = shift } + return $self->{VALID_HEAD}; +} sub HEAD_check { @@ -195,6 +203,8 @@ if (exists $config{MaxDocuments}) {$max_documents = $config{MaxDocuments}} else {$max_documents = 0} print "Now Using the CSS Validation module...\n" if $verbose; + use LWP::UserAgent; + use URI::Escape; my @uris = undef; my %hits; if (defined ($config{tmpfile})) @@ -239,6 +249,7 @@ my $intro="Here are the <census> most popular $whatweshow_str document(s) that I could find in the logs for $name."; my $outro; + my $ua = new LWP::UserAgent; @uris = $self->trim_uris(@uris); my $invalid_census = 0; # number of invalid docs @@ -253,47 +264,62 @@ my $uri_orig = $uri; $self->new_doc(); $total_census++; - print " processing #$total_census $uri... " if ($verbose > 1); - my $val = WebService::Validator::CSS::W3C->new; - my $cssvalidator_server=join ("", "http://",$config{ValidatorHost},":",$config{ValidatorPort}, $config{ValidatorString}); - $val->validator_uri($cssvalidator_server); - $val->validate(uri => $uri); - $self->valid_success($val->success); - $self->valid($val->is_valid); - my @errors = $val->errors; - $self->{VALID_ERR_NUM} = int( @errors ); - - if (! $self->valid_success) - { - print " Could not validate!" if ($verbose > 1); - } - else - { - if ($self->valid) # success, valid - { - print "Valid!" if ($verbose > 1); - } - else # success - not valid -> invalid + print " processing #$total_census $uri... " if ($verbose > 1); + $uri = uri_escape($uri); + # creating the HTTP query string with all parameters + my $string=join ("", "http://",$config{ValidatorHost},":",$config{ValidatorPort}, $config{ValidatorString},$uri); + my $method = $config{ValidatorMethod}; + my $request = new HTTP::Request("$method", "$string"); + my $response = new HTTP::Response; + $response = $ua->simple_request($request); + if ($response->is_success) { + # not an error, we could contact the server + # set both valid and error number according to response + $self->valid($response->header('X-W3C-Validator-Status')); + $self->{VALID_ERR_NUM} = $response->header('X-W3C-Validator-Errors'); + # we know the validator has been able to (in)validate if $self->valid is not NULL + if ( ($self->valid)) # we got an answer about validation (valid, invalid or abort) { - printf ("Invalid, %s error(s)!",$self->valid_err_num) if ($verbose > 1);; + if ( + (($self->valid =~ /Invalid/i) and ($config{ShowInvalid} eq "Yes")) + or (($self->valid =~ /Valid/i) and ($config{ShowValid} eq "Yes")) + or (($self->valid =~ /Abort/i) and ($config{ShowAborted} eq "Yes")) + ) { + my @result_tmp; + push @result_tmp, $total_census; + push @result_tmp, $hits{$uri_orig}; + if ($self->valid =~ /Abort/i) { push @result_tmp, "Abort"; } + else { push @result_tmp, $self->valid_err_num; } + push @result_tmp, $uri_orig; + push @result, [@result_tmp]; + $invalid_census++; + $last_invalid_position = $total_census; + } } - } - if ( ((! $self->valid_success) and ($config{ShowAborted} eq "Yes")) - or (($self->valid_success) and (! $self->valid) and ($config{ShowInvalid} eq "Yes")) - or (($self->valid_success) and ($self->valid) and ($config{ShowValid} eq "Yes")) ){ - my @result_tmp; - push @result_tmp, $total_census; - push @result_tmp, $hits{$uri_orig}; - if (! $self->valid_success) { push @result_tmp, "Abort";} - else {push @result_tmp, $self->valid_err_num;} - push @result_tmp, $uri_orig; - push @result, [@result_tmp]; - $invalid_census++; - $last_invalid_position = $total_census; - } - - print "\n" if ($verbose > 1); + printf (" %s!", $self->valid) if ( ($verbose > 1) and (defined ($self->valid))); + print " Could not validate (validation failed)!" if (($verbose > 1) and(!defined ($self->valid))); + + if (($verbose > 1) and ($self->valid_err_num)) # verbose or debug + {printf ", %s errors!",$self->valid_err_num} + } + else { + print " Could not validate (no response from validator)!" if ($verbose > 1) ; + if ($config{ShowAborted} eq "Yes") { + my @result_tmp; + push @result_tmp, $total_census; + push @result_tmp, $hits{$uri_orig}; + push @result_tmp, "Abort"; + push @result_tmp, $uri_orig; + push @result, [@result_tmp]; + $invalid_census++; + $last_invalid_position = $total_census; + } + } + print "\n" if ($verbose > 1); + $self->valid_head($response->as_string); # for debug + if ($verbose > 2) {printf "%s :\n%s", $string, $self->valid_head;} # debug + sleep(1); # do not kill the validator } print "Done!\n" if $verbose;
Received on Monday, 5 May 2008 06:42:28 UTC