| 1 | package Net::Rexster::Request; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Net::Rexster::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Encode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use URI::Escape; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | has 'ua' => (is => 'ro', isa => "LWP::UserAgent", default => sub { LWP::UserAgent->new } ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 16 | |||||||||||
| 17 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 18 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub get { shift->_call('GET', @_) } | ||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 21 | 0 | ▶ | sub post { shift->_call('POST', @_) } | ||||||||
|
Subroutine
post: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 22 | 0 | ▶ | sub put { shift->_call('PUT', @_) } | ||||||||
|
Subroutine
put: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 23 | 0 | ▶ | sub delete { shift->_call('DELETE', @_) } | ||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 24 | |||||||||||
| 25 | # Send query to server by LWP::UserAgent | ||||||||||
| 26 | 0 | ▶ | sub _call { | ||||||||
|
Subroutine
_call: not called CC=2 SCAR=17.9
| |||||||||||
| 27 | 0 | my ($self, $method, $uri, $data, $args) = @_; | |||||||||
| 28 | |||||||||||
| 29 | # URI encoding for # and the language which needs ecoding, e.g. Japanese | ||||||||||
| 30 | 0 | $uri = uri_escape_utf8($uri, "^A-Za-z0-9\/\:\&\+\=\?\(\)\'\,\*\;"); | |||||||||
| 31 | 0 | my $req = HTTP::Request->new($method, $uri); | |||||||||
| 32 | |||||||||||
| 33 | 0 | my $response = $self->ua->request($req); | |||||||||
| 34 | 0 | ▶ | unless ($response->is_success){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | warn "Failed to get response from server...\n"; | |||||||||
| 36 | 0 | return Net::Rexster::Response->new(content => {}); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | # Decode from JSON and utf8 | ||||||||||
| 40 | 0 | return Net::Rexster::Response->new(content => JSON->new->utf8->decode(decode_utf8($response->content))); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 2 | 1; # Magic true value required at end of module | |||||||||