6 use List::Util qw[ first ];
8 use overload ( q/""/ => 'stringify', fallback => 1 );
10 our $VERSION = '0.01';
13 'application/octet-stream' => 'HTTP::Body::OctetStream',
14 'application/x-www-form-urlencoded' => 'HTTP::Body::UrlEncoded',
15 'multipart/form-data' => 'HTTP::Body::MultiPart'
20 HTTP::Body - HTTP Body Parser
37 my ( $class, $content_type, $content_length ) = @_;
40 Carp::croak( $class, '->new( $content_type, $content_length )' );
43 my $type = first { index( lc($content_type), $_ ) >= 0 } keys %{$TYPES};
44 my $body = $TYPES->{ $type || 'application/octet-stream' };
55 content_length => $content_length,
56 content_type => $content_type,
63 bless( $self, $body );
75 if ( defined $_[0] ) {
76 $self->{buffer} .= $_[0];
77 $self->{body} .= $_[0];
78 $self->{length} += length( $_[0] );
81 unless ( $self->state eq 'done' ) {
85 return ( $self->length - $self->content_length );
94 $self->{body} = shift if @_;
103 return shift->{buffer};
111 return shift->{content_length};
119 return shift->{content_type};
135 return shift->{length};
143 Carp::croak('Define abstract method spin() in implementation');
152 $self->{state} = shift if @_;
153 return $self->{state};
161 return shift->{body};
173 my ( $name, $value ) = @_;
175 if ( exists $self->{param}->{$name} ) {
176 for ( $self->{param}->{$name} ) {
177 $_ = [$_] unless ref($_) eq "ARRAY";
182 $self->{param}->{$name} = $value;
186 return $self->{param};
198 my ( $name, $upload ) = @_;
200 if ( exists $self->{upload}->{$name} ) {
201 for ( $self->{upload}->{$name} ) {
202 $_ = [$_] unless ref($_) eq "ARRAY";
203 push( @$_, $upload );
207 $self->{upload}->{$name} = $upload;
211 return $self->{upload};
218 Christian Hansen, C<ch@ngmedia.com>
219 Messed up by Sebastian Riedel
223 This library is free software . You can redistribute it and/or modify
224 it under the same terms as perl itself.