line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Validator::Feed::W3C;
|
2
|
1
|
|
|
1
|
|
8559
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1478
|
use SOAP::Lite 0.65;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use LWP::UserAgent qw//;
|
7
|
|
|
|
|
|
|
use URI qw//;
|
8
|
|
|
|
|
|
|
use URI::QueryParam qw//;
|
9
|
|
|
|
|
|
|
use Carp qw//;
|
10
|
|
|
|
|
|
|
use HTTP::Request::Common;
|
11
|
|
|
|
|
|
|
use base qw/Class::Accessor/;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = "0.8";
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw/user_agent validator_uri/ );
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw/response request_uri som success/ );
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new
|
19
|
|
|
|
|
|
|
{
|
20
|
|
|
|
|
|
|
my $proto = shift;
|
21
|
|
|
|
|
|
|
my $class = ref $proto || $proto;
|
22
|
|
|
|
|
|
|
my $self = bless {}, $class;
|
23
|
|
|
|
|
|
|
my $ua = shift;
|
24
|
|
|
|
|
|
|
my $uri = shift;
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
if (defined $ua) {
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# check whether it really is
|
29
|
|
|
|
|
|
|
Carp::croak "$ua is not a LWP::UserAgent"
|
30
|
|
|
|
|
|
|
unless UNIVERSAL::isa($ua, 'LWP::UserAgent');
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$self->user_agent($ua);
|
33
|
|
|
|
|
|
|
} else {
|
34
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(agent => __PACKAGE__."/".$VERSION);
|
35
|
|
|
|
|
|
|
$self->user_agent($ua);
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if (defined $uri) {
|
39
|
|
|
|
|
|
|
$self->validator_uri($uri);
|
40
|
|
|
|
|
|
|
} else {
|
41
|
|
|
|
|
|
|
$self->validator_uri("http://validator.w3.org/feed/check.cgi");
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $self;
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _handle_response
|
48
|
|
|
|
|
|
|
{
|
49
|
|
|
|
|
|
|
my $self = shift;
|
50
|
|
|
|
|
|
|
my $res = shift;
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# internal or server errors...
|
53
|
|
|
|
|
|
|
return 0 unless $res->is_success;
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
local $_ = $res->content;
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $som;
|
58
|
|
|
|
|
|
|
eval { $som = SOAP::Deserializer->new->deserialize($_); };
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Deserialization might fail if the response is not a legal
|
61
|
|
|
|
|
|
|
# SOAP response, e.g., if the response is ill-formed... Not
|
62
|
|
|
|
|
|
|
# sure how to make the reason for failure available to the
|
63
|
|
|
|
|
|
|
# application, suggestions welcome.
|
64
|
|
|
|
|
|
|
if ($@) {
|
65
|
|
|
|
|
|
|
# Carp::carp $@;
|
66
|
|
|
|
|
|
|
return 0;
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# memorize the SOAP object model object
|
70
|
|
|
|
|
|
|
$self->{'som'} = $som;
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# check whether this is really the Feed Validator responding
|
73
|
|
|
|
|
|
|
if ($som->match("/Envelope/Body/feedvalidationresponse")) {
|
74
|
|
|
|
|
|
|
$self->{'success'} = 1;
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
# if the response was a SOAP fault
|
77
|
|
|
|
|
|
|
elsif ($som->match("/Envelope/Body/Fault")) {
|
78
|
|
|
|
|
|
|
$self->{'success'} = 0;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# return whether the response was successfully processed
|
82
|
|
|
|
|
|
|
return $self->{'success'};
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub validate
|
86
|
|
|
|
|
|
|
{
|
87
|
|
|
|
|
|
|
my $self = shift;
|
88
|
|
|
|
|
|
|
my %parm = @_;
|
89
|
|
|
|
|
|
|
my $uri = URI->new($self->validator_uri);
|
90
|
|
|
|
|
|
|
my $ua = $self->user_agent;
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$self->{'success'} = 0;
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $req;
|
95
|
|
|
|
|
|
|
if (defined $parm{string}) {
|
96
|
|
|
|
|
|
|
$req = POST $uri, [ rawdata => $parm{string}, manual => 1, output => "soap12" ];
|
97
|
|
|
|
|
|
|
} elsif (defined $parm{uri}) {
|
98
|
|
|
|
|
|
|
$uri->query_param(url => $parm{uri});
|
99
|
|
|
|
|
|
|
$uri->query_param(output => "soap12");
|
100
|
|
|
|
|
|
|
$req = GET $uri;
|
101
|
|
|
|
|
|
|
} else {
|
102
|
|
|
|
|
|
|
Carp::croak "you must supply a string/uri parameter\n";
|
103
|
|
|
|
|
|
|
}
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# memorize request uri
|
107
|
|
|
|
|
|
|
$self->{'request_uri'} = $uri;
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $res = $ua->simple_request($req);
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# memorize response
|
112
|
|
|
|
|
|
|
$self->{'response'} = $res;
|
113
|
|
|
|
|
|
|
# print $res->as_string; # little printf debugging
|
114
|
|
|
|
|
|
|
return $self->_handle_response($res);
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub is_valid
|
118
|
|
|
|
|
|
|
{
|
119
|
|
|
|
|
|
|
my $self = shift;
|
120
|
|
|
|
|
|
|
my $som = $self->som;
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# previous failure means the feed is invalid
|
123
|
|
|
|
|
|
|
return 0 unless $self->success and defined $som;
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# fetch validity field in reponse
|
126
|
|
|
|
|
|
|
my $validity = $som->valueof("/Envelope/Body/feedvalidationresponse/validity");
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# valid if m:validity is true
|
129
|
|
|
|
|
|
|
return 1 if defined $validity and $validity eq "true";
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# else invalid
|
132
|
|
|
|
|
|
|
return 0;
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub errors
|
136
|
|
|
|
|
|
|
{
|
137
|
|
|
|
|
|
|
my $self = shift;
|
138
|
|
|
|
|
|
|
my $som = $self->som;
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
return () unless defined $som;
|
141
|
|
|
|
|
|
|
return $som->valueof("//error");
|
142
|
|
|
|
|
|
|
}
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub warnings
|
145
|
|
|
|
|
|
|
{
|
146
|
|
|
|
|
|
|
my $self = shift;
|
147
|
|
|
|
|
|
|
my $som = $self->som;
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
return () unless defined $som;
|
150
|
|
|
|
|
|
|
return $som->valueof("//warning");
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub errorcount
|
154
|
|
|
|
|
|
|
{
|
155
|
|
|
|
|
|
|
my $self = shift;
|
156
|
|
|
|
|
|
|
my $som = $self->som;
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
return () unless defined $som;
|
159
|
|
|
|
|
|
|
return $som->valueof("//errorcount");
|
160
|
|
|
|
|
|
|
}
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub warningcount
|
163
|
|
|
|
|
|
|
{
|
164
|
|
|
|
|
|
|
my $self = shift;
|
165
|
|
|
|
|
|
|
my $som = $self->som;
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
return () unless defined $som;
|
168
|
|
|
|
|
|
|
return $som->valueof("//warningcount");
|
169
|
|
|
|
|
|
|
}
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1;
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
__END__
|