6 use List::Util qw[ first ];
9 'application/octet-stream' => 'HTTP::Body::Octetstream',
10 'application/x-www-form-urlencoded' => 'HTTP::Body::Urlencoded',
11 'multipart/form-data' => 'HTTP::Body::Multipart'
15 my ( $class, $content_type, $content_length ) = @_;
18 Carp::croak( $class, '->new( $content_type, $content_length )' );
21 my $type = first { index( lc($content_type), $_ ) >= 0 } keys %{$TYPES};
22 my $body = $TYPES->{ $type || 'application/octet-stream' };
32 content_length => $content_length,
33 content_type => $content_type,
40 bless( $self, $body );
48 if ( defined $_[0] ) {
49 $self->{buffer} .= $_[0];
50 $self->{length} += length( $_[0] );
53 unless ( $self->state eq 'done' ) {
57 return ( $self->length - $self->content_length );
62 $self->{body} = shift if @_;
67 return shift->{buffer};
71 return shift->{content_length};
75 return shift->{content_type};
83 return shift->{length};
87 Carp::croak('Define abstract method spin() in implementation');
92 $self->{state} = shift if @_;
93 return $self->{state};
101 my ( $name, $value ) = @_;
103 if ( exists $self->{param}->{$name} ) {
104 for ( $self->{param}->{$name} ) {
105 $_ = [$_] unless ref($_) eq "ARRAY";
110 $self->{param}->{$name} = $value;
114 return $self->{param};
122 my ( $name, $upload ) = @_;
124 if ( exists $self->{upload}->{$name} ) {
125 for ( $self->{upload}->{$name} ) {
126 $_ = [$_] unless ref($_) eq "ARRAY";
127 push( @$_, $upload );
131 $self->{upload}->{$name} = $upload;
135 return $self->{upload};