Added documentation and CPAN requirements updates from Daisuke Maki
[catagits/Catalyst-Action-REST.git] / t / lib / Test / Rest.pm
CommitLineData
7ad87df9 1#
2# Rest.pm
3# Created by: Adam Jacob, Marchex, <adam@marchex.com>
4# Created on: 10/16/2006 11:11:25 AM PDT
5#
6# $Id: $
7
8package Test::Rest;
9
10use strict;
11use warnings;
12
13use LWP::UserAgent;
14use Params::Validate qw(:all);
15
16sub new {
17 my $self = shift;
18 my %p = validate(@_,
19 {
20 content_type => { type => SCALAR },
21 },
22 );
23 my $ref = {
24 'ua' => LWP::UserAgent->new,
25 'content_type' => $p{'content_type'},
26 };
27 bless $ref, $self;
28}
29
30sub get {
31 my $self = shift;
32 my %p = validate(@_,
33 {
34 url => { type => SCALAR },
35 },
36 );
37 my $req = HTTP::Request->new('GET' => $p{'url'});
38 $req->content_type($self->{'content_type'});
39 return $req;
40}
41
42sub delete {
43 my $self = shift;
44 my %p = validate(@_,
45 {
46 url => { type => SCALAR },
47 },
48 );
49 my $req = HTTP::Request->new('DELETE' => $p{'url'});
50 $req->content_type($self->{'content_type'});
51 return $req;
52}
53
54sub put {
55 my $self = shift;
56 my %p = validate(@_,
57 {
58 url => { type => SCALAR },
59 data => 1,
60 },
61 );
62 my $req = HTTP::Request->new('PUT' => $p{'url'});
63 $req->content_type($self->{'content_type'});
64 $req->content_length(do { use bytes; length($p{'data'}) });
65 $req->content($p{'data'});
66 return $req;
67}
68
69sub post {
70 my $self = shift;
71 my %p = validate(@_,
72 {
73 url => { type => SCALAR },
74 data => { required => 1 },
75 },
76 );
77 my $req = HTTP::Request->new('POST' => $p{'url'});
78 $req->content_type($self->{'content_type'});
79 $req->content_length(do { use bytes; length($p{'data'}) });
80 $req->content($p{'data'});
81 return $req;
82}
83
84
851;
86