| 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 ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | my $skip = delete $conf->{skip} // []; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $conf->{"skip"} // []
MC/DC0%0/1
delete $conf->{"skip"} // []
delete $conf->{"skip"}
Truth table50%1/2
A
A= delete $conf->{"skip"}
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$conf->{"on_error"} and ref $conf->{"on_error"} eq "CODE"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ## Only html response | ||||||||||||||||||||||||||||
| 34 | 2 | ▶ | return unless $res->headers->content_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | return if $res->headers->content_type !~ /html/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 3 | $on_error->( $c, "HTMLLint:" . $error->as_string ); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 1 | } ); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | 1; | |||||||||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||||||||||