blib/lib/Mojolicious/Plugin/HTMLLint.pm

filter: Statementstmt 94.1% 32 / 34 Branchbran 50.0% 5 / 10 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 74.6% 47 / 63 CC 10 SCAR 15.0
CC
10
Cov
78%
__ANON__
6.3
register
5.6
__ANON__
2.0
CRAP 4.5
↑ Summary
1 package Mojolicious::Plugin::HTMLLint;
2 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use HTML::Lint;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use v5.10; # earliest occurance of feature
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶no if $] >= 5.017011, warnings => 'experimental::smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.06';
10  
11 1 ▶sub register {
Subroutine register: called CC=5 SCAR=17.2
Pod documented
12 1 my ( $self, $app, $conf ) = @_;
13 1 ▶ $conf ||= {};
Condition50%1/2
$conf ||= {}
l!l
10
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
Aresult
11
00
14  
15 1 ▶ my $skip = delete $conf->{skip} // [];
Condition50%1/2
delete $conf->{"skip"} // []
l!l
01
MC/DC0%0/1
delete $conf->{"skip"} // []
delete $conf->{"skip"}
Truth table50%1/2
A
A= delete $conf->{"skip"}
Aresult
11
00
16  
17 # On error callback
18 1 my $on_error;
19 1 ▶ if ( $conf->{on_error} && ref($conf->{on_error}) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{'on_error'} and ref $conf->{'on_error'} eq 'CODE') { } 1 0 1
Condition33%1/3
$conf->{"on_error"} and ref $conf->{"on_error"} eq "CODE"
!ll&&!rl&&r
001
MC/DC0%0/2
$conf->{"on_error"} and ref $conf->{"on_error"} eq "CODE"
$conf->{"on_error"} ref $conf->{"on_error"} eq "CODE"
Truth table33%1/3
A and B
A= $conf->{"on_error"}B= ref $conf->{"on_error"} eq "CODE"
ABresult
0X0
100
111
20 1 $on_error = delete $conf->{on_error};
21 } else {
22 0 ▶ $on_error = sub { $app->log->warn($_[1]) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 }
24  
25 $app->hook(
26 2 ▶ 'after_dispatch' => sub {
Subroutine __ANON__: called CC=6 SCAR=18.4
27 2 my ( $c ) = @_;
28 2 my $res = $c->res;
29  
30 # Only successful response
31 2 ▶ return if $res->code !~ m/^2/;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->code =~ /^2/d 0 2 2
32  
33 ## Only html response
34 2 ▶ return unless $res->headers->content_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->headers->content_type 0 2 2
35 2 ▶ return if $res->headers->content_type !~ /html/;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->headers->content_type =~ /html/d 0 2 2
36  
37 2 my $lint = HTML::Lint->new(%$conf);
38 2 $lint->parse($res->body);
39 2 $lint->eof();
40  
41 2 foreach my $error ( $lint->errors ) {
42 3 my $err_msg = $error->as_string();
43 3 ▶ next if $err_msg ~~ $skip;
Branch: 1 branch
BranchTrueFalseTotal
if $err_msg ~~ $skip 0 3 3
44  
45 3 $on_error->( $c, "HTMLLint:" . $error->as_string );
46 }
47 1 } );
48 }
49  
50 1 1;
51 __END__
↑ Summary