line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PagSeguro::API::Request; |
2
|
3
|
|
|
3
|
|
12
|
use Moo; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
12
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
694
|
use Carp; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
192
|
|
5
|
3
|
|
|
3
|
|
1727
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
112930
|
|
|
3
|
|
|
|
|
98
|
|
6
|
3
|
|
|
3
|
|
1298
|
use PagSeguro::API::Response; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
833
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# attributes |
9
|
|
|
|
|
|
|
has ua => (is => 'rw', default => sub { LWP::UserAgent->new }); |
10
|
|
|
|
|
|
|
has param => (is => 'rw', default => sub { {} }); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# method |
14
|
|
|
|
|
|
|
sub get { |
15
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
16
|
0
|
0
|
|
|
|
|
my $args = (@_ % 2 == 0) ? {@_} : undef; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# error (required) |
19
|
0
|
0
|
|
|
|
|
croak "url cannot be undefined" unless $args->{url}; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $ua = $self->ua; |
22
|
0
|
|
|
|
|
|
my $res = $ua->get($args->{url}); |
23
|
0
|
|
|
|
|
|
return $self->_parse_response($res); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub post { |
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
28
|
0
|
0
|
|
|
|
|
my $args = (@_ % 2 == 0) ? {@_} : undef; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# error (required) |
31
|
0
|
0
|
|
|
|
|
croak "url cannot be undefined" unless $args->{url}; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $ua = $self->ua; |
34
|
0
|
|
|
|
|
|
my $res = $ua->post($args->{url}, $args->{params}); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $self->_parse_response($res); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _parse_response { |
40
|
0
|
|
|
0
|
|
|
my ($self, $res) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $response = PagSeguro::API::Response->new; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if ($res->is_success) { |
45
|
0
|
|
|
|
|
|
$response->data($res->decoded_content); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
0
|
|
|
|
|
|
$response->error($res->status_line); |
49
|
0
|
|
|
|
|
|
$response->data($res->decoded_content); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $response; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |