WWW/WebDevout/BrowserSupportInfo.pm

filter: Statementstmt 63.5% 68 / 107 Branchbran 33.3% 14 / 42 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 70.0% 14 / 20 Podpod 100% 4 / 4 totaltotal 56.8% 100 / 176 CC 27 SCAR 19.3
CC
27
Cov
54%
_wheel
20.0
_child_close
12.0
_fetch
11.5
CRAP 6.9
« WebService/Validator/CSS/W3C.pm ↑ Summary WWW/Alexa/TrafficRank.pm »
1 package POE::Component::WWW::WebDevout::BrowserSupportInfo;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '2.001002'; # VERSION
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use POE qw(Wheel::Run Filter::Reference Filter::Line);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use WWW::WebDevout::BrowserSupportInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub spawn {
Subroutine spawn: called CC=5 SCAR=16.6
Pod documented
13 1 my $package = shift;
14  
15 1 ▶ croak "Must have even number of arguments to spawn()"
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 1 1
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
BranchTrueFalseTotal
unless ref $params{"options"} eq "HASH" 1 0 1
24  
25 1 my $self = bless \%params, $package;
26  
27 $self->{session_id} = POE::Session->create(
28 object_states => [
29 $self => {
30 fetch => '_fetch',
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
BranchTrueFalseTotal
exists $params{'options'} ? : 0 1 1
45 )->ID;
46  
47 1 return $self;
48 }
49  
50 1 ▶sub _start {
Subroutine _start: called CC=4 SCAR=16.3
51 1 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
52 1 $self->{session_id} = $_[SESSION]->ID();
53 1 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 1 1
54 0 $kernel->alias_set( $self->{alias} );
55 }
56 else {
57 1 $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ );
58 }
59  
60 $self->{wheel} = POE::Wheel::Run->new(
61 0 ▶ Program => sub { _wheel( $self->{obj_args} || {} ); },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$self->{'obj_args'} || {}
l!l
00
MC/DC0%0/1
$self->{'obj_args'} || {}
$self->{'obj_args'}
Truth table0%0/2
A
A= $self->{'obj_args'}
Aresult
11
00
62 1 ▶ ErrorEvent => '_child_error',
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 1 1
63 CloseEvent => '_child_close',
64 StderrEvent => '_child_stderr',
65 StdoutEvent => '_child_stdout',
66 StdioFilter => POE::Filter::Reference->new,
67 StderrFilter => POE::Filter::Line->new,
68 ( $^O eq 'MSWin32' ? ( CloseOnCall => 0 ) : ( CloseOnCall => 1 ) ),
69 );
70  
71 $kernel->call('shutdown')
72 1 ▶ unless $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"wheel"} 0 1 1
73  
74 1 $kernel->sig_child( $self->{wheel}->PID, '_sig_chld' );
75 }
76  
77 1 ▶sub _sig_chld {
Subroutine _sig_chld: called CC=1 SCAR=0.0
78 1 $poe_kernel->sig_handled;
79 }
80  
81 0 ▶sub _child_close {
Subroutine _child_close: not called CC=3 SCAR=24.8
82 0 my ( $kernel, $self, $wheel_id ) = @_[ KERNEL, OBJECT, ARG0 ];
83  
84 warn "_child_close called (@_[ARG0..$#_])\n"
85 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
86  
87 0 delete $self->{wheel};
88 $kernel->yield('shutdown')
89 0 ▶ unless $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"shutdown"} 0 0 0
90  
91 0 undef;
92 }
93  
94 1 ▶sub _child_error {
Subroutine _child_error: called CC=3 SCAR=11.3
95 1 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
96 warn "_child_error called (@_[ARG0..$#_])\n"
97 1 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 1 0 1
98  
99 1 delete $self->{wheel};
100 $kernel->yield('shutdown')
101 1 ▶ unless $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"shutdown"} 0 1 1
102  
103 1 undef;
104 }
105  
106 0 ▶sub _child_stderr {
Subroutine _child_stderr: not called CC=2 SCAR=17.9
107 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
108 warn "_child_stderr: $_[ARG0]\n"
109 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
110  
111 0 undef;
112 }
113  
114 1 ▶sub _child_stdout {
Subroutine _child_stdout: called CC=1 SCAR=0.0
115 1 my ( $kernel, $self, $input ) = @_[ KERNEL, OBJECT, ARG0 ];
116  
117 1 my $session = delete $input->{sender};
118 1 my $event = delete $input->{event};
119  
120 1 delete @$input{ qw(login pass ua_args) };
121  
122 1 $kernel->post( $session, $event, $input );
123 1 $kernel->refcount_decrement( $session => __PACKAGE__ );
124  
125 1 undef;
126 }
127  
128 1 ▶sub shutdown {
Subroutine shutdown: called CC=1 SCAR=0.0
Pod documented
129 1 my $self = shift;
130 1 $poe_kernel->post( $self->{session_id} => 'shutdown' );
131 }
132  
133 1 ▶sub _shutdown {
Subroutine _shutdown: called CC=4 SCAR=14.2
134 1 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
135 1 $kernel->alarm_remove_all;
136 1 $kernel->alias_remove( $_ ) for $kernel->alias_list;
137 $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ )
138 1 ▶ unless $self->{alias};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"alias"} 1 0 1
139  
140 1 $self->{shutdown} = 1;
141 $self->{wheel}->shutdown_stdin
142 1 ▶ if $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"wheel"} 1 0 1
143 }
144  
145 0 ▶sub session_id {
Subroutine session_id: not called CC=1 SCAR=6.9
Pod documented
146 0 return $_[0]->{session_id};
147 }
148  
149 1 ▶sub fetch {
Subroutine fetch: called CC=1 SCAR=0.0
Pod documented
150 1 my $self = shift;
151 1 $poe_kernel->post( $self->{session_id} => 'fetch' => @_ );
152 }
153  
154 1 ▶sub _fetch {
Subroutine _fetch: called CC=7 SCAR=24.4
155 1 my ( $kernel, $self, $args )= @_[ KERNEL, OBJECT, ARG0 ];
156  
157 1 my $sender = $_[SENDER]->ID;
158  
159 return
160 1 ▶ if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 0 1 1
161  
162 $args->{ lc $_ } = delete $args->{ $_ }
163 1 for grep { !/^_/ } keys %{ $args };
164  
165 1 ▶ unless ( defined $args->{what} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->{"what"}) 0 1 1
166 0 carp "Missing the term to look up (`what` argument)";
167 0 return;
168 }
169  
170 1 ▶ unless ( defined $args->{event} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->{"event"}) 0 1 1
171 0 carp "Missing the name of the event for results (`event` argument)";
172 0 return;
173 }
174  
175 1 ▶ if ( $args->{session} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'session'}) { } 0 1 1
176 0 ▶ if ( my $ref = $kernel->alias_resolve( $args->{session} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $kernel->alias_resolve($args->{'session'})) { } 0 0 0
177 0 $args->{sender} = $ref->ID;
178 }
179 else {
180 0 carp "Could not resolve `session` parameter to a "
181 . "valid POE session. Aborting...";
182 0 return;
183 }
184 }
185 else {
186 1 $args->{sender} = $sender;
187 }
188  
189 1 $kernel->refcount_increment( $args->{sender} => __PACKAGE__ );
190 1 $self->{wheel}->put( $args );
191  
192 1 undef;
193 }
194  
195 0 ▶sub _wheel {
Subroutine _wheel: not called CC=4 SCAR=30.0
196 0 my $poco_args = shift;
197 0 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
198 0 binmode STDIN;
199 0 binmode STDOUT;
200 }
201  
202 0 my $wd = WWW::WebDevout::BrowserSupportInfo->new( %$poco_args );
203  
204 0 my $raw;
205 0 my $size = 4096;
206 0 my $filter = POE::Filter::Reference->new;
207  
208 0 ▶ while ( sysread STDIN, $raw, $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread STDIN, $raw, $size) 0 0 0
209 0 my $requests = $filter->get( [ $raw ] );
210 0 foreach my $req_ref ( @$requests ) {
211  
212 0 _retrieve_browser_info( $wd, $req_ref );
213  
214 0 my $response = $filter->put( [ $req_ref ] );
215 0 print STDOUT @$response;
216 }
217 }
218 }
219  
220 0 ▶sub _retrieve_browser_info {
Subroutine _retrieve_browser_info: not called CC=2 SCAR=17.9
221 0 my ( $wd, $req_ref ) = @_;
222  
223 0 my $results = $wd->fetch( $req_ref->{what} );
224 0 ▶ if ( defined $results ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $results) { } 0 0 0
225 0 @$req_ref{ qw( uri_info results ) }
226 = ( $wd->uri_info, $wd->browser_results );
227 }
228 else {
229 0 $req_ref->{error} = $wd->error;
230 }
231 0 undef;
232 }
233  
234 2 1;
235 __END__
« WebService/Validator/CSS/W3C.pm ↑ Summary WWW/Alexa/TrafficRank.pm »