| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::HTMLLint; |
|
2
|
1
|
|
|
1
|
|
726
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
648
|
use HTML::Lint; |
|
|
1
|
|
|
|
|
13199
|
|
|
|
1
|
|
|
|
|
25
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
23
|
use v5.10; # earliest occurance of feature |
|
|
1
|
|
|
|
|
2
|
|
|
7
|
1
|
|
|
1
|
|
3
|
no warnings 'experimental::smartmatch'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
316
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
|
12
|
1
|
|
|
1
|
1
|
50
|
my ( $self, $app, $conf ) = @_; |
|
13
|
1
|
|
50
|
|
|
3
|
$conf ||= {}; |
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
50
|
|
|
7
|
my $skip = delete $conf->{skip} // []; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# On error callback |
|
18
|
1
|
|
|
|
|
1
|
my $on_error; |
|
19
|
1
|
50
|
33
|
|
|
6
|
if ( $conf->{on_error} && ref($conf->{on_error}) eq 'CODE' ) { |
|
20
|
1
|
|
|
|
|
2
|
$on_error = delete $conf->{on_error}; |
|
21
|
|
|
|
|
|
|
} else { |
|
22
|
0
|
|
|
0
|
|
0
|
$on_error = sub { $app->log->warn($_[1]) }; |
|
|
0
|
|
|
|
|
0
|
|
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$app->hook( |
|
26
|
|
|
|
|
|
|
'after_dispatch' => sub { |
|
27
|
2
|
|
|
2
|
|
21444
|
my ( $c ) = @_; |
|
28
|
2
|
|
|
|
|
9
|
my $res = $c->res; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Only successful response |
|
31
|
2
|
50
|
|
|
|
16
|
return if $res->code !~ m/^2/; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
## Only html response |
|
34
|
2
|
50
|
|
|
|
20
|
return unless $res->headers->content_type; |
|
35
|
2
|
50
|
|
|
|
26
|
return if $res->headers->content_type !~ /html/; |
|
36
|
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
34
|
my $lint = HTML::Lint->new(%$conf); |
|
38
|
2
|
|
|
|
|
30
|
$lint->parse($res->body); |
|
39
|
2
|
|
|
|
|
2085
|
$lint->eof(); |
|
40
|
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
92
|
foreach my $error ( $lint->errors ) { |
|
42
|
3
|
|
|
|
|
35
|
my $err_msg = $error->as_string(); |
|
43
|
3
|
50
|
|
|
|
61
|
next if $err_msg ~~ $skip; |
|
44
|
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
7
|
$on_error->( $c, "HTMLLint:" . $error->as_string ); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
1
|
|
|
|
|
11
|
} ); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
|
51
|
|
|
|
|
|
|
__END__ |