6 use List::Util qw[ first ];
7 use Scalar::Util qw[ blessed ];
10 'application/octet-stream' => 'HTTP::Body::Octetstream',
11 'application/x-www-form-urlencoded' => 'HTTP::Body::Urlencoded',
12 'multipart/form-data' => 'HTTP::Body::Multipart'
16 my ( $class, $content_type, $content_length ) = @_;
19 Carp::croak( $class, '->new( $content_type, $content_length )' );
22 my $type = first { index( lc($content_type), $_ ) >= 0 } keys %{ $PARSERS };
23 my $body = $PARSERS->{ $type || 'application/octet-stream' };
33 content_length => $content_length,
34 content_type => $content_type,
39 bless( $self, $body );
45 Carp::croak('Define abstract method add() in implementation');
54 $self->{body} = shift if @_;
59 return shift->{content_length};
63 return shift->{content_type};
71 my ( $name, $value ) = @_;
73 if ( exists $self->{param}->{$name} ) {
74 for ( $self->{param}->{$name} ) {
75 $_ = [$_] unless ref($_) eq "ARRAY";
80 $self->{param}->{$name} = $value;
84 return $self->{param};
92 my ( $name, $upload ) = @_;
94 if ( exists $self->{upload}->{$name} ) {
95 for ( $self->{upload}->{$name} ) {
96 $_ = [$_] unless ref($_) eq "ARRAY";
101 $self->{upload}->{$name} = $upload;
105 return $self->{upload};