Changeset 16907 for lang/perl/Atomik

Show
Ignore:
Timestamp:
07/31/08 12:53:04 (6 years ago)
Author:
daisuke
Message:

separate out request generation to another module

Location:
lang/perl/Atomik/trunk/lib/Atomik
Files:
2 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Atomik/trunk/lib/Atomik/Client.pm

    r16906 r16907  
    44use Moose; 
    55use Atomik; 
     6use Atomik::Client::RequestFactory; 
    67use Atomik::MediaType; 
    78use Atomik::Service; 
     
    1718    isa => 'Str' 
    1819); 
     20 
     21has 'request_factory' => ( 
     22    is => 'rw', 
     23    isa => 'Atomik::Client::RequestFactory', 
     24    default => sub { Atomik::Client::RequestFactory->new() }, 
     25    handles => { 
     26        request_create => 'create' 
     27    } 
     28); 
     29     
    1930 
    2031has 'user_agent' => ( 
     
    4152    my $uri = $args{uri} || confess "no URI given to service()"; 
    4253 
    43     my $request = $self->create_request(%args); 
    44     my $response = $self->make_request( request => $request ); 
     54    my $request = $self->request_create(%args); 
     55    my $response = $self->send_request( request => $request ); 
    4556 
    4657    DEBUG( $response->as_string ); 
     
    7485} 
    7586 
    76 sub create_request { 
     87sub send_request { 
    7788    my ($self, %args) = @_; 
    78  
    79     my $method = $args{method} || 'GET'; 
    80     my $request =  HTTP::Request->new($method => $args{uri}); 
    81  
    82     if (my $h = $args{headers}) { 
    83         $request->headers->header(%$h); 
    84     } 
    85     return $request; 
    86 } 
    87  
    88 sub make_request { 
    89     my ($self, %args) = @_; 
    90  
    9189    my $request = $args{request}; 
    92     LWP::UserAgent->new()->request($request); 
     90    $self->user_agent->request($request); 
    9391} 
    9492