| 1 | package WebService::Validator::CSS::W3C; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use SOAP::Lite 0.65; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use LWP::UserAgent qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use URI qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use URI::QueryParam qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use base qw/Class::Accessor/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = "0.3"; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # profiles currently supported by the W3C CSS Validator | ||||||||||||||||||||||||||||
| 15 | 2 | our %PROFILES = map { $_ => 1 } qw/none css1 css2 css21 css3 svg svgbasic | |||||||||||||||||||||||||||
| 16 | svgtiny mobile atsc-tv tv/; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # user media currently supported by the W3C CSS Validator | ||||||||||||||||||||||||||||
| 19 | 2 | our %MEDIA = map { $_ => 1 } qw/all aural braille embossed handheld | |||||||||||||||||||||||||||
| 20 | print screen tty tv presentation/; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # warnings level currently supported by the W3C CSS Validator | ||||||||||||||||||||||||||||
| 23 | 2 | our %WARNINGS = map { $_ => 1 } qw/0 1 2 no/; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | __PACKAGE__->mk_accessors (qw/user_agent validator_uri/); | |||||||||||||||||||||||||||
| 26 | 2 | __PACKAGE__->mk_ro_accessors (qw/response request_uri som success/); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub new | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 1 | my $proto = shift; | |||||||||||||||||||||||||||
| 31 | 1 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 32 | 1 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 33 | 1 | my $ua = shift; | |||||||||||||||||||||||||||
| 34 | 1 | my $uri = shift; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if (defined $ua) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # check whether it really is | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | Carp::croak "$ua is not a LWP::UserAgent" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | unless UNIVERSAL::isa($ua, 'LWP::UserAgent'); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | $self->user_agent($ua); | |||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||
| 44 | 1 | my $ua = LWP::UserAgent->new(agent => __PACKAGE__."/".$VERSION); | |||||||||||||||||||||||||||
| 45 | 1 | $self->user_agent($ua); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if (defined $uri) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | $self->validator_uri($uri); | |||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||
| 51 | 1 | $self->validator_uri("http://jigsaw.w3.org/css-validator/validator"); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | return $self; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub _handle_response | ||||||||||||||||||||||||||||
| 58 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_handle_response: called CC=5 SCAR=29.3
| |||||||||||||||||||||||||||||
| 59 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | 1 | my $res = shift; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # internal or server errors... | ||||||||||||||||||||||||||||
| 63 | 1 | ▶ | return 0 unless $res->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | local $_ = $res->content; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $som; | |||||||||||||||||||||||||||
| 68 | 0 | eval { $som = SOAP::Deserializer->new->deserialize($_); }; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Deserialization might fail if the response is not a legal | ||||||||||||||||||||||||||||
| 71 | # SOAP response, e.g., if the response is ill-formed... Not | ||||||||||||||||||||||||||||
| 72 | # sure how to make the reason for failure available to the | ||||||||||||||||||||||||||||
| 73 | # application, suggestions welcome. | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | # Carp::carp $@; | ||||||||||||||||||||||||||||
| 76 | 0 | return 0; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # memorize the SOAP object model object | ||||||||||||||||||||||||||||
| 80 | 0 | $self->{'som'} = $som; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # check whether this is really the CSS Validator responding | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($som->match("/Envelope/Body/cssvalidationresponse")) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 84 | 0 | $self->{'success'} = 1; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | # if the response was a SOAP fault | ||||||||||||||||||||||||||||
| 87 | elsif ($som->match("/Envelope/Body/Fault")) { | ||||||||||||||||||||||||||||
| 88 | 0 | $self->{'success'} = 0; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # return whether the response was successfully processed | ||||||||||||||||||||||||||||
| 92 | 0 | return $self->{'success'}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub validate | ||||||||||||||||||||||||||||
| 96 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=10 SCAR=30.4
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 1 | my %parm = @_; | |||||||||||||||||||||||||||
| 99 | 1 | my $uri = URI->new($self->validator_uri); | |||||||||||||||||||||||||||
| 100 | 1 | my $ua = $self->user_agent; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | $self->{'success'} = 0; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||
| 105 | 1 | ▶ | if (defined $parm{string}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 106 | 0 | $uri->query_param(text => $parm{string}); | |||||||||||||||||||||||||||
| 107 | } elsif (defined $parm{uri}) { | ||||||||||||||||||||||||||||
| 108 | 1 | $uri->query_param(uri => $parm{uri}); | |||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||
| 110 | 0 | Carp::croak "you must supply a string/uri parameter\n"; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | ▶ | if (defined $parm{medium}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | # check whether the medium is supported | ||||||||||||||||||||||||||||
| 115 | Carp::croak "$parm{medium} is not a legal medium\n" | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | unless $MEDIA{$parm{medium}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | $uri->query_param(medium => $parm{medium}); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | if (defined $parm{profile}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | # check whether the profile is supported | ||||||||||||||||||||||||||||
| 123 | Carp::croak "$parm{profile} is not a legal profile\n" | ||||||||||||||||||||||||||||
| 124 | 0 | ▶ | unless $PROFILES{$parm{profile}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | $uri->query_param(profile => $parm{profile}); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | ▶ | if (defined $parm{warnings}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | Carp::croak "warnings must be either \"no\" or an integer from 0 to 2\n" | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | unless $WARNINGS{$parm{warnings}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | $uri->query_param(warning => $parm{warnings}); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # request SOAP 1.2 output | ||||||||||||||||||||||||||||
| 136 | 1 | $uri->query_param(output => "soap12"); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # memorize request uri | ||||||||||||||||||||||||||||
| 139 | 1 | $self->{'request_uri'} = $uri; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # generate new HTTP::Request object | ||||||||||||||||||||||||||||
| 142 | 1 | my $req = HTTP::Request->new(GET => $uri); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # add an Accept-Language header if desired | ||||||||||||||||||||||||||||
| 145 | 1 | ▶ | if (defined $parm{language}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | $req->header(Accept_Language => $parm{language}); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 1 | my $res = $ua->simple_request($req); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | # memorize response | ||||||||||||||||||||||||||||
| 152 | 1 | $self->{'response'} = $res; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 1 | return $self->_handle_response($res); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub is_valid | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_valid: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 160 | 0 | my $som = $self->som; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # previous failure means the style sheet is invalid | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return 0 unless $self->success and defined $som; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->success and defined $som
MC/DC0%0/2
$self->success and defined $som
$self->success
defined $som
Truth table0%0/3
A and B
A= $self->successB= defined $som
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # fetch validity field in reponse | ||||||||||||||||||||||||||||
| 166 | 0 | my $validity = $som->valueof("/Envelope/Body/cssvalidationresponse/validity"); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # valid if m:validity is true | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return 1 if defined $validity and $validity eq "true"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $validity and $validity eq "true"
MC/DC0%0/2
defined $validity and $validity eq "true"
defined $validity
$validity eq "true"
Truth table0%0/3
A and B
A= defined $validityB= $validity eq "true"
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # else invalid | ||||||||||||||||||||||||||||
| 172 | 0 | return 0; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | sub errors | ||||||||||||||||||||||||||||
| 176 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
errors: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 178 | 1 | my $som = $self->som; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1 | ▶ | return () unless defined $som; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | return $som->valueof("//error"); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | sub warnings | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
warnings: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 187 | 0 | my $som = $self->som; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return () unless defined $som; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | return $som->valueof("//warning"); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | sub errorcount | ||||||||||||||||||||||||||||
| 194 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
errorcount: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 196 | 0 | my $som = $self->som; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | return () unless defined $som; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 0 | return $som->valueof("//errorcount"); | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | sub warningcount | ||||||||||||||||||||||||||||
| 203 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
warningcount: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 204 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 205 | 0 | my $som = $self->som; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | return () unless defined $som; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | return $som->valueof("//warningcount"); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 2 | 1; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | __END__ | ||||||||||||||||||||||||||||