line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::MusicBrainz::Request; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
40
|
use Mojo::Base -base; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
33
|
|
4
|
5
|
|
|
5
|
|
3438
|
use Mojo::UserAgent; |
|
5
|
|
|
|
|
1242415
|
|
|
5
|
|
|
|
|
48
|
|
5
|
5
|
|
|
5
|
|
220
|
use Mojo::URL; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
20
|
|
6
|
5
|
|
|
5
|
|
146
|
use Mojo::Util qw/dumper/; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
3635
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has url_base => 'http://musicbrainz.org/ws/2'; |
9
|
|
|
|
|
|
|
has ua => sub { Mojo::UserAgent->new() }; |
10
|
|
|
|
|
|
|
has 'format' => 'json'; |
11
|
|
|
|
|
|
|
has 'search_resource'; |
12
|
|
|
|
|
|
|
has 'mbid'; |
13
|
|
|
|
|
|
|
has 'discid'; |
14
|
|
|
|
|
|
|
has 'inc' => sub { [] }; |
15
|
|
|
|
|
|
|
has 'query_params'; |
16
|
|
|
|
|
|
|
has offset => 0; |
17
|
|
|
|
|
|
|
has debug => sub { $ENV{MUSICBRAINZ_DEBUG} || 0 };; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.0'; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
5
|
|
36
|
binmode STDOUT, ":encoding(UTF-8)"; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
52
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub make_url { |
24
|
22
|
|
|
22
|
0
|
62
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
22
|
|
|
|
|
51
|
my @url_parts; |
27
|
|
|
|
|
|
|
|
28
|
22
|
|
|
|
|
107
|
push @url_parts, $self->url_base(); |
29
|
22
|
|
|
|
|
188
|
push @url_parts, $self->search_resource(); |
30
|
22
|
100
|
|
|
|
126
|
push @url_parts, $self->mbid() if $self->mbid; |
31
|
22
|
50
|
|
|
|
186
|
push @url_parts, $self->discid() if $self->discid; |
32
|
|
|
|
|
|
|
|
33
|
22
|
|
|
|
|
220
|
my $url_str = join '/', @url_parts; |
34
|
|
|
|
|
|
|
|
35
|
22
|
|
|
|
|
98
|
$url_str .= '?fmt=' . $self->format; |
36
|
|
|
|
|
|
|
|
37
|
22
|
100
|
|
|
|
171
|
if(scalar(@{ $self->inc }) > 0) { |
|
22
|
|
|
|
|
74
|
|
38
|
5
|
|
|
|
|
37
|
my $inc_query = join '+', @{ $self->inc }; |
|
5
|
|
|
|
|
37
|
|
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
|
|
35
|
$url_str .= '&inc=' . $inc_query; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
22
|
|
|
|
|
73
|
my @extra_params; |
44
|
|
|
|
|
|
|
|
45
|
22
|
|
|
|
|
47
|
foreach my $key (keys %{ $self->query_params }) { |
|
22
|
|
|
|
|
75
|
|
46
|
19
|
|
|
|
|
152
|
push @extra_params, $key . ':"' . $self->query_params->{$key} . '"'; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
22
|
100
|
|
|
|
167
|
if(scalar(@extra_params) > 0) { |
50
|
12
|
|
|
|
|
49
|
my $extra_param_str = join ' AND ', @extra_params; |
51
|
|
|
|
|
|
|
|
52
|
12
|
|
|
|
|
51
|
$url_str .= '&query=' . $extra_param_str; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
22
|
|
|
|
|
118
|
$url_str .= '&offset=' . $self->offset(); |
56
|
|
|
|
|
|
|
|
57
|
22
|
50
|
|
|
|
205
|
print "REQUEST URL: $url_str\n" if $self->debug(); |
58
|
|
|
|
|
|
|
|
59
|
22
|
|
|
|
|
246
|
my $url = Mojo::URL->new($url_str); |
60
|
|
|
|
|
|
|
|
61
|
22
|
|
|
|
|
4603
|
return $url; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub result { |
65
|
22
|
|
|
22
|
0
|
235
|
my $self = shift; |
66
|
|
|
|
|
|
|
|
67
|
22
|
|
|
|
|
88
|
my $request_url = $self->make_url(); |
68
|
|
|
|
|
|
|
|
69
|
22
|
|
|
|
|
97
|
my $get_result = $self->ua->get($request_url => { 'Accept-Encoding' => 'application/json' })->result; |
70
|
|
|
|
|
|
|
|
71
|
22
|
|
|
|
|
2038346
|
my $result_formatted; |
72
|
|
|
|
|
|
|
|
73
|
22
|
100
|
|
|
|
135
|
if($self->format eq 'json') { |
|
|
50
|
|
|
|
|
|
74
|
19
|
|
|
|
|
208
|
$result_formatted = $get_result->json; |
75
|
19
|
50
|
|
|
|
439953
|
print "JSON RESULT: ", dumper($get_result->json) if $self->debug; |
76
|
|
|
|
|
|
|
} elsif($self->format eq 'xml') { |
77
|
3
|
|
|
|
|
68
|
$result_formatted = $get_result->dom; |
78
|
3
|
50
|
|
|
|
11053
|
print "XML RESULT: ", $get_result->dom->to_string, "\n" if $self->debug; |
79
|
|
|
|
|
|
|
} else { |
80
|
0
|
|
|
|
|
0
|
warn "Unsupported format type : $self->format"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
22
|
|
|
|
|
310
|
return $result_formatted; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
WebService::MusicBrainz::Request |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SYNOPSIS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 ABSTRACT |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
WebService::MusicBrainz::Request - Handle queries using the MusicBrainz WebService API version 2 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 METHODS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item Bob Faist |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Copyright 2006-2017 by Bob Faist |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
113
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 SEE ALSO |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
http://wiki.musicbrainz.org/XMLWebService |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |