line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::LastFM::TrackInfo; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENE'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Access to *.getInfo slices of the last.fm API |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.0205'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
2334
|
use Moo; |
|
1
|
|
|
|
|
8529
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
1559
|
use strictures 2; |
|
1
|
|
|
|
|
1330
|
|
|
1
|
|
|
|
|
48
|
|
10
|
1
|
|
|
1
|
|
561
|
use namespace::clean; |
|
1
|
|
|
|
|
9170
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
229
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
13
|
1
|
|
|
1
|
|
8
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
14
|
1
|
|
|
1
|
|
46
|
use Mojo::JSON qw(decode_json); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
15
|
1
|
|
|
1
|
|
5
|
use Mojo::URL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
16
|
1
|
|
|
1
|
|
35
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
456
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has api_key => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has method => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
default => sub { 'track' }, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has format => ( |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
default => sub { 'json' }, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has base => ( |
38
|
|
|
|
|
|
|
is => 'rw', |
39
|
|
|
|
|
|
|
default => sub { 'http://ws.audioscrobbler.com' }, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has version => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
default => sub { '2.0' }, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has ua => ( |
50
|
|
|
|
|
|
|
is => 'rw', |
51
|
|
|
|
|
|
|
default => sub { Mojo::UserAgent->new }, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub fetch { |
56
|
4
|
|
|
4
|
1
|
22334
|
my ( $self, %args ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
4
|
100
|
|
|
|
19
|
croak 'No artist provided' unless $args{artist}; |
59
|
3
|
100
|
100
|
|
|
27
|
croak 'No track provided' if $self->method eq 'track' && !$args{track}; |
60
|
2
|
100
|
66
|
|
|
19
|
croak 'No album provided' if $self->method eq 'album' && !$args{album}; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
10
|
my $url = Mojo::URL->new($self->base) |
63
|
|
|
|
|
|
|
->path($self->version) |
64
|
|
|
|
|
|
|
->query( |
65
|
|
|
|
|
|
|
%args, |
66
|
|
|
|
|
|
|
api_key => $self->api_key, |
67
|
|
|
|
|
|
|
method => $self->method . '.getInfo', |
68
|
|
|
|
|
|
|
format => $self->format, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
495
|
my $tx = $self->ua->get($url); |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
21976
|
my $data = $self->_handle_response($tx); |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
10
|
return $data; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _handle_response { |
79
|
1
|
|
|
1
|
|
4
|
my ($self, $tx) = @_; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
2
|
my $data; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
7
|
my $res = $tx->result; |
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
|
|
24
|
if ( $res->is_success ) { |
86
|
1
|
|
|
|
|
17
|
my $body = $res->body; |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
|
|
23
|
if ($self->format eq 'json') { |
89
|
|
|
|
|
|
|
try { |
90
|
1
|
|
|
1
|
|
150
|
$data = decode_json($body); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
catch { |
93
|
0
|
|
|
0
|
|
0
|
croak $body, "\n"; |
94
|
1
|
|
|
|
|
12
|
}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
0
|
|
|
|
|
0
|
$data = $body; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
0
|
|
|
|
|
0
|
croak 'Connection error: ', $res->message; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
145
|
return $data; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |