blib/lib/POE/Component/NonBlockingWrapper/Base.pm

filter: Statementstmt 13.5% 14 / 103 Branchbran 0.0% 0 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 19.0% 4 / 21 Podpod 0.0% 0 / 3 totaltotal 10.6% 18 / 169 CC 26 SCAR 31.5
CC
26
Cov
10%
_wheel_entry
72.0
spawn
30.0
_start
20.0
CRAP 23.3
↑ Summary
1 package POE::Component::NonBlockingWrapper::Base;
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 = '1.001003'; # VERSION
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use POE qw( Filter::Reference Filter::Line Wheel::Run );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub spawn {
Subroutine spawn: not called CC=5 SCAR=34.0
Pod undocumented
12 0 my $package = shift;
13 0 ▶ croak "$package requires an even number of arguments"
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 0 0
14 if @_ & 1;
15  
16 0 my %args = @_;
17  
18 0 $args{ lc $_ } = delete $args{ $_ } for keys %args;
19  
20 delete $args{options}
21 0 ▶ unless ref $args{options} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"options"} eq "HASH" 0 0 0
22  
23 0 my $self = bless \%args, $package;
24  
25 $self->{session_id} = POE::Session->create(
26 object_states => [
27 $self => {
28 $self->_methods_define( \%args ),
29 shutdown => '_shutdown',
30 },
31 $self => [
32 qw(
33 _child_error
34 _child_closed
35 _child_stdout
36 _child_stderr
37 _sig_child
38 _start
39 )
40 ]
41 ],
42 0 ▶ ( defined $args{options} ? ( options => $args{options} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'options'} ? : 0 0 0
43 )->ID();
44  
45 0 return $self;
46 }
47  
48  
49 0 ▶sub _start {
Subroutine _start: not called CC=4 SCAR=30.0
50 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
51 0 $self->{session_id} = $_[SESSION]->ID();
52  
53 0 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 0 0
54 0 $kernel->alias_set( $self->{alias} );
55 }
56 else {
57 0 $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ );
58 }
59  
60 $self->{wheel} = POE::Wheel::Run->new(
61 0 ▶ Program => sub{ $self->_wheel; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 0 ▶ ErrorEvent => '_child_error',
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
63 CloseEvent => '_child_close',
64 StdoutEvent => '_child_stdout',
65 StderrEvent => '_child_stderr',
66 StdioFilter => POE::Filter::Reference->new,
67 StderrFilter => POE::Filter::Line->new,
68 ( $^O eq 'MSWin32' ? ( CloseOnCall => 0 ) : ( CloseOnCall => 1 ) )
69 );
70  
71 $kernel->yield('shutdown')
72 0 ▶ unless $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"wheel"} 0 0 0
73  
74 0 $kernel->sig_child( $self->{wheel}->PID(), '_sig_child' );
75  
76 0 undef;
77 }
78  
79 0 ▶sub _sig_child {
Subroutine _sig_child: not called CC=1 SCAR=6.9
80 0 $poe_kernel->sig_handled;
81 }
82  
83 0 ▶sub session_id {
Subroutine session_id: not called CC=1 SCAR=6.9
Pod undocumented
84 0 return $_[0]->{session_id};
85 }
86  
87 0 ▶sub _wheel_entry {
Subroutine _wheel_entry: not called CC=8 SCAR=42.8
88 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
89 0 my $sender = $_[SENDER]->ID;
90  
91 return
92 0 ▶ if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 0 0 0
93  
94 0 my $args;
95 0 ▶ if ( ref $_[ARG0] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[10] eq 'HASH') { } 0 0 0
96 0 $args = { %{ $_[ARG0] } };
97 }
98 else {
99 0 carp "First parameter must be a hashref, trying to adjust...";
100 0 $args = { @_[ARG0 .. $#_] };
101 }
102  
103 $args->{ lc $_ } = delete $args->{ $_ }
104 0 for grep { !/^_/ } keys %$args;
105  
106 0 ▶ $self->_check_args( $args )
Branch: 1 branch
BranchTrueFalseTotal
$self->_check_args($args) or return 0 0 0
107 or return;
108  
109 0 ▶ unless ( defined $args->{event} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->{"event"}) 0 0 0
110 0 carp '`event` argument is not defined';
111 0 return;
112 }
113  
114 0 ▶ if ( $args->{session} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'session'}) { } 0 0 0
115 0 ▶ if ( my $ref = $kernel->alias_resolve( $args->{session} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $kernel->alias_resolve($args->{'session'})) { } 0 0 0
116 0 $args->{sender} = $ref->ID;
117 }
118 else {
119 0 carp "Could not resolve 'session' parameter to a valid"
120 . " POE session";
121 0 return;
122 }
123 }
124 else {
125 0 $args->{sender} = $sender;
126 }
127  
128 0 $kernel->refcount_increment( $args->{sender} => __PACKAGE__ );
129 0 $self->{wheel}->put( $args );
130  
131 0 undef;
132 }
133  
134 0 ▶sub shutdown {
Subroutine shutdown: not called CC=1 SCAR=6.9
Pod undocumented
135 0 my $self = shift;
136 0 $poe_kernel->call( $self->{session_id} => 'shutdown' => @_ );
137 }
138  
139 0 ▶sub _shutdown {
Subroutine _shutdown: not called CC=4 SCAR=30.0
140 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
141 0 $kernel->alarm_remove_all;
142 0 $kernel->alias_remove( $_ ) for $kernel->alias_list;
143 $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ )
144 0 ▶ unless $self->{alias};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"alias"} 0 0 0
145  
146 0 $self->{shutdown} = 1;
147  
148 $self->{wheel}->shutdown_stdin
149 0 ▶ if $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"wheel"} 0 0 0
150 }
151  
152 0 ▶sub _child_closed {
Subroutine _child_closed: not called CC=3 SCAR=24.8
153 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
154  
155 carp "_child_closed called (@_[ARG0..$#_])\n"
156 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
157  
158 0 delete $self->{wheel};
159 $kernel->yield('shutdown')
160 0 ▶ unless $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"shutdown"} 0 0 0
161  
162 0 undef;
163 }
164  
165 0 ▶sub _child_error {
Subroutine _child_error: not called CC=3 SCAR=24.8
166 0 my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
167 carp "_child_error called (@_[ARG0..$#_])\n"
168 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
169  
170 0 delete $self->{wheel};
171 $kernel->yield('shutdown')
172 0 ▶ unless $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"shutdown"} 0 0 0
173  
174 0 undef;
175 }
176  
177 0 ▶sub _child_stderr {
Subroutine _child_stderr: not called CC=2 SCAR=17.9
178 0 my $self = $_[ OBJECT ];
179 carp "_child_stderr: $_[ARG0]\n"
180 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
181  
182 0 undef;
183 }
184  
185 0 ▶sub _child_stdout {
Subroutine _child_stdout: not called CC=1 SCAR=6.9
186 0 my ( $kernel, $self, $input ) = @_[ KERNEL, OBJECT, ARG0 ];
187  
188 0 my $session = delete $input->{sender};
189 0 my $event = delete $input->{event};
190  
191 0 $kernel->post( $session, $event, $input );
192 0 $kernel->refcount_decrement( $session => __PACKAGE__ );
193  
194 0 undef;
195 }
196  
197 0 ▶sub _wheel {
Subroutine _wheel: not called CC=4 SCAR=30.0
198 0 my $self = shift;
199  
200 0 $self->_prepare_wheel;
201  
202 0 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
203 0 binmode STDIN;
204 0 binmode STDOUT;
205 }
206  
207 0 my $raw;
208 0 my $size = 4096;
209 0 my $filter = POE::Filter::Reference->new;
210  
211 0 ▶ while ( sysread STDIN, $raw, $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread STDIN, $raw, $size) 0 0 0
212 0 my $requests = $filter->get( [ $raw ] );
213 0 foreach my $req_ref ( @$requests ) {
214  
215 0 $self->_process_request( $req_ref ); # changes $req_ref
216  
217 0 my $response = $filter->put( [ $req_ref ] );
218 0 print STDOUT @$response;
219 }
220 }
221 }
222  
223 0 ▶sub _process_request {
Subroutine _process_request: not called CC=1 SCAR=6.9
224 0 croak 'Looks like the author of the module did not override '
225 . '_process_request() sub';
226 }
227  
228 0 ▶sub _check_args { 1; }
Subroutine _check_args: not called CC=1 SCAR=6.9
229 0 ▶sub _prepare_wheel { 1; }
Subroutine _prepare_wheel: not called CC=1 SCAR=6.9
230  
231 0 ▶sub _methods_define {
Subroutine _methods_define: not called CC=1 SCAR=6.9
232 0 croak 'Looks like the author of the module did not override '
233 . '_methods_define() sub';
234 }
235  
236  
237 2 1;
238 __END__
↑ Summary