W3C home > Mailing lists > Public > www-validator@w3.org > January 2007

Re: standalone perl module?

From: Struan Donald <struandonald@gmail.com>
Date: Wed, 24 Jan 2007 10:24:54 +0000
Message-ID: <e2465780701240224w230053ebq52bed70938c0ee93@mail.gmail.com>
To: dmitry@karasik.eu.org
Cc: www-validator@w3.org

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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:23 GMT