Cleaned HTTP::Body a bit
[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/%([0-9a-fA-F]{2})/;
8
9 =head1 NAME
10
11 HTTP::Body - HTTP Body UrlEncoded Parser
12
13 =head1 SYNOPSIS
14
15     use HTTP::Body::UrlEncoded;
16
17 =head1 DESCRIPTION
18
19 HTTP Body UrlEncoded Parser.
20
21 =head1 METHODS
22
23 =over 4
24
25 =item spin
26
27 =cut
28
29 sub spin {
30     my $self = shift;
31
32     return unless $self->length == $self->content_length;
33
34     for my $pair ( split( /[&;]/, $self->{buffer} ) ) {
35
36         my ( $name, $value ) = split( /=/, $pair );
37
38         next unless defined $name;
39         next unless defined $value;
40
41         $name  =~ tr/+/ /;
42         $name  =~ s/$DECODE/chr(hex($1))/eg;
43         $value =~ tr/+/ /;
44         $value =~ s/$DECODE/chr(hex($1))/eg;
45
46         $self->param( $name, $value );
47     }
48
49     $self->{buffer} = '';
50     $self->{state}  = 'done';
51 }
52
53 =back
54
55 =head1 AUTHOR
56
57 Christian Hansen, C<ch@ngmedia.com>
58
59 =head1 LICENSE
60
61 This library is free software . You can redistribute it and/or modify 
62 it under the same terms as perl itself.
63
64 =cut
65
66 1;