| 1 | package POE::Component::WebService::Validator::HTML::W3C; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 7 | our $VERSION = '2.001002'; # VERSION | |||||||||||||
| 7 | |||||||||||||||
| 8 | 7 | ▶ | use WebService::Validator::HTML::W3C; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 7 | ▶ | use POE (qw( Wheel::Run Filter::Reference Filter::Line)); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 7 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | ▶ | sub spawn { | ||||||||||||
|
Subroutine
spawn: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||
| 13 | 1 | my $package = shift; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 1 | ▶ | croak "Even number of arguments must be passed to $package" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 16 | if @_ & 1; | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 1 | my %params = @_; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 1 | $params{ lc $_ } = delete $params{ $_ } for keys %params; | |||||||||||||
| 21 | |||||||||||||||
| 22 | delete $params{options} | ||||||||||||||
| 23 | 1 | ▶ | unless ref $params{options} eq 'HASH'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 1 | my $self = bless \%params, $package; | |||||||||||||
| 26 | |||||||||||||||
| 27 | $self->{session_id} = POE::Session->create( | ||||||||||||||
| 28 | object_states => [ | ||||||||||||||
| 29 | $self => { | ||||||||||||||
| 30 | validate => '_validate', | ||||||||||||||
| 31 | shutdown => '_shutdown', | ||||||||||||||
| 32 | }, | ||||||||||||||
| 33 | $self => [ | ||||||||||||||
| 34 | qw( | ||||||||||||||
| 35 | _child_error | ||||||||||||||
| 36 | _child_close | ||||||||||||||
| 37 | _child_stderr | ||||||||||||||
| 38 | _child_stdout | ||||||||||||||
| 39 | _sig_chld | ||||||||||||||
| 40 | _start | ||||||||||||||
| 41 | ) | ||||||||||||||
| 42 | ], | ||||||||||||||
| 43 | ], | ||||||||||||||
| 44 | 1 | ▶ | ( exists $params{options} ? ( options => $params{options} ) : () ), | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | )->ID; | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 1 | return $self; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 1 | ▶ | sub _start { | ||||||||||||
|
Subroutine
_start: called CC=4 SCAR=14.8
| |||||||||||||||
| 51 | 1 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||
| 52 | 1 | $self->{session_id} = $_[SESSION]->ID(); | |||||||||||||
| 53 | |||||||||||||||
| 54 | 1 | ▶ | if ( $self->{alias} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | 0 | $kernel->alias_set( $self->{alias} ); | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | else { | ||||||||||||||
| 58 | 1 | $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ ); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 1 | ▶ | $self->{wheel} = POE::Wheel::Run->new( | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | Program => \&_validate_wheel, | ||||||||||||||
| 63 | ErrorEvent => '_child_error', | ||||||||||||||
| 64 | CloseEvent => '_child_close', | ||||||||||||||
| 65 | StderrEvent => '_child_stderr', | ||||||||||||||
| 66 | StdoutEvent => '_child_stdout', | ||||||||||||||
| 67 | StdioFilter => POE::Filter::Reference->new, | ||||||||||||||
| 68 | StderrFilter => POE::Filter::Line->new, | ||||||||||||||
| 69 | ( $^O eq 'MSWin32' ? ( CloseOnCall => 0 ) : ( CloseOnCall => 1 ) ), | ||||||||||||||
| 70 | ); | ||||||||||||||
| 71 | |||||||||||||||
| 72 | $kernel->call('shutdown') | ||||||||||||||
| 73 | 1 | ▶ | unless $self->{wheel}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | |||||||||||||||
| 75 | 1 | $kernel->sig_child( $self->{wheel}->PID, '_sig_chld' ); | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 1 | ▶ | sub _sig_chld { | ||||||||||||
|
Subroutine
_sig_chld: called CC=1 SCAR=0.0
| |||||||||||||||
| 79 | 1 | $poe_kernel->sig_handled; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | ▶ | sub _child_close { | ||||||||||||
|
Subroutine
_child_close: not called CC=3 SCAR=24.8
| |||||||||||||||
| 83 | 0 | my ( $kernel, $self, $wheel_id ) = @_[ KERNEL, OBJECT, ARG0 ]; | |||||||||||||
| 84 | |||||||||||||||
| 85 | warn "_child_close called (@_[ARG0..$#_])\n" | ||||||||||||||
| 86 | 0 | ▶ | if $self->{debug}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | |||||||||||||||
| 88 | 0 | delete $self->{wheel}; | |||||||||||||
| 89 | $kernel->yield('shutdown') | ||||||||||||||
| 90 | 0 | ▶ | unless $self->{shutdown}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | |||||||||||||||
| 92 | 0 | undef; | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | |||||||||||||||
| 95 | 1 | ▶ | sub _child_error { | ||||||||||||
|
Subroutine
_child_error: called CC=3 SCAR=11.3
| |||||||||||||||
| 96 | 1 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||
| 97 | warn "_child_error called (@_[ARG0..$#_])\n" | ||||||||||||||
| 98 | 1 | ▶ | if $self->{debug}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 99 | |||||||||||||||
| 100 | 1 | delete $self->{wheel}; | |||||||||||||
| 101 | $kernel->yield('shutdown') | ||||||||||||||
| 102 | 1 | ▶ | unless $self->{shutdown}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 103 | |||||||||||||||
| 104 | 1 | undef; | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | |||||||||||||||
| 107 | 0 | ▶ | sub _child_stderr { | ||||||||||||
|
Subroutine
_child_stderr: not called CC=2 SCAR=17.9
| |||||||||||||||
| 108 | 0 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||
| 109 | warn "_child_stderr: $_[ARG0]\n" | ||||||||||||||
| 110 | 0 | ▶ | if $self->{debug}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | |||||||||||||||
| 112 | 0 | undef; | |||||||||||||
| 113 | } | ||||||||||||||
| 114 | |||||||||||||||
| 115 | 0 | ▶ | sub _child_stdout { | ||||||||||||
|
Subroutine
_child_stdout: not called CC=1 SCAR=6.9
| |||||||||||||||
| 116 | 0 | my ( $kernel, $self, $input ) = @_[ KERNEL, OBJECT, ARG0 ]; | |||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | my $session = delete $input->{sender}; | |||||||||||||
| 119 | 0 | my $event = delete $input->{event}; | |||||||||||||
| 120 | 0 | $kernel->post( $session, $event, $input ); | |||||||||||||
| 121 | 0 | $kernel->refcount_decrement( $session => __PACKAGE__ ); | |||||||||||||
| 122 | |||||||||||||||
| 123 | 0 | undef; | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | |||||||||||||||
| 126 | 1 | ▶ | sub shutdown { | ||||||||||||
|
Subroutine
shutdown: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 127 | 1 | my $self = shift; | |||||||||||||
| 128 | 1 | $poe_kernel->post( $self->{session_id} => 'shutdown' ); | |||||||||||||
| 129 | } | ||||||||||||||
| 130 | |||||||||||||||
| 131 | 1 | ▶ | sub _shutdown { | ||||||||||||
|
Subroutine
_shutdown: called CC=4 SCAR=14.2
| |||||||||||||||
| 132 | 1 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||
| 133 | 1 | $kernel->alarm_remove_all; | |||||||||||||
| 134 | 1 | $kernel->alias_remove( $_ ) for $kernel->alias_list; | |||||||||||||
| 135 | $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ ) | ||||||||||||||
| 136 | 1 | ▶ | unless $self->{alias}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 137 | |||||||||||||||
| 138 | 1 | $self->{shutdown} = 1; | |||||||||||||
| 139 | $self->{wheel}->shutdown_stdin | ||||||||||||||
| 140 | 1 | ▶ | if $self->{wheel}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 141 | } | ||||||||||||||
| 142 | |||||||||||||||
| 143 | 0 | ▶ | sub session_id { | ||||||||||||
|
Subroutine
session_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 144 | 0 | return $_[0]->{session_id}; | |||||||||||||
| 145 | } | ||||||||||||||
| 146 | |||||||||||||||
| 147 | 0 | ▶ | sub validate { | ||||||||||||
|
Subroutine
validate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 148 | 0 | my $self = shift; | |||||||||||||
| 149 | 0 | $poe_kernel->post( $self->{session_id} => 'validate' => @_ ); | |||||||||||||
| 150 | } | ||||||||||||||
| 151 | |||||||||||||||
| 152 | 0 | ▶ | sub _validate { | ||||||||||||
|
Subroutine
_validate: not called CC=10 SCAR=47.0
| |||||||||||||||
| 153 | 0 | my ( $kernel, $self ) = @_[KERNEL, OBJECT]; | |||||||||||||
| 154 | |||||||||||||||
| 155 | 0 | my $sender = $_[SENDER]->ID; | |||||||||||||
| 156 | |||||||||||||||
| 157 | return | ||||||||||||||
| 158 | 0 | ▶ | if $self->{shutdown}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 159 | |||||||||||||||
| 160 | 0 | my $args; | |||||||||||||
| 161 | 0 | ▶ | if ( ref $_[ARG0] eq 'HASH' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 162 | 0 | $args = { %{ $_[ARG0] } }; | |||||||||||||
| 163 | } | ||||||||||||||
| 164 | else { | ||||||||||||||
| 165 | 0 | warn "Argument must be a hashref, trying to adjust"; | |||||||||||||
| 166 | 0 | $args = { @_[ARG0 .. $#_] }; | |||||||||||||
| 167 | } | ||||||||||||||
| 168 | |||||||||||||||
| 169 | $args->{ lc $_ } = delete $args->{ $_ } | ||||||||||||||
| 170 | 0 | for grep { !/^_/ } keys %{ $args }; | |||||||||||||
| 171 | |||||||||||||||
| 172 | 0 | ▶ | unless ( $args->{event} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 173 | 0 | warn "No `event` parameter specified. Aborting..."; | |||||||||||||
| 174 | 0 | return; | |||||||||||||
| 175 | } | ||||||||||||||
| 176 | |||||||||||||||
| 177 | 0 | ▶ | unless ( $args->{in} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 178 | 0 | warn "No `in` parameter specified. Aborting..."; | |||||||||||||
| 179 | 0 | return; | |||||||||||||
| 180 | } | ||||||||||||||
| 181 | |||||||||||||||
| 182 | 0 | ▶ | unless ( exists $args->{options}{detailed} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 183 | 0 | $args->{options}{detailed} = 1; | |||||||||||||
| 184 | } | ||||||||||||||
| 185 | |||||||||||||||
| 186 | 0 | ▶ | if ( $args->{type} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 187 | 0 | $args->{type} = lc $args->{type}; | |||||||||||||
| 188 | } | ||||||||||||||
| 189 | else { | ||||||||||||||
| 190 | 0 | $args->{type} = 'uri'; | |||||||||||||
| 191 | } | ||||||||||||||
| 192 | |||||||||||||||
| 193 | 0 | ▶ | if ( $args->{session} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 194 | 0 | ▶ | if ( my $ref = $kernel->alias_resolve( $args->{session} ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 195 | 0 | $args->{sender} = $ref->ID; | |||||||||||||
| 196 | } | ||||||||||||||
| 197 | else { | ||||||||||||||
| 198 | 0 | warn "Could not resolve `session` parameter to a " | |||||||||||||
| 199 | . "valid POE session. Aborting..."; | ||||||||||||||
| 200 | 0 | return; | |||||||||||||
| 201 | } | ||||||||||||||
| 202 | } | ||||||||||||||
| 203 | else { | ||||||||||||||
| 204 | 0 | $args->{sender} = $sender; | |||||||||||||
| 205 | } | ||||||||||||||
| 206 | 0 | $kernel->refcount_increment( $args->{sender} => __PACKAGE__ ); | |||||||||||||
| 207 | 0 | $self->{wheel}->put( $args ); | |||||||||||||
| 208 | |||||||||||||||
| 209 | 0 | undef; | |||||||||||||
| 210 | } | ||||||||||||||
| 211 | |||||||||||||||
| 212 | 0 | ▶ | sub _validate_wheel { | ||||||||||||
|
Subroutine
_validate_wheel: not called CC=12 SCAR=50.5
| |||||||||||||||
| 213 | 0 | ▶ | if ( $^O eq 'MSWin32' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 214 | 0 | binmode STDIN; | |||||||||||||
| 215 | 0 | binmode STDOUT; | |||||||||||||
| 216 | } | ||||||||||||||
| 217 | |||||||||||||||
| 218 | 0 | my $raw; | |||||||||||||
| 219 | 0 | my $size = 4096; | |||||||||||||
| 220 | 0 | my $filter = POE::Filter::Reference->new; | |||||||||||||
| 221 | |||||||||||||||
| 222 | 0 | ▶ | while ( sysread STDIN, $raw, $size ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 223 | 0 | my $requests = $filter->get( [ $raw ] ); | |||||||||||||
| 224 | 0 | foreach my $req ( @$requests ) { | |||||||||||||
| 225 | |||||||||||||||
| 226 | my $val | ||||||||||||||
| 227 | 0 | = WebService::Validator::HTML::W3C->new( %{ $req->{options} } ); | |||||||||||||
| 228 | |||||||||||||||
| 229 | 0 | my $val_success = 0; | |||||||||||||
| 230 | 0 | ▶ | if ( $req->{type} eq 'file' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 231 | 0 | $val_success = $val->validate_file( $req->{in} ); | |||||||||||||
| 232 | } | ||||||||||||||
| 233 | elsif ( $req->{type} eq 'markup' ) { | ||||||||||||||
| 234 | 0 | $val_success = $val->validate_markup( $req->{in} ); | |||||||||||||
| 235 | } | ||||||||||||||
| 236 | else { | ||||||||||||||
| 237 | 0 | $val_success = $val->validate( $req->{in} ); | |||||||||||||
| 238 | } | ||||||||||||||
| 239 | |||||||||||||||
| 240 | 0 | ▶ | if ( $val_success ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 241 | |||||||||||||||
| 242 | 0 | @{ $req }{ | |||||||||||||
| 243 | 0 | qw( | |||||||||||||
| 244 | is_valid | ||||||||||||||
| 245 | num_errors | ||||||||||||||
| 246 | ) | ||||||||||||||
| 247 | } | ||||||||||||||
| 248 | = ( | ||||||||||||||
| 249 | $val->is_valid, | ||||||||||||||
| 250 | $val->num_errors, | ||||||||||||||
| 251 | ); | ||||||||||||||
| 252 | |||||||||||||||
| 253 | 0 | $req->{errors} = undef; | |||||||||||||
| 254 | 0 | ▶ | foreach my $error ( @{ $val->errors || [] } ) { | ||||||||||||
|
Condition0%0/2
$val->errors || []
MC/DC0%0/1
$val->errors || []
$val->errors
Truth table0%0/2
A
A= $val->errors
| |||||||||||||||
| 255 | 0 | push @{ $req->{errors} }, { | |||||||||||||
| 256 | line => $error->line, | ||||||||||||||
| 257 | col => $error->col, | ||||||||||||||
| 258 | msg => $error->msg, | ||||||||||||||
| 259 | }; | ||||||||||||||
| 260 | } | ||||||||||||||
| 261 | 0 | ▶ | if ( $req->{get_warnings} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 262 | 0 | $req->{'warnings'} = undef; | |||||||||||||
| 263 | 0 | ▶ | foreach my $warning ( @{ $val->warnings || [] } ) { | ||||||||||||
|
Condition0%0/2
$val->warnings || []
MC/DC0%0/1
$val->warnings || []
$val->warnings
Truth table0%0/2
A
A= $val->warnings
| |||||||||||||||
| 264 | 0 | push @{ $req->{'warnings'} }, { | |||||||||||||
| 265 | line => $warning->line, | ||||||||||||||
| 266 | col => $warning->col, | ||||||||||||||
| 267 | msg => $warning->msg, | ||||||||||||||
| 268 | } | ||||||||||||||
| 269 | } | ||||||||||||||
| 270 | } | ||||||||||||||
| 271 | |||||||||||||||
| 272 | } | ||||||||||||||
| 273 | else { | ||||||||||||||
| 274 | 0 | $req->{validator_error} = $val->validator_error; | |||||||||||||
| 275 | } | ||||||||||||||
| 276 | 0 | $req->{validator_uri} = $val->validator_uri; | |||||||||||||
| 277 | |||||||||||||||
| 278 | 0 | my $response = $filter->put( [ $req ] ); | |||||||||||||
| 279 | 0 | print STDOUT @$response; | |||||||||||||
| 280 | } | ||||||||||||||
| 281 | } | ||||||||||||||
| 282 | } | ||||||||||||||
| 283 | |||||||||||||||
| 284 | 7 | 1; | |||||||||||||
| 285 | __END__ | ||||||||||||||