aboutsummaryrefslogtreecommitdiffstats
path: root/misc/w3c-validator.pl
blob: 76355ac4d7e83d875257581b9c5054512c28fc47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl

# Usage: w3c-validator.pl /tmp/fpanel/*.html
#
# To generate a bunch of HTML files for the RunModes you want to check,
# add the following to lib/Fripost/Panel/Login.pm
#
#     sub cgiapp_postrun {
#         my $self = shift;
#         my $out = shift;
#         unless ($$out eq '') {
#             open OUT, '>', "/tmp/fpanel/".$self->get_current_runmode
#                                          .int(rand 65536).'.'.$$.'.html';
#             print OUT $$out;
#             close OUT;
#         }
#         return $out;
#     }
#
# cd /opt/fripost-panel/
# sudo mkdir /tmp/fpanel && sudo chown fpanel:www-data /tmp/fpanel/
# sudo ./bin/fripost-panel restart
#
# Every HTML page will now be dumped into /tmp/fpanel/. Once you are done
# browsing the RunModes, 
#   sudo chmod -R +r /tmp/fpanel/
#   ./misc/w3c-validator.pl /tmp/fpanel/*.html
#
# /!\ Note: There is a serious privacy concern here. Do *NOT* forget to  /!\
# /!\ remove the postrun hook, and to restart the FCGI, once you are     /!\
# /!\ done testing the application!                                      /!\

use 5.010_000;
use strict;
use warnings;
use utf8;

use WebService::Validator::HTML::W3C;
my $v = WebService::Validator::HTML::W3C->new( detailed => 1 );

foreach my $html (@ARGV) {
    die "Error: Cannot read file $html" unless -f $html and -r $html;
    $v->validate_file($html) or die "Cannot validate: ", $v->validator_error, "\n";

    if (defined $v->errors) {
        my @errors = @{$v->errors};
        foreach (@errors) {
            printf STDERR ( "line: %s, col: %s\n\terror: %s\n", 
                            $_->line, $_->col,
                            $_->msg );
        }
        die "ERR: Cannot validate ".$html.' ('.(1+$#errors)." error(s) found).\n";
    }
    elsif (@{$v->warnings}) {
        my @warnings = @{$v->warnings};
        foreach (@warnings) {
            printf STDERR ( "line: %s, col: %s\n\twarning: %s\n", 
                            $_->line, $_->col,
                            $_->msg );
        }
        die "WARN: Cannot validate ".$html.' ('.(1+$#warnings)." warnings(s) found).\n";
    }
    elsif ($v->is_valid) {
        print STDERR "Passed: $html\n";
    }
    else {
        die "A weird thing happened with $html\n";
    }
}