File Coverage

blib/lib/Apache/Lint.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Apache::Lint;
2              
3 1     1   29747 use warnings;
  1         2  
  1         35  
4 1     1   5 use strict;
  1         2  
  1         59  
5              
6             =head1 NAME
7              
8             Apache::Lint - Apache wrapper around HTML::Lint
9              
10             =head1 SYNOPSIS
11              
12             Apache::Lint passes all your mod_perl-generated code through the HTML::Lint module,
13             and spits out the resulting errors into.
14              
15            
16             SetHandler perl-script
17             PerlSetVar Filter On
18             PerlHandler Your::Handler Apache::Lint
19            
20              
21             Your handler C must be Apache::Filter-aware. At the top
22             of your handler, put this line:
23              
24             my $r = shift;
25             $r = $r->filter_register
26              
27             =head1 VERSION
28              
29             Version 0.10
30              
31             =cut
32              
33             our $VERSION = '0.10';
34              
35 1     1   439 use mod_perl 1.21;
  0            
  0            
36             use Apache::Constants qw( OK HTTP_OK );
37             use Apache::Log;
38             use HTML::Lint;
39              
40             =head1 FUNCTIONS
41              
42             =head2 handler()
43              
44             Apache::Filter-aware content handler. Your other handlers in the chain
45             must also be filter-aware.
46              
47             =cut
48              
49             sub handler {
50             my $r = shift;
51             $r = $r->filter_register;
52              
53             my $log = $r->server->log;
54              
55             # Get any output from previous filters in the chain.
56             (my $fh, my $handler_status) = $r->filter_input;
57              
58             return $handler_status unless $handler_status == OK;
59              
60             my $output = do { local $/ = undef; <$fh> };
61             $r->print( $output );
62              
63             my $response_code = $r->status;
64             my $type = $r->content_type;
65             return OK unless ($r->content_type eq "text/html") && ($r->status eq HTTP_OK);
66              
67             my $lint = new HTML::Lint;
68             $lint->newfile( $r->uri );
69             $lint->parse( $output );
70             $lint->eof;
71              
72             if ( $lint->errors ) {
73             $log->warn( "Apache::Lint found errors in ", $r->the_request );
74             $log->warn( $_->as_string() ) for $lint->errors;
75             }
76              
77             return $handler_status;
78             }
79              
80             1;
81              
82             __END__