File Coverage

blib/lib/POE/Component/Server/HTTPServer/ParameterParseHandler.pm
Criterion Covered Total %
statement 18 34 52.9
branch 0 6 0.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 25 48 52.0


line stmt bran cond sub pod time code
1             package POE::Component::Server::HTTPServer::ParameterParseHandler;
2 1     1   1234 use strict;
  1         1  
  1         1150  
3 1     1   12 use HTTP::Status;
  1         1  
  1         327  
4 1     1   821 use MIME::Types;
  1         5420  
  1         39  
5 1     1   9 use URI::Escape qw(uri_unescape);
  1         2  
  1         47  
6 1     1   5 use POE::Component::Server::HTTPServer::Handler;
  1         2  
  1         50  
7 1     1   6 use base 'POE::Component::Server::HTTPServer::Handler';
  1         2  
  1         359  
8              
9             #
10             # problems to fix:
11             # multi-valued params
12             # mutlipart form data
13             # the hash copying at the end of the POST handling could be more efficient
14             #
15             sub handle {
16 0     0 1   my $self = shift;
17 0           my $context = shift;
18 0           my $req = $context->{request};
19             # technically, for POST requests we could ignore (uri-)query params
20             # might as well grab them, though
21 0           my %p = $req->uri->query_form;
22 0           $context->{param} = \%p;
23 0 0         if ( $req->method eq 'POST' ) {
24 0 0         if ( $req->content_type ne 'application/x-www-form-urlencoded' ) {
25 0           print "XXX Don't know how to handle POST content encoding: ",
26             $req->content_type, "\n";
27             } else {
28 0           my $querydata = $req->content;
29             # following mapmap stolen from URI::_query
30 0 0         my %bodyp = map { s/\+/ /g; uri_unescape($_) }
  0            
  0            
31 0           map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/&/, $querydata);
32 0           foreach my $k (keys %bodyp) {
33 0           $context->{param}->{$k} = $bodyp{$k};
34             }
35             }
36             }
37 0           return H_CONT;
38             }
39              
40             1;
41             __END__