ZofCMS/Plugin/Debug/Validator/HTML.pm

filter: Statementstmt 32.6% 17 / 52 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 2 totaltotal 25.5% 22 / 86 CC 13 SCAR 47.8
CC
13
Cov
23%
process
182.0
new
2.0
_wrap
2.0
CRAP 118.8
« ZofCMS/Plugin/Tagged.pm ↑ Summary ZofCMS/Plugin/Comments.pm »
1 package App::ZofCMS::Plugin::Debug::Validator::HTML;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001010'; # VERSION
7  
8 1 ▶use WebService::Validator::HTML::W3C;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 0 ▶sub process {
Subroutine process: not called CC=13 SCAR=52.0
Pod undocumented
15 0 my ( $self, $template, $query, $config ) = @_;
16  
17 my %conf = (
18 t_name => 'plug_val_html',
19 q_name => 'plug_val_html',
20 validator_uri => 'http://127.0.0.1/w3c-markup-validator/check',
21  
22 0 ▶ %{ delete $config->conf->{plug_validator_html} || {} },
Condition0%0/2
delete $config->conf->{'plug_validator_html'} || {}
l!l
00
MC/DC0%0/1
delete $config->conf->{'plug_validator_html'} || {}
delete $config->conf->{'plug_validator_html'}
Truth table0%0/2
A
A= delete $config->conf->{'plug_validator_html'}
Aresult
11
00
23 0 ▶ %{ delete $template->{plug_validator_html} || {} },
Condition0%0/2
delete $template->{'plug_validator_html'} || {}
l!l
00
MC/DC0%0/1
delete $template->{'plug_validator_html'} || {}
delete $template->{'plug_validator_html'}
Truth table0%0/2
A
A= delete $template->{'plug_validator_html'}
Aresult
11
00
24 );
25 0 ▶ unless ( defined $conf{address} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $conf{"address"}) 0 0 0
26 0 my $query_string = $ENV{QUERY_STRING};
27 0 ▶ $query_string =~ s/&?\Q$conf{q_name}=\E[^&]+//g
Branch: 1 branch
BranchTrueFalseTotal
if defined $query_string 0 0 0
28 if defined $query_string;
29 $conf{address} = 'http://' . $ENV{SERVER_NAME}
30 . $ENV{SCRIPT_NAME} . '?' . $query_string
31 0 ▶ if defined $ENV{SCRIPT_NAME};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"SCRIPT_NAME"} 0 0 0
32 }
33  
34 $conf{address} = ''
35 0 ▶ unless defined $conf{address};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conf{"address"} 0 0 0
36  
37 0 ▶ my $link = $conf{address} =~ /\?/
Branch: 1 branch
BranchTrueFalseTotal
$conf{'address'} =~ /\?/ ? : 0 0 0
38 ? "$conf{address}&$conf{q_name}=1"
39 : "$conf{address}?$conf{q_name}=1";
40  
41 0 encode_entities $link;
42  
43 0 $template->{t}{ $conf{t_name} . '_link' } = "<div><a href='$link'>Validate</a></div>";
44  
45 return
46 0 ▶ unless $query->{ $conf{q_name} };
Branch: 1 branch
BranchTrueFalseTotal
unless $$query{$conf{"q_name"}} 0 0 0
47  
48 $template->{t}{ $conf{t_name} . '_link' } =
49 0 "<div><a href='" . encode_entities($conf{address}) . "'>Turn off validation</a></div>";
50  
51 0 my $response = LWP::UserAgent->new->get( $conf{address} );
52 0 ▶ unless ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
53 $template->{t}{ $conf{t_name} }
54 0 = _wrap("Error fetching your page: [$conf{address}] " . $response->status_line);
55 0 return;
56 }
57  
58 my $val = WebService::Validator::HTML::W3C->new(
59 detailed => 1,
60 validator_uri => $conf{validator_uri},
61 0 timeout => 30,
62 );
63  
64 0 ▶ unless ( $val->validate_markup( $response->content ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val->validate_markup($response->content)) 0 0 0
65 0 $template->{t}{ $conf{t_name} } = _wrap('Validator error: ' . $val->validator_error);
66 0 return;
67 }
68 0 my $num_errors = $val->num_errors;
69  
70 0 ▶ unless ( $num_errors ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($num_errors) 0 0 0
71 0 $template->{t}{ $conf{t_name} } = _wrap('HTML is <b>VALID</b>');
72 0 return;
73 }
74  
75 0 my @out = ( "Invalid: <b>$num_errors</b> errors" );
76  
77 0 foreach my $error ( @{ $val->errors } ) {
78 0 push @out, sprintf q|line: <b>%s</b>, col: <b>%s</b>, error: <b>%s</b>|,
79 map $error->$_, qw/line col msg/;
80 }
81  
82 0 $template->{t}{ $conf{t_name} } = _wrap( join "\n",
83 map qq|<p style="border-bottom: 1px solid #000;">$_</p>|, @out
84 );
85  
86 0 return;
87 }
88  
89 0 ▶sub _wrap {
Subroutine _wrap: not called CC=1 SCAR=6.9
90 0 my $content = shift;
91 0 return "<div style='border: 2px solid #f00'>$content</div>\n";
92 }
93  
94 1 1;
95 __END__
« ZofCMS/Plugin/Tagged.pm ↑ Summary ZofCMS/Plugin/Comments.pm »