line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::GNUDB::Cd; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Net::GNUDB::Cd - Base class for L results. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Net::GNUDB::Cd; |
12
|
|
|
|
|
|
|
my $config = { |
13
|
|
|
|
|
|
|
'id' => '950cc10c', |
14
|
|
|
|
|
|
|
'genre' => 'misc' |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
my $cd = Net::GNUDB::Cd->new($config); |
17
|
|
|
|
|
|
|
my $id = $cd->getId(); |
18
|
|
|
|
|
|
|
my $genre = $cd->getGenre(); |
19
|
|
|
|
|
|
|
my $tracks = $cd->getTracks(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Base class for L results, normally not instantiated directly but can used to lookup a specific GNUDB entry. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
|
25182
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
109
|
|
30
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
111
|
|
31
|
3
|
|
|
3
|
|
79
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
465
|
|
32
|
3
|
|
|
3
|
|
3379
|
use Net::FreeDB2; |
|
3
|
|
|
|
|
38631
|
|
|
3
|
|
|
|
|
145
|
|
33
|
3
|
|
|
3
|
|
5925
|
use Net::FreeDB2::Match; |
|
3
|
|
|
|
|
5571
|
|
|
3
|
|
|
|
|
131
|
|
34
|
3
|
|
|
3
|
|
4007
|
use Net::FreeDB2::Entry; #see bug: https://rt.cpan.org/Ticket/Display.html?id=69089 |
|
3
|
|
|
|
|
65853
|
|
|
3
|
|
|
|
|
2093
|
|
35
|
|
|
|
|
|
|
######################################################### |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new($config) |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $config = { |
40
|
|
|
|
|
|
|
'id' => '950cc10c', |
41
|
|
|
|
|
|
|
'genre' => 'misc' |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
my $cd = Net::GNUDB::Cd->new($config); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Constructor, returns a new instance of the search CD object. Requires all two of the above elements in the provided hash reference for operation. These |
46
|
|
|
|
|
|
|
elements must match a GNUDB entry. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
######################################################### |
51
|
|
|
|
|
|
|
sub new{ |
52
|
2
|
|
|
2
|
1
|
764
|
my($class, $config) = @_; |
53
|
2
|
|
|
|
|
13
|
my $self = { |
54
|
|
|
|
|
|
|
'__id' => undef, |
55
|
|
|
|
|
|
|
'__genre' => undef, |
56
|
|
|
|
|
|
|
'__tracks' => [] |
57
|
|
|
|
|
|
|
}; |
58
|
2
|
|
|
|
|
7
|
bless $self, $class; |
59
|
2
|
|
|
|
|
14
|
$self->__setId($config->{'id'}); |
60
|
2
|
|
|
|
|
10
|
$self->__setGenre($config->{'genre'}); |
61
|
2
|
|
|
|
|
5
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
######################################################## |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 getTracks() |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $tracks = $cd->getTracks() |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Returns an array reference of track names for the CD found from the details in the config given at object creation. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This method actually performs the lookup to the GNUDB database. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
######################################################## |
76
|
|
|
|
|
|
|
sub getTracks{ |
77
|
4
|
|
|
4
|
1
|
1843
|
my $self = shift; |
78
|
4
|
|
|
|
|
9
|
my @tracks = @{$self->{'__tracks'}}; |
|
4
|
|
|
|
|
18
|
|
79
|
4
|
100
|
|
|
|
19
|
if($#tracks == -1){ |
80
|
2
|
|
|
|
|
16
|
my $connectionConfig = { |
81
|
|
|
|
|
|
|
client_name => ref($self), |
82
|
|
|
|
|
|
|
client_version => 1.0, |
83
|
|
|
|
|
|
|
protocol => "HTTP", |
84
|
|
|
|
|
|
|
freedb_host => "gnudb.gnudb.org" |
85
|
|
|
|
|
|
|
}; |
86
|
2
|
|
|
|
|
18
|
my $conn = Net::FreeDB2->connection($connectionConfig); |
87
|
2
|
|
|
|
|
175011
|
my $matchConfig = { |
88
|
|
|
|
|
|
|
"categ" => $self->getGenre(), |
89
|
|
|
|
|
|
|
"discid" => $self->getId() |
90
|
|
|
|
|
|
|
}; |
91
|
2
|
|
|
|
|
22
|
my $match = Net::FreeDB2::Match->new($matchConfig); |
92
|
2
|
|
|
|
|
78
|
my $res = $conn->read($match); |
93
|
2
|
50
|
|
|
|
927664
|
if($res->hasError()){ |
94
|
0
|
|
|
|
|
0
|
confess('Error quering GNUDB'); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else{ #all ok |
97
|
2
|
|
|
|
|
33
|
my $entry = $res->getEntry(); |
98
|
2
|
|
|
|
|
19
|
@tracks = $entry->getTtitlen(0); #get all tracks; |
99
|
2
|
|
|
|
|
350
|
$self->{'__tracks'} = \@tracks; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
4
|
|
|
|
|
257
|
return @tracks; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
######################################################### |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 getId() |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $id = $cd->getId() |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Returns the same ID string as given in the config on object creation. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
######################################################### |
115
|
|
|
|
|
|
|
sub getId{ |
116
|
4
|
|
|
4
|
1
|
10
|
my $self = shift; |
117
|
4
|
|
|
|
|
23
|
return $self->{'__id'}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
######################################################### |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 getGenre() |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $genre = $cd->getGenre() |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns the same genre string as given in the config on object creation. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
######################################################### |
130
|
|
|
|
|
|
|
sub getGenre{ |
131
|
4
|
|
|
4
|
1
|
665
|
my $self = shift; |
132
|
4
|
|
|
|
|
30
|
return $self->{'__genre'}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
######################################################### |
135
|
|
|
|
|
|
|
sub __setId{ |
136
|
2
|
|
|
2
|
|
4
|
my($self, $id) = @_; |
137
|
2
|
50
|
|
|
|
10
|
if(defined($id)){ |
138
|
2
|
50
|
|
|
|
15
|
if($id =~ m/^[0-9a-fA-F]+$/){ |
139
|
2
|
|
|
|
|
12
|
$self->{'__id'} = $id; |
140
|
2
|
|
|
|
|
6
|
return 1; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
else{ |
143
|
0
|
|
|
|
|
0
|
confess("Invalid ID"); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else{ |
147
|
0
|
|
|
|
|
0
|
confess("No ID given"); |
148
|
|
|
|
|
|
|
} |
149
|
0
|
|
|
|
|
0
|
return 0; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
######################################################### |
152
|
|
|
|
|
|
|
sub __setGenre{ |
153
|
2
|
|
|
2
|
|
6
|
my($self, $genre) = @_; |
154
|
2
|
50
|
|
|
|
7
|
if(defined($genre)){ |
155
|
2
|
|
|
|
|
4
|
$self->{'__genre'} = $genre; |
156
|
2
|
|
|
|
|
5
|
return 1; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
else{ |
159
|
0
|
|
|
|
|
|
confess("No genre given"); |
160
|
|
|
|
|
|
|
} |
161
|
0
|
|
|
|
|
|
return 0; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
######################################################### |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=pod |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 Author |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
MacGyveR |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Development questions, bug reports, and patches are welcome to the above address. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 Copyright |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Copyright (c) 2012 MacGyveR. All rights reserved. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 See Also |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
L |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
######################################################### |
186
|
|
|
|
|
|
|
return 1; |