line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::8tracks::Response; |
2
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
86
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
84
|
|
4
|
3
|
|
|
3
|
|
7315
|
use HTTP::Status (); |
|
3
|
|
|
|
|
6301
|
|
|
3
|
|
|
|
|
785
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=pod |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
WebService::8tracks::Response - Thin wrapper of 8tracks API response hash |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $res = $api->user_mixes('dp'); # isa WebService::8tracks::Response |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Currently only is_success/is_error/is_*_error are provided |
17
|
|
|
|
|
|
|
$res->is_success or die $res->{status}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Access data via as normal hashref |
20
|
|
|
|
|
|
|
my @mixes = @{ $res->{mixes} }; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
21
|
|
|
21
|
0
|
38
|
my ($class, $args) = @_; |
26
|
21
|
|
|
|
|
241
|
return bless $args, $class; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _status_code { |
30
|
21
|
|
|
21
|
|
24
|
my $self = shift; |
31
|
21
|
50
|
|
|
|
110
|
$self->{status} =~ /^(\d+)/ or return undef; |
32
|
21
|
|
|
|
|
88
|
return $1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over 4 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item is_success |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item is_error |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item is_client_error |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item is_server_error |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Returns whether API response has corresponding status. Uses HTTP::Status internally. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=back |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub is_success { |
54
|
20
|
|
|
20
|
1
|
484
|
my $self = shift; |
55
|
20
|
50
|
|
|
|
53
|
my $code = $self->_status_code or return 0; |
56
|
20
|
|
|
|
|
91
|
return HTTP::Status::is_success($code); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
foreach my $is_error (qw(is_error is_client_error is_server_error)) { |
60
|
|
|
|
|
|
|
my $code = sub { |
61
|
1
|
|
|
1
|
|
14
|
my $self = shift; |
62
|
1
|
50
|
|
|
|
4
|
my $code = $self->_status_code or return 1; |
63
|
1
|
|
|
|
|
16
|
return HTTP::Status->can($is_error)->($code); |
64
|
|
|
|
|
|
|
}; |
65
|
3
|
|
|
3
|
|
21
|
no strict 'refs'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
176
|
|
66
|
|
|
|
|
|
|
*$is_error = $code; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |