blib/lib/Statocles/Plugin/HTMLLint.pm

filter: Statementstmt 45.4% 15 / 33 Branchbran 12.5% 1 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 44.9% 22 / 49 CC 7 SCAR 30.8
CC
7
Cov
39%
check_pages
42.0
BEGIN
2.0
__ANON__
1.1
CRAP 21.7
« blib/lib/Statocles/Command/create.pm ↑ Summary blib/lib/Statocles/App/Role/Store.pm »
1 package Statocles::Plugin::HTMLLint;
2 1 our $VERSION = '0.099';
3 # ABSTRACT: Check HTML for common errors and issues
4  
5 1 ▶use Statocles::Base 'Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 with 'Statocles::Plugin';
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
8 1 ▶ eval { require HTML::Lint::Pluggable; HTML::Lint::Pluggable->VERSION( 0.06 ); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require HTML::Lint::Pluggable; "HTML::Lint::Pluggable"->VERSION("0.06"); 1 } } or die "Error loading Statocles::Plugin::HTMLLint. To use this plugin, install HTML::Lint::Pluggable" 1 0 1
9 or die "Error loading Statocles::Plugin::HTMLLint. To use this plugin, install HTML::Lint::Pluggable";
10 };
11  
12 #pod =attr fatal
13 #pod
14 #pod If set to true, and there are any linting errors, the plugin will also call
15 #pod C<die()> after printing the problems. Defaults to false.
16 #pod
17 #pod =cut
18  
19 1 has fatal => (
20 is => 'ro',
21 isa => Bool,
22 default => 0,
23 );
24  
25 #pod =attr plugins
26 #pod
27 #pod The L<HTML::Lint::Pluggable> plugins to use. Defaults to a generic set of
28 #pod plugins good for HTML5: 'HTML5' and 'TinyEntitesEscapeRule'
29 #pod
30 #pod =cut
31  
32 has plugins => (
33 is => 'ro',
34 isa => ArrayRef,
35 1 ▶ default => sub { [qw( HTML5 TinyEntitesEscapeRule )] },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 1 );
37  
38 #pod =method check_pages
39 #pod
40 #pod $plugin->check_pages( $event );
41 #pod
42 #pod Check the pages inside the given
43 #pod L<Statocles::Event::Pages|Statocles::Event::Pages> event.
44 #pod
45 #pod =cut
46  
47 0 ▶sub check_pages {
Subroutine check_pages: not called CC=6 SCAR=37.4
Pod documented
48 0 my ( $self, $event ) = @_;
49 0 my @plugins = @{ $self->plugins };
50  
51 0 my $lint = HTML::Lint::Pluggable->new;
52 0 $lint->load_plugins( @plugins );
53  
54 0 for my $page ( @{ $event->pages } ) {
55 0 ▶ if ( $page->DOES( 'Statocles::Page::Document' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page->DOES("Statocles::Page::Document")) 0 0 0
56 0 my $html = "".$page->dom;
57 0 my $page_url = $page->path;
58  
59 0 $lint->newfile( $page_url );
60 0 $lint->parse( $html );
61 0 $lint->eof;
62 }
63 }
64  
65 0 ▶ if ( my @errors = $lint->errors ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@errors) = $lint->errors) 0 0 0
66 0 for my $error ( @errors ) {
67 0 $event->emitter->log->warn( "-" . $error->as_string );
68 }
69  
70 0 ▶ die 'Linting failed!' if $self->fatal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->fatal 0 0 0
71 }
72 }
73  
74 #pod =method register
75 #pod
76 #pod Register this plugin to install its event handlers. Called automatically.
77 #pod
78 #pod =cut
79  
80 1 ▶sub register {
Subroutine register: called CC=1 SCAR=0.4
Pod documented
81 1 my ( $self, $site ) = @_;
82 0 ▶ $site->on( build => sub { $self->check_pages( @_ ) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
83 }
84  
85 1 1;
86  
87 __END__
« blib/lib/Statocles/Command/create.pm ↑ Summary blib/lib/Statocles/App/Role/Store.pm »