| 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'} || {}
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'}
| |||||||||||||
| 23 | 0 | ▶ | %{ delete $template->{plug_validator_html} || {} }, | ||||||||||
|
Condition0%0/2
delete $template->{'plug_validator_html'} || {}
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'}
| |||||||||||||
| 24 | ); | ||||||||||||
| 25 | 0 | ▶ | unless ( defined $conf{address} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 0 | my $query_string = $ENV{QUERY_STRING}; | |||||||||||
| 27 | 0 | ▶ | $query_string =~ s/&?\Q$conf{q_name}=\E[^&]+//g | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | $conf{address} = '' | ||||||||||||
| 35 | 0 | ▶ | unless defined $conf{address}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | |||||||||||||
| 37 | 0 | ▶ | my $link = $conf{address} =~ /\?/ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||