Re: standalone perl module?

On 23/01/07, Dmitry Karasik <dmitry@karasik.eu.org> wrote:
>
> Hello,
>
> I've been playing with the locally installed validator, and quickly found that
> it's not really convenient to validate local html pages from command line.
> Actually, I can't find how it can be done in an efficient manner, because it
> takes some effort to prepare GET or POST request just to trick CGI.pm into
> thinking that it runs from under apache ( and I can't find a commandline tool
> either).

If I understand you correctly you want to take a file on your hard
disk and send that to the validator for validation? If so then
WebService::Validator::HTML::W3C is probably what you want. You can
get it from CPAN:

http://search.cpan.org/~struan/WebService-Validator-HTML-W3C-0.17/

and then the following code should do what you want:

#!/usr/bin/perl
use strict;
use warnings;
use WebService::Validator::HTML::W3C;

my $file = shift;

my $v = WebService::Validator::HTML::W3C->new();
$v->validate_file( $file );
if ($v->is_valid() ) {
    print "$file is valid HTML\n";
} else {
    print "$file is not valid HTML\n";
}

and then if you save that as validate.pl

./validate.pl file.html

should do what you want.

If you want to actually validate a file without using a web service
then you could have a look at HTML::Validator. I've not used it but it
claims to do the right thing.

Hope that helps

Struan

Received on Wednesday, 24 January 2007 10:24:59 UTC