WebService/Validator/CSS/W3C.pm

filter: Statementstmt 63.2% 81 / 128 Branchbran 34.0% 15 / 44 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 72.7% 16 / 22 Podpod 100% 4 / 4 totaltotal 56.8% 117 / 206 CC 30 SCAR 21.4
CC
30
Cov
55%
_val_wheel
20.0
_validate
18.6
_child_closed
12.0
CRAP 8.5
« App/PNGCrush.pm ↑ Summary WWW/WebDevout/BrowserSupportInfo.pm »
1 package POE::Component::WebService::Validator::CSS::W3C;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '2.001002'; # VERSION
7  
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use WebService::Validator::CSS::W3C;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use POE qw( Wheel::Run Filter::Reference Filter::Line );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶sub spawn {
Subroutine spawn: called CC=5 SCAR=16.5
Pod documented
15 1 my $package = shift;
16 1 ▶ croak "$package requires an even number of arguments"
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 1 1
17 if @_ & 1;
18  
19 1 my %params = @_;
20  
21 1 $params{ lc $_ } = delete $params{ $_ } for keys %params;
22  
23 delete $params{options}
24 1 ▶ unless ref $params{options} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $params{"options"} eq "HASH" 1 0 1
25  
26 # fill in defaults
27 1 %params = (
28 ua => LWP::UserAgent->new( timeout => 30 ),
29 val_uri => 'https://jigsaw.w3.org/css-validator/validator',
30  
31 %params,
32 );
33  
34 1 my $self = bless \%params, $package;
35  
36 $self->{session_id} = POE::Session->create(
37 object_states => [
38 $self => {
39 validate => '_validate',
40 shutdown => '_shutdown',
41 },
42 $self => [
43 qw(
44 _child_error
45 _child_closed
46 _child_stdout
47 _child_stderr
48 _sig_child
49 _start
50 )
51 ]
52 ],
53 1 ▶ ( defined $params{options} ? ( options => $params{options} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'options'} ? : 0 1 1
54 )->ID();
55  
56 1 return $self;
57 }
58  
59 1 ▶sub _start {
Subroutine _start: called CC=4 SCAR=15.0
60 1 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
61 1 $self->{session_id} = $_[SESSION]->ID();
62  
63 1 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 1 1
64 0 $kernel->alias_set( $self->{alias} );
65 }
66 else {
67 1 $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ );
68 }
69  
70 $self->{wheel} = POE::Wheel::Run->new(
71 0 ▶ Program => sub { _val_wheel( @$self{ qw(ua val_uri) } ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 1 ▶ ErrorEvent => '_child_error',
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 1 1
73 CloseEvent => '_child_close',
74 StdoutEvent => '_child_stdout',
75 StderrEvent => '_child_stderr',
76 StdioFilter => POE::Filter::Reference->new,
77 StderrFilter => POE::Filter::Line->new,
78 ( $^O eq 'MSWin32' ? ( CloseOnCall => 0 ) : ( CloseOnCall => 1 ) )
79 );
80  
81 $kernel->yield('shutdown')
82 1 ▶ unless $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"wheel"} 0 1 1
83  
84 1 $kernel->sig_child( $self->{wheel}->PID(), '_sig_child' );
85  
86 1 undef;
87 }
88  
89 1 ▶sub _sig_child {
Subroutine _sig_child: called CC=1 SCAR=0.0
90 1 $poe_kernel->sig_handled;
91 }
92  
93 0 ▶sub session_id {
Subroutine session_id: not called CC=1 SCAR=6.9
Pod documented
94 0 return $_[0]->{session_id};
95 }
96  
97 1 ▶sub validate {
Subroutine validate: called CC=1 SCAR=0.0
Pod documented
98 1 my $self = shift;
99 1 $poe_kernel->post( $self->{session_id} => 'validate' => @_ );
100 }
101  
102 1 ▶sub _validate {
Subroutine _validate: called CC=10 SCAR=29.2
103 1 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
104 1 my $sender = $_[SENDER]->ID;
105  
106 return
107 1 ▶ if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 0 1 1
108  
109 1 my $args;
110 1 ▶ if ( ref $_[ARG0] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[10] eq 'HASH') { } 1 0 1
111 1 $args = { %{ $_[ARG0] } };
112 }
113 else {
114 0 warn "First parameter must be a hashref, trying to adjust...";
115 0 $args = { @_[ARG0 .. $#_] };
116 }
117  
118 $args->{ lc $_ } = delete $args->{ $_ }
119 1 for grep { !/^_/ } keys %{ $args };
120  
121 1 ▶ unless ( $args->{event} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"event"}) 0 1 1
122 0 carp "Missing 'event' parameter to validate()";
123 0 return;
124 }
125  
126 1 ▶ if ( !exists $args->{uri} and !exists $args->{string} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args->{"uri"} or exists $args->{"string"}) 0 1 1
Condition33%1/3
exists $args->{"uri"} or exists $args->{"string"}
l!l&&r!l&&!r
010
MC/DC0%0/2
exists $args->{"uri"} or exists $args->{"string"}
exists $args->{"uri"} exists $args->{"string"}
Truth table33%1/3
A or B
A= exists $args->{"uri"}B= exists $args->{"string"}
ABresult
1X1
011
000
127 0 carp "Must specify either `uri` or `string` validate()";
128 0 return;
129 }
130  
131 $args->{params}{ $_ } = $args->{ $_ }
132 1 for ( qw( string uri medium profile warnings language ) );
133  
134 1 ▶ if ( $args->{session} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'session'}) { } 0 1 1
135 0 ▶ if ( my $ref = $kernel->alias_resolve( $args->{session} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $kernel->alias_resolve($args->{'session'})) { } 0 0 0
136 0 $args->{sender} = $ref->ID;
137 }
138 else {
139 0 carp "Could not resolve 'session' parameter to a valid"
140 . " POE session";
141 0 return;
142 }
143 }
144 else {
145 1 $args->{sender} = $sender;
146 }
147  
148 1 $kernel->refcount_increment( $args->{sender} => __PACKAGE__ );
149 1 $self->{wheel}->put( $args );
150  
151 1 undef;
152 }
153  
154 1 ▶sub shutdown {
Subroutine shutdown: called CC=1 SCAR=0.0
Pod documented
155 1 my $self = shift;
156 1 $poe_kernel->call( $self->{session_id} => 'shutdown' => @_ );
157 }
158  
159 1 ▶sub _shutdown {
Subroutine _shutdown: called CC=4 SCAR=14.2
160 1 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
161 1 $kernel->alarm_remove_all;
162 1 $kernel->alias_remove( $_ ) for $kernel->alias_list;
163 $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ )
164 1 ▶ unless $self->{alias};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"alias"} 1 0 1
165  
166 1 $self->{shutdown} = 1;
167  
168 $self->{wheel}->shutdown_stdin
169 1 ▶ if $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"wheel"} 1 0 1
170 }
171  
172 0 ▶sub _child_closed {
Subroutine _child_closed: not called CC=3 SCAR=24.8
173 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
174  
175 warn "_child_closed called (@_[ARG0..$#_])\n"
176 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
177  
178 0 delete $self->{wheel};
179 $kernel->yield('shutdown')
180 0 ▶ unless $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"shutdown"} 0 0 0
181  
182 0 undef;
183 }
184  
185 1 ▶sub _child_error {
Subroutine _child_error: called CC=3 SCAR=11.3
186 1 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
187 warn "_child_error called: (@_[ARG0..$#_])\n"
188 1 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 1 0 1
189  
190 1 delete $self->{wheel};
191 $kernel->yield('shutdown')
192 1 ▶ unless $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"shutdown"} 0 1 1
193  
194 1 undef;
195 }
196  
197 0 ▶sub _child_stderr {
Subroutine _child_stderr: not called CC=2 SCAR=17.9
198 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
199 warn "_child_stderr: $_[ARG0]\n"
200 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
201  
202 0 undef;
203 }
204  
205 1 ▶sub _child_stdout {
Subroutine _child_stdout: called CC=1 SCAR=0.0
206 1 my ( $kernel, $self, $input ) = @_[ KERNEL, OBJECT, ARG0 ];
207  
208 1 my $session = delete $input->{sender};
209 1 my $event = delete $input->{event};
210 1 delete $input->{params};
211  
212 1 $kernel->post( $session, $event, $input );
213 1 $kernel->refcount_decrement( $session => __PACKAGE__ );
214  
215 1 undef;
216 }
217  
218 0 ▶sub _val_wheel {
Subroutine _val_wheel: not called CC=4 SCAR=30.0
219 0 my ( $val_ua, $val_uri ) = @_;
220  
221 0 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
222 0 binmode STDIN;
223 0 binmode STDOUT;
224 }
225  
226 0 my $raw;
227 0 my $size = 4096;
228 0 my $filter = POE::Filter::Reference->new;
229  
230 0 ▶ while ( sysread STDIN, $raw, $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread STDIN, $raw, $size) 0 0 0
231 0 my $requests = $filter->get( [ $raw ] );
232 0 foreach my $req_ref ( @$requests ) {
233  
234 # changes $req_ref
235 0 _prepare_results( $req_ref, $val_ua, $val_uri );
236  
237 0 my $response = $filter->put( [ $req_ref ] );
238 0 print STDOUT @$response;
239 }
240 }
241 }
242  
243 0 ▶sub _prepare_results {
Subroutine _prepare_results: not called CC=3 SCAR=24.8
244 0 my ( $req_ref, $val_ua, $val_uri ) = @_;
245  
246 0 my $val = WebService::Validator::CSS::W3C->new( $val_ua, $val_uri );
247  
248 @$req_ref{
249 qw(
250 result
251 is_valid
252 num_errors
253 errors
254 num_warnings
255 warnings
256 val_uri
257 http_response
258 request_uri
259 som
260 )
261 }
262 = (
263 0 ▶ $val->validate( %{ $req_ref->{params} || {} } ),
Condition0%0/2
$req_ref->{'params'} || {}
l!l
00
MC/DC0%0/1
$req_ref->{'params'} || {}
$req_ref->{'params'}
Truth table0%0/2
A
A= $req_ref->{'params'}
Aresult
11
00
264 $val->is_valid,
265 scalar $val->errorcount,
266 [ $val->errors ],
267 scalar $val->warningcount,
268 [ $val->warnings ],
269 $val->validator_uri,
270 $val->response,
271 $val->request_uri,
272 $val->som,
273 );
274 0 ▶ unless ( $req_ref->{result} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req_ref->{"result"}) 0 0 0
275 0 delete $req_ref->{result};
276 0 $req_ref->{request_error} = $req_ref->{http_response}->status_line;
277 }
278  
279 0 my $refer_to_uri = URI->new( $req_ref->{request_uri} );
280  
281 0 my %refer_to_params = $refer_to_uri->query_form;
282 0 delete $refer_to_params{output};
283 0 $refer_to_uri->query_form( %refer_to_params );
284  
285 0 $req_ref->{refer_to_uri} = $refer_to_uri;
286  
287 0 undef;
288 }
289  
290 3 1;
291  
292 __END__
« App/PNGCrush.pm ↑ Summary WWW/WebDevout/BrowserSupportInfo.pm »