c20e9554b70d201a0d9a255d7bfa04c510dc9461
[catagits/HTTP-Body.git] / lib / HTTP / Body / Urlencoded.pm
1 package HTTP::Body::Urlencoded;
2
3 use strict;
4 use base 'HTTP::Body';
5 use bytes;
6
7 our $DECODE = qr/%u?([0-9a-fA-F]{2,4})/;
8
9 sub spin {
10     my $self = shift;
11     
12     return unless $self->length == $self->content_length;
13
14     for my $pair ( split( /[&;]/, $self->{buffer} ) ) {
15         
16         my ( $name, $value ) = split( /=/, $pair );
17         
18         next unless defined $name;
19         next unless defined $value;
20         
21         $name  =~ s/$DECODE/chr(hex($1))/eg;
22         $name  =~ tr/+/ /;
23         $value =~ s/$DECODE/chr(hex($1))/eg;
24         $value =~ tr/+/ /;
25         
26         $self->param( $name, $value );
27     }
28     
29     $self->{state}  = 'done';
30     $self->{buffer} = ''
31 }
32
33 1;