blib/lib/POE/Component/Server/SimpleContent.pm

filter: Statementstmt 77.9% 187 / 240 Branchbran 54.2% 51 / 94 Conditioncond 38.8% 21 / 54 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 88.2% 30 / 34 Podpod 91.6% 11 / 12 totaltotal 64.5% 300 / 465 SCAR 56.4
CC
75
Cov
67%
_generate_dir_listing
56.0
spawn
24.1
_generate_content
22.0
CRAP 281.7
↑ Summary
1 package POE::Component::Server::SimpleContent;
2  
3 # We export some stuff
4 9 require Exporter;
5 9 @ISA = qw( Exporter );
6 9 @EXPORT = qw(generate_301 generate_404 generate_403);
7  
8 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use POE qw( Wheel::ReadWrite Filter::Stream );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use CGI qw(:standard);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Filesys::Virtual::Plain;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use MIME::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 9 $VERSION = '1.14';
21  
22 sub spawn {
23 7 ▶ my $package = shift;
Subroutine spawn: called CC=16 SCAR=31.8
Pod documented
24 7 ▶ croak "$package needs an even number of parameters" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 7 7
25 7 my %params = @_;
26  
27 7 $params{lc $_} = delete $params{$_} for keys %params;
28  
29 die "$package requires a 'root_dir' argument\n"
30 7 ▶ unless $params{root_dir} and -d $params{root_dir};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"root_dir"} and -d $params{"root_dir"} 0 7 7
Condition33%1/3
$params{"root_dir"} and -d $params{"root_dir"}
!ll&&!rl&&r
007
MC/DC0%0/2
$params{"root_dir"} and -d $params{"root_dir"}
$params{"root_dir"} -d $params{"root_dir"}
Truth table33%1/3
A and B
A= $params{"root_dir"}B= -d $params{"root_dir"}
ABresult
0X0
100
111
31  
32 7 ▶ _massage_handlers( $params{handlers} ) if $params{handlers};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"handlers"} 0 7 7
33 7 ▶ $params{handlers} = { } unless $params{handlers};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"handlers"} 7 0 7
34  
35 7 my $options = delete $params{'options'};
36  
37 7 my $self = bless \%params, $package;
38  
39 $self->{vdir} = Filesys::Virtual::Plain->new( { root_path => $self->{root_dir} } )
40 7 ▶ or die "Could not create a Filesys::Virtual::Plain object for $self->{root_dir}\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"vdir"} = "Filesys::Virtual::Plain"->new({"root_path", $self->{"root_dir"}}) or die qq[Could not create a Filesys::Virtual::Plain object for $self->{"root_dir"}\n] 0 7 7
41  
42 7 $self->{mt} = MIME::Types->new();
43  
44 7 ▶ $self->{auto_index} = 1 unless defined ( $self->{auto_index} ) and $self->{auto_index} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"auto_index"} and $self->{"auto_index"} == 0 7 0 7
Condition33%1/3
defined $self->{"auto_index"} and $self->{"auto_index"} == 0
!ll&&!rl&&r
700
MC/DC0%0/2
defined $self->{"auto_index"} and $self->{"auto_index"} == 0
defined $self->{"auto_index"} $self->{"auto_index"} == 0
Truth table33%1/3
A and B
A= defined $self->{"auto_index"}B= $self->{"auto_index"} == 0
ABresult
0X0
100
111
45 7 ▶ $self->{index_file} = 'index.html' unless $self->{index_file};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"index_file"} 7 0 7
46  
47 7 ▶ $self->{prefix_fix} = delete $self->{alias_path} if $self->{alias_path};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"alias_path"} 2 5 7
48  
49 7 ▶ $self->{prefix_fix} = quotemeta( $self->{prefix_fix} ) if $self->{prefix_fix};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefix_fix"} 2 5 7
50  
51 7 my $mm;
52  
53 7 eval {
54 7 require File::MMagic::XS;
55 0 import File::MMagic::XS qw(:compat);
56 0 $mm = File::MMagic::XS->new();
57 };
58  
59 7 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
unless $mm 7 0 7
60 7 require File::MMagic;
61 0 $mm = File::MMagic->new();
62 } unless $mm;
63
64 7 $self->{mm} = $mm;
65  
66 7 ▶ $self->{session_id} = POE::Session->create(
Branch: 1 branch
BranchTrueFalseTotal
defined $options && ref $options eq 'HASH' ? : 0 7 7
Condition33%1/3
defined $options and ref $options eq "HASH"
!ll&&!rl&&r
700
MC/DC0%0/2
defined $options and ref $options eq "HASH"
defined $options ref $options eq "HASH"
Truth table33%1/3
A and B
A= defined $optionsB= ref $options eq "HASH"
ABresult
0X0
100
111
67 object_states => [
68 $self => {
69 request => '_request',
70 shutdown => '_shutdown',
71 -input => '_read_input',
72 -error => '_read_error',
73 },
74 $self => [ qw(_start) ],
75 ],
76 ( ( defined ( $options ) and ref ( $options ) eq 'HASH' ) ? ( options => $options ) : () ),
77 )->ID();
78  
79 7 return $self;
80 }
81  
82 sub _start {
83 7 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _start: called CC=2 SCAR=7.2
84  
85 7 $self->{session_id} = $_[SESSION]->ID();
86  
87 7 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 7 7
88 0 $kernel->alias_set( $self->{alias} );
89 } else {
90 7 $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ );
91 }
92  
93 7 return;
94 }
95  
96 sub request {
97 30 ▶ my $self = shift;
Subroutine request: called CC=1 SCAR=0.0
Pod documented
98 30 $poe_kernel->post( $self->session_id() => 'request' => @_ );
99 }
100  
101 sub _request {
102 30 ▶ my ($kernel,$self,$request,$response) = @_[KERNEL,OBJECT,ARG0 .. ARG1];
Subroutine _request: called CC=16 SCAR=30.2
103 30 my $sender = $_[SENDER]->ID();
104  
105 # Sanity check the $request and $response objects *sigh*
106 30 ▶ return unless $response and $response->isa("HTTP::Response");
Branch: 1 branch
BranchTrueFalseTotal
unless $response and $response->isa("HTTP::Response") 0 30 30
Condition33%1/3
$response and $response->isa("HTTP::Response")
!ll&&!rl&&r
0030
MC/DC0%0/2
$response and $response->isa("HTTP::Response")
$response $response->isa("HTTP::Response")
Truth table33%1/3
A and B
A= $responseB= $response->isa("HTTP::Response")
ABresult
0X0
100
111
107  
108 30 ▶ unless ( $request and $request->isa("HTTP::Request") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request and $request->isa("HTTP::Request")) 0 30 30
Condition33%1/3
$request and $request->isa("HTTP::Request")
!ll&&!rl&&r
0030
MC/DC0%0/2
$request and $request->isa("HTTP::Request")
$request $request->isa("HTTP::Request")
Truth table33%1/3
A and B
A= $requestB= $request->isa("HTTP::Request")
ABresult
0X0
100
111
109 0 $kernel->post( $sender => 'DONE' => $response );
110 0 return;
111 }
112  
113 30 my $path = uri_unescape( $request->uri->path );
114 30 my $realpath = $path;
115  
116 30 ▶ $realpath = $self->{prefix_path} . $path if $self->{prefix_path};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefix_path"} 10 20 30
117 30 ▶ $realpath =~ s/^$self->{prefix_fix}// if $self->{prefix_fix};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefix_fix"} 10 20 30
118  
119 SWITCH: {
120 30 ▶ if ( $self->{vdir}->test('d', $realpath) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vdir"}->test("d", $realpath)) 18 12 30
121 18 ▶ if ( $path !~ /\/$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/$]) 6 12 18
122 6 $path .= '/';
123 6 $response = $self->_generate_301( $path, $response );
124 6 last SWITCH;
125 }
126 12 ▶ if ( $self->{auto_index} and !$self->{vdir}->test('e', $realpath . $self->{index_file} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"auto_index"} and not $self->{"vdir"}->test("e", $realpath . $self->{"index_file"})) 0 12 12
Condition33%1/3
$self->{"auto_index"} and not $self->{"vdir"}->test("e", $realpath . $self->{"index_file"})
!ll&&!rl&&r
1200
MC/DC0%0/2
$self->{"auto_index"} and not $self->{"vdir"}->test("e", $realpath . $self->{"index_file"})
$self->{"auto_index"} not $self->{"vdir"}->test("e", $realpath . $self->{"index_file"})
Truth table33%1/3
A and not(B)
A= $self->{"auto_index"}B= not $self->{"vdir"}->test("e", $realpath . $self->{"index_file"})
ABresult
0X0
100
111
127 0 $response = $self->_generate_dir_listing( $path, $response );
128 0 last SWITCH;
129 }
130 12 ▶ if ( $self->{vdir}->test('e', $realpath . $self->{index_file} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vdir"}->test("e", $realpath . $self->{"index_file"})) 6 6 12
131 6 my ($filename, $directory, $suffix) = fileparse($self->{index_file}, keys %{ $self->{handlers} } );
132 6 ▶ if ( $suffix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix) 0 6 6
133 $kernel->post(
134 $self->{handlers}->{ $suffix }->{SESSION},
135 $self->{handlers}->{ $suffix }->{EVENT},
136 {
137 request => $request,
138 response => $response,
139 session => $sender,
140 script_name => $path . $self->{index_file},
141 script_filename => $self->{vdir}->root_path() . $realpath . $self->{index_file},
142 },
143 0 );
144 0 return;
145 }
146 6 $response = $self->_generate_content( $sender, $path . $self->{index_file}, $response );
147 6 last SWITCH;
148 }
149 6 $response = $self->_generate_403( $response );
150 6 last SWITCH;
151 }
152 12 ▶ if ( $self->{vdir}->test('e', $realpath) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vdir"}->test("e", $realpath)) 3 9 12
153 3 my ($filename, $directory, $suffix) = fileparse($realpath, keys %{ $self->{handlers} } );
154 3 ▶ if ( $suffix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix) 3 0 3
155 $kernel->post(
156 $self->{handlers}->{ $suffix }->{SESSION},
157 $self->{handlers}->{ $suffix }->{EVENT},
158 {
159 request => $request,
160 response => $response,
161 session => $sender,
162 script_name => $path,
163 3 script_filename => $self->{vdir}->root_path() . $realpath,
164 },
165 );
166 3 return;
167 }
168 0 $response = $self->_generate_content( $sender, $path, $response );
169 0 last SWITCH;
170 }
171 9 $response = $self->_generate_404( $response );
172 }
173  
174 27 ▶ $kernel->post( $sender => 'DONE' => $response ) if defined $response;
Branch: 1 branch
BranchTrueFalseTotal
if defined $response 21 6 27
175 27 undef;
176 }
177  
178 sub shutdown {
179 7 ▶ my $self = shift;
Subroutine shutdown: called CC=1 SCAR=0.0
Pod documented
180 7 $poe_kernel->post( $self->session_id() => 'shutdown' => @_ );
181 }
182  
183 sub _shutdown {
184 7 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _shutdown: called CC=3 SCAR=11.7
185  
186 7 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 7 7
187 0 $kernel->alias_remove( $_ ) for $kernel->alias_list();
188 } else {
189 7 $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ );
190 }
191 7 undef;
192 }
193  
194 sub session_id {
195 37 ▶ return $_[0]->{session_id};
Subroutine session_id: called CC=1 SCAR=0.0
Pod documented
196 }
197  
198 # Alias for deprecated function
199 sub autoindex {
200 0 ▶ warn "autoindex is deprecated: please use auto_index";
Subroutine autoindex: not called CC=1 SCAR=6.9
Pod undocumented
201 0 goto &auto_index;
202 }
203  
204 sub auto_index {
205 6 ▶ my $self = shift;
Subroutine auto_index: called CC=2 SCAR=7.0
Pod documented
206 6 my $value = shift;
207 6 ▶ return $self->{auto_index} unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 6 6
208 6 $self->{auto_index} = $value;
209 }
210  
211 sub index_file {
212 0 ▶ my $self = shift;
Subroutine index_file: not called CC=2 SCAR=17.9
Pod documented
213 0 my $value = shift;
214 0 ▶ return $self->{index_file} unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
215 0 $self->{index_file} = $value;
216 }
217  
218 sub _generate_404 {
219 9 ▶ my $self = shift;
Subroutine _generate_404: called CC=2 SCAR=7.1
220 9 ▶ my $response = shift || return;
Condition50%1/2
shift() || (return)
l!l
90
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
221 9 return generate_404( $response );
222 }
223  
224 sub generate_404 {
225 9 ▶ my $response = shift || return;
Subroutine generate_404: called CC=3 SCAR=11.2
Pod documented
Condition50%1/2
shift() || (return)
l!l
90
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
226 9 ▶ return unless $response->isa('HTTP::Response');
Branch: 1 branch
BranchTrueFalseTotal
unless $response->isa("HTTP::Response") 0 9 9
227 9 $response->code( 404 );
228 9 $response->header( 'Content-Type', 'text/html' );
229 9 $response->content( start_html('404') . h1('Not Found') . end_html );
230 9 return $response;
231 }
232  
233 sub _generate_403 {
234 6 ▶ my $self = shift;
Subroutine _generate_403: called CC=2 SCAR=7.1
235 6 ▶ my $response = shift || return;
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
236 6 return generate_403( $response );
237 }
238  
239 sub generate_403 {
240 6 ▶ my $response = shift || return;
Subroutine generate_403: called CC=3 SCAR=11.2
Pod documented
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
241 6 ▶ return unless $response->isa('HTTP::Response');
Branch: 1 branch
BranchTrueFalseTotal
unless $response->isa("HTTP::Response") 0 6 6
242 6 $response->code( 403 );
243 6 $response->header( 'Content-Type', 'text/html' );
244 6 $response->content( start_html('403') . h1('Forbidden') . end_html );
245 6 return $response;
246 }
247  
248 sub _generate_301 {
249 6 ▶ my $self = shift;
Subroutine _generate_301: called CC=3 SCAR=11.4
250 6 ▶ my $path = shift || return;
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
251 6 ▶ my $response = shift || return;
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
252 6 return generate_301( $path, $response );
253 }
254  
255 sub generate_301 {
256 6 ▶ my $path = shift || return;
Subroutine generate_301: called CC=4 SCAR=14.2
Pod documented
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
257 6 ▶ my $response = shift || return;
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
258 6 ▶ return unless $response->isa('HTTP::Response');
Branch: 1 branch
BranchTrueFalseTotal
unless $response->isa("HTTP::Response") 0 6 6
259 6 $response->code( 301 );
260 6 $response->header( 'Location' => $path );
261 6 $response->header( 'Content-Type', 'text/html' );
262 6 $response->content( start_html('301') . h1('Moved Permanently') . '<p>The document has moved <a href="' . $path . '">here</a>.</p>' . end_html );
263 6 return $response;
264 }
265  
266 sub _generate_dir_listing {
267 0 ▶ my $self = shift;
Subroutine _generate_dir_listing: not called CC=7 SCAR=40.3
268 0 ▶ my $path = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
269 0 ▶ my $response = shift || return undef;
Condition0%0/2
shift() || (return undef)
l!l
00
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
270 0 my $content = start_html('Index of ' . $path) . h1('Index of ' . $path) . qq{<HR>\n<UL>\n};
271  
272 0 my $realpath = $path;
273 0 ▶ $realpath = $self->{prefix_path} . $path if $self->{prefix_path};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefix_path"} 0 0 0
274 0 ▶ $realpath =~ s/^$self->{prefix_fix}// if $self->{prefix_fix};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefix_fix"} 0 0 0
275
276 0 foreach my $item ( $self->{vdir}->list( $realpath ) ) {
277 0 ▶ next if $item =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $item =~ /^\./ 0 0 0
278 0 $content .= qq{<LI><A HREF="$path$item">$item</A></LI>\n};
279 }
280
281 0 $content .= qq{</UL>\n} . end_html;
282 0 $response->code( 200 );
283 0 $response->header( 'Content-Type', 'text/html' );
284 0 $response->content( $content );
285 0 return $response;
286 }
287  
288 sub _read_input {
289 6 ▶ ${ $_[OBJECT]{read}{$_[ARG1]}{content} } .= $_[ARG0];
Subroutine _read_input: called CC=1 SCAR=0.0
290 }
291  
292 # Read finished
293 sub _read_error {
294 6 ▶ my ($self, $kernel, $error, $wheelid) = @_[ OBJECT, KERNEL, ARG1, ARG3 ];
Subroutine _read_error: called CC=4 SCAR=15.8
295 6 my $read = delete $self->{read}{$wheelid};
296 6 my $response = delete $read->{response};
297 6 my $content = delete $read->{content};
298 6 my $mimetype = delete $read->{mimetype};
299 6 my $sender = delete $read->{sender};
300  
301 6 delete $read->{wheel};
302
303 6 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) { } 0 6 6
304 0 $response->content("Internal Server Error");
305 0 $response->code(500);
306 }
307 else {
308 6 ▶ unless ( $mimetype ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mimetype) 0 6 6
309 0 ▶ if ( $self->{mm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'mm'}) { } 0 0 0
310 0 $mimetype = $self->{mm}->checktype_contents( $$content );
311 }
312 else {
313 0 $mimetype = 'application/octet-stream';
314 }
315 }
316 6 $response->code( 200 );
317 6 $response->content_type( $mimetype );
318 6 $response->content_ref( $content );
319 }
320
321 6 $kernel->post( $sender => 'DONE' => $response );
322 }
323  
324 sub _generate_content {
325 6 ▶ my $self = shift;
Subroutine _generate_content: called CC=11 SCAR=30.9
326 6 ▶ my $sender = shift || return;
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
327 6 ▶ my $path = shift || return;
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
328 6 ▶ my $response = shift || return;
Condition50%1/2
shift() || (return)
l!l
60
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
329 6 my $realpath = $path;
330 6 ▶ $realpath = $self->{prefix_path} . $path if $self->{prefix_path};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefix_path"} 2 4 6
331 6 ▶ $realpath =~ s/^$self->{prefix_fix}// if $self->{prefix_fix};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"prefix_fix"} 2 4 6
332  
333 6 my $mimetype = $self->{mt}->mimeTypeOf( $path );
334  
335 6 ▶ if ( my $fh = $self->{vdir}->open_read( $realpath ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = $self->{'vdir'}->open_read($realpath)) { } 6 0 6
336 6 binmode($fh);
337 6 ▶ if ( $^O eq 'MSWin32' or $self->{blocking} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32' or $self->{'blocking'}) { } 0 6 6
Condition33%1/3
$^O eq "MSWin32" or $self->{"blocking"}
l!l&&r!l&&!r
006
MC/DC0%0/2
$^O eq "MSWin32" or $self->{"blocking"}
$^O eq "MSWin32" $self->{"blocking"}
Truth table33%1/3
A or B
A= $^O eq "MSWin32"B= $self->{"blocking"}
ABresult
1X1
011
000
338 0 local $/ = undef;
339 0 my $content = <$fh>;
340 0 ▶ unless ( $mimetype ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mimetype) 0 0 0
341 0 ▶ if ( $self->{mm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'mm'}) { } 0 0 0
342 0 $mimetype = $self->{mm}->checktype_contents( $content );
343 }
344 else {
345 0 $mimetype = 'application/octet-stream';
346 }
347 }
348 0 $response->code( 200 );
349 0 $response->content_type( $mimetype );
350 0 $response->content_ref( \$content );
351 } else {
352 6 my $readwrite = POE::Wheel::ReadWrite->new(
353 Handle => $fh,
354 Filter => POE::Filter::Stream->new(),
355 InputEvent => "-input",
356 ErrorEvent => "-error",
357 );
358  
359 6 my $content = "";
360  
361 6 my $wheelid = $readwrite->ID;
362 6 my $readheap = {
363 wheel => $readwrite,
364 response => $response,
365 mimetype => $mimetype,
366 sender => $sender,
367 content => \$content,
368 };
369  
370 6 $self->{read}{$wheelid} = $readheap;
371  
372 6 return;
373 }
374 } else {
375 0 $response = $self->_generate_404( $response );
376 }
377  
378 0 return $response;
379 }
380  
381 sub _massage_handlers {
382 3 ▶ my $handler = shift || return;
Subroutine _massage_handlers: called CC=9 SCAR=24.8
Condition50%1/2
shift() || (return)
l!l
30
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
383 3 ▶ croak( "HANDLERS is not a ref to an hash!" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $handler and ref $handler eq "HASH" 0 3 3
Condition33%1/3
ref $handler and ref $handler eq "HASH"
!ll&&!rl&&r
003
MC/DC0%0/2
ref $handler and ref $handler eq "HASH"
ref $handler ref $handler eq "HASH"
Truth table33%1/3
A and B
A= ref $handlerB= ref $handler eq "HASH"
ABresult
0X0
100
111
384 unless ref $handler and ref $handler eq 'HASH';
385 3 foreach my $ext ( keys %{ $handler } ) {
386 3 ▶ delete $handler->{ $ext } unless ref $handler->{ $ext } eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $handler->{$ext} eq "HASH" 0 3 3
387 croak( "HANDLER for '$ext' does not have a SESSION argument!" )
388 3 ▶ unless $handler->{ $ext }->{'SESSION'};
Branch: 1 branch
BranchTrueFalseTotal
unless $handler->{$ext}{"SESSION"} 0 3 3
389 croak( "HANDLER for '$ext' does not have an EVENT argument!" )
390 3 ▶ unless $handler->{ $ext }->{'EVENT'};
Branch: 1 branch
BranchTrueFalseTotal
unless $handler->{$ext}{"EVENT"} 0 3 3
391 $handler->{ $ext }->{'SESSION'} = $handler->{ $ext }->{'SESSION'}->ID()
392 3 ▶ if UNIVERSAL::isa( $handler->{ $ext }->{'SESSION'}, 'POE::Session' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($handler->{$ext}{"SESSION"}, "POE::Session") 0 3 3
393 }
394 3 return 1;
395 }
396  
397 sub get_handlers {
398 0 ▶ my $self = shift;
Subroutine get_handlers: not called CC=1 SCAR=6.9
Pod documented
399 0 my $handlers = Storable::dclone( $self->{handlers} );
400 0 return $handlers;
401 }
402  
403 sub set_handlers {
404 3 ▶ my $self = shift;
Subroutine set_handlers: called CC=2 SCAR=7.0
Pod documented
405 3 ▶ my $handlers = shift || return;
Condition50%1/2
shift() || (return)
l!l
30
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
406 3 _massage_handlers( $handlers );
407 3 $self->{handlers} = $handlers;
408 3 return 1;
409 }
410  
411 9 1;
412  
413 __END__
↑ Summary