1 package HTTP::Body::Context;
5 use base 'Class::Accessor::Fast';
8 use HTTP::Headers qw[];
9 use Params::Validate qw[];
10 use Scalar::Util qw[];
12 __PACKAGE__->mk_accessors( qw[ content headers param upload ] );
15 my $class = ref $_[0] ? ref shift : shift;
16 my $params = Params::Validate::validate_with(
20 type => Params::Validate::ARRAYREF
21 | Params::Validate::HASHREF
22 | Params::Validate::OBJECT,
25 'isa HTTP::Headers instance' => sub {
26 return 1 unless Scalar::Util::blessed( $_[0] );
27 return $_[0]->isa('HTTP::Headers');
32 type => Params::Validate::OBJECT,
33 isa => 'Class::Param::Base',
37 type => Params::Validate::OBJECT,
38 isa => 'Class::Param::Base',
42 called => "$class\::new"
45 return bless( {}, $class )->initialize($params);
49 my ( $self, $params ) = @_;
51 if ( ref $params->{headers} eq 'ARRAY' ) {
52 $params->{headers} = HTTP::Headers->new( @{ $params->{headers} } );
55 if ( ref $params->{headers} eq 'HASH' ) {
56 $params->{headers} = HTTP::Headers->new( %{ $params->{headers} } );
59 $params->{param} ||= Class::Param->new;
60 $params->{upload} ||= Class::Param->new;
62 while ( my ( $param, $value ) = each( %{ $params } ) ) {
63 $self->$param($value);
70 return shift->headers->content_length(@_);
74 return shift->headers->content_type(@_);
78 return shift->headers->header(@_);