4 use namespace::autoclean;
7 use Params::Validate qw(:all);
11 my %p = validate( @_, {
12 content_type => { type => SCALAR },
16 'ua' => LWP::UserAgent->new,
17 'content_type' => $p{'content_type'},
23 my @non_data_methods = qw(HEAD GET DELETE OPTIONS);
24 foreach my $method (@non_data_methods) {
26 my $sub = lc($method);
32 url => { type => SCALAR },
33 headers => { type => HASHREF, default => {} },
36 my $req = HTTP::Request->new( "$method" => $p{'url'} );
37 $req->header( $_ => $p{headers}{$_} ) for keys %{ $p{headers} };
38 $req->content_type( $self->{'content_type'} );
43 my @data_methods = qw(PUT POST);
44 foreach my $method (@data_methods) {
46 my $sub = lc($method);
52 url => { type => SCALAR },
54 headers => { type => HASHREF, default => {} },
57 my $req = HTTP::Request->new( "$method" => $p{'url'} );
58 $req->header( $_ => $p{headers}{$_} ) for keys %{ $p{headers} };
59 $req->content_type( $self->{'content_type'} );
61 do { use bytes; length( $p{'data'} ) }
63 $req->content( $p{'data'} );