This file is indexed.

/usr/share/perl5/Test/HTML/W3C.pm is in libtest-html-w3c-perl 0.04-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package Test::HTML::W3C;

use strict;
use vars qw($VERSION @EXPORT);
$VERSION = "0.04"; 

=head1 NAME

Test::HTML::W3C - Perform W3C HTML validation testing

=head1 SYNOPSIS

  use Test::HTML::W3C tests => $test_count;
  # or
  use Test::HTML::W3C 'show_detail';
  # or when using both
  use Test::HTML::W3C tests => $test_count, 'show_detail';

  is_valid_markup($my_html_scalar);

  is_valid_file("/path/to/my/file.html");

  is_valid("http://example.com");

  # Get the underlying WebService:;Validator::W3C::HTML object
  my $validator = validator();

=head1 DESCRIPTION

The purpose of this module is to provide a wrapper around the W3C
that works with the L<Test::More> testing framework.

=head1 ABUSE

Please keep in mind that the W3C validation pages and services are
a shared resource. If you plan to do many many tests, please consider
using your own installation of the validation programs, and then use
your local install by modifying the local validtor:

  my $v = validator();
  $v->validator_uri($my_own_validator);

See the documentation for WebService:;Validator::W3C::HTML and the W3C's
site at http://validator.w3.org/ for details

=over 4

=cut

use WebService::Validator::HTML::W3C;
use base qw(Test::Builder::Module);
@EXPORT = qw(
             plan
             diag_html
             is_valid_markup
             is_valid_file
             is_valid
             validator
            );

my $v = WebService::Validator::HTML::W3C->new();
my $not_checked = 1;
my $show_detail = 0;

sub import_extra {
    my ($class, $list) = @_;
    my @other = ();
    my $idx = 0;
    while( $idx <= $#{$list} ) {
        my $item = $list->[$idx];

        if( defined $item and $item eq 'show_detail' ) {
            $show_detail = 1;
            $v = WebService::Validator::HTML::W3C->new(detailed => 1);
        } else {
            push @other, $item;
        }
        $idx++;
    }
    @$list = @other;
}

=item validator();

B<Description:> Returns the underlying WebService::Validator::HTML::W3C object

B<Parameters:> None.

B<Returns:> $validator

=cut

sub validator {
    return $v;
}


=item plan();

B<Description:> Access to the underlying C<plan> method provided by
L<Test::Builder>.

B<Parameters:> As per L<Test::Builder>

=cut

sub plan {
    __PACKAGE__->builder->plan(@_);
}

sub _check_plan {
    $not_checked = 0;
    if (! __PACKAGE__->builder->has_plan()) {
        plan("no_plan");
    }
}

=item is_valid_markup($markup[, $name]);

B<Description:> is_valid_markup tests whether the text in the provided scalar
value correctly validates according to the W3C specifications. This is useful
if you have markup stored in a scalar that you wish to test that  you might get
from using LWP or WWW::Mechanize for example...

B<Parameters:> $markup, a scalar containing the data to test, $name, an
optional descriptive test name.

B<Returns:> None.

=cut

sub is_valid_markup {
    _check_plan() if $not_checked;
    my ($markup, $message) = @_;
    if ($v->validate_markup($markup)) {
        _result($v, $message);
    } else {
        _validator_err($v, "markup");
    }
}

=item is_valid_file($path[, $name]);

B<Description:> is_valid_file works the same way as is_valid_markup, except that
you can specify the text to validate with the path to a filename. This is useful
if you have pregenerated all your HTML files locally, and now wish to test them.

B<Parameters:> $path, a scalar, $name, an optional descriptive test name.

B<Returns:> None.

=cut

sub is_valid_file {
    my ($file, $message) = @_;
    _check_plan() if $not_checked;
    if ($v->validate_file($file)) {
        _result($v, $message);
    } else {
        _validator_err($v, "file");
    }
}


=item is_valid($url[, $name]);

B<Description:> is_valid, again, works very similarly to the is_valid_file and
is_valid_file, except you specify a document that is already online with its
URL. This can be useful if you wish to periodically test a website or webpage
that dynamically changes over time for example, like a blog or a wiki, without
first saving the html to a file using your browswer, or a utility such as wget.

B<Parameters:> $url, a scalar, $name, an optional descriptive test name.

B<Returns:> None.

=cut

sub is_valid {
    my ($uri, $message) = @_;
    _check_plan() if $not_checked;
    if ($v->validate($uri)) {
       _result($v, $message);
    } else {
        _validator_err($v, "URI");
    }
}

sub _validator_err {
    my ($validator, $type) = @_;
    __PACKAGE__->builder->ok(0, "Failed to validate $type.");
    __PACKAGE__->builder->diag($v->validator_error());
}

sub _result {
    my ($validator, $message) = @_;
    if ($validator->is_valid()) {
        __PACKAGE__->builder->ok(1, $message);
    } else {
        my $num = $validator->num_errors();
        my $plurality = ($num == 1) ? "error" : "errors";
        __PACKAGE__->builder->ok(0, $message . " ($num $plurality).");
    }
}


=item diag_html($url);

B<Description:> If you want to display the actual errors reported by
the service for a particular test, you can use the diag_html function.
Please note that you must have imported 'show_detail' for this to
work properly.

  use Test::HTML::W3C 'show_detail';

  is_valid_markup("<html></html">, "My simple test") or diag_html();

B<Parameters:> $url, a scalar.

B<Returns:> None.

=cut

sub diag_html {
    my $tb = __PACKAGE__->builder();
    if ($show_detail) {
        my $e = "";
        if ($v->errors()) {
            my @errs = @{$v->errors()};
            foreach my $error ( @errs ) {
                $e .= sprintf("%s at line %d\n", $error->msg, $error->line);
            }
        }
        else {
            $e .= $v->validator_error;
        }
        $tb->diag($e);
    } else {
        $tb->diag("You need to import 'show_detail' in order to call diag_html\n");
    }
}


1;

__END__

=back

=head1 SEE ALSO

L<Test::Builder::Module> for creating your own testing modules.

L<Test::More> for another popular testing framework, also based on
Test::Builder

L<Test::Harness> for detils about how test results are interpreted.

=head1 AUTHORS

Victor E<lt>victor73@gmail.comE<gt> with inspiration
from the authors of the Test::More and WebService::Validator::W3C:HTML
modules.

=head1 BUGS

See F<http://rt.cpan.org> to report and view bugs.

=head1 COPYRIGHT

Copyright 2006 by Victor E<lt>victor73@gmail.comE<gt>.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

See F<http://www.perl.com/perl/misc/Artistic.html>