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

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