Subject: | Multiple relation-lists not parsed correctly in WebService-MusicBrainz-0.21 |
Date: | Thu, 12 Mar 2009 09:48:40 +0000 |
To: | bug-WebService-MusicBrainz [...] rt.cpan.org |
From: | Christopher Key <cjk32 [...] cam.ac.uk> |
Some releases have mutliple relation lists for relationships to
different types of object, e.g.:
http://musicbrainz.org/ws/1/release/88ef66e4-9490-4b11-9f40-422c6c065e87?type=xml&inc=artist-rels+release-rels
The current code only selects the first relation-list, and ignore the
rest. Attached is a patch which deals with the problem by making
$x->relation_list() return an array ref containing 0 or more elements.
As this is incompatible with previous behaviour, an option must be
passed to query() requesting the new parsing behaviour over the old.
Whilst not terribly tidy, this does have the advantage that old and new
code can coexist.
The only other simple solution seemed to be to pass an option to an
import routine, e.g. use MusicBrainz::WebService::Release
qw(-MultipleRelationLists), and then keep track of these flags per
caller namespace. Whilst keeping the caller code cleaner in general,
the chosen method does allow finer grain control over new/old behaviour.
diff -ur WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Artist.pm WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Artist.pm
--- WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Artist.pm 2009-03-12 09:20:28.000000000 +0000
+++ WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Artist.pm 2009-03-12 09:24:20.000000000 +0000
@@ -99,8 +99,9 @@
sub search {
my $self = shift;
my $params = shift;
+ my $options = shift;
- my $response = $self->query()->get('artist', $params);
+ my $response = $self->query()->get('artist', $params, $options);
return $response;
}
diff -ur WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Label.pm WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Label.pm
--- WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Label.pm 2009-03-12 09:20:28.000000000 +0000
+++ WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Label.pm 2009-03-12 09:24:20.000000000 +0000
@@ -93,8 +93,9 @@
sub search {
my $self = shift;
my $params = shift;
+ my $options = shift;
- my $response = $self->query()->get('label', $params);
+ my $response = $self->query()->get('label', $params, $options);
return $response;
}
diff -ur WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Query.pm WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Query.pm
--- WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Query.pm 2009-03-12 09:20:28.000000000 +0000
+++ WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Query.pm 2009-03-12 09:24:20.000000000 +0000
@@ -121,6 +121,7 @@
my $self = shift;
my $class = shift;
my $params = shift;
+ my $options = shift;
my $url = $self->_url($class, $params);
@@ -132,7 +133,7 @@
my $response = $ua->get($url);
if($response->code() eq "200") {
- my $r = WebService::MusicBrainz::Response->new( XML => $response->content );
+ my $r = WebService::MusicBrainz::Response->new( XML => $response->content, MultipleRelationLists => $options->{MultipleRelationLists} );
return $r;
}
diff -ur WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Release.pm WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Release.pm
--- WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Release.pm 2009-03-12 09:20:28.000000000 +0000
+++ WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Release.pm 2009-03-12 09:24:20.000000000 +0000
@@ -101,8 +101,9 @@
sub search {
my $self = shift;
my $params = shift;
+ my $options = shift;
- my $response = $self->query()->get('release', $params);
+ my $response = $self->query()->get('release', $params, $options);
return $response;
}
diff -ur WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Response.pm WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Response.pm
--- WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Response.pm 2009-03-12 09:20:28.000000000 +0000
+++ WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Response.pm 2009-03-12 09:24:20.000000000 +0000
@@ -31,6 +31,7 @@
bless $self, $class;
$self->{_xml} = $params{XML} || die "XML parameter required";
+ $self->{_multipleRelationLists} = $params{MultipleRelationLists};
$self->_load_xml();
@@ -309,7 +310,7 @@
my ($xDisambiguation) = $xpc->findnodes('mmd:disambiguation[1]', $xArtist);
my ($xLifeSpan) = $xpc->findnodes('mmd:life-span[1]', $xArtist);
my ($xAliasList) = $xpc->findnodes('mmd:alias-list[1]', $xArtist);
- my ($xRelationList) = $xpc->findnodes('mmd:relation-list[1]', $xArtist);
+ my @xRelationList = $xpc->findnodes('mmd:relation-list', $xArtist);
my ($xReleaseList) = $xpc->findnodes('mmd:release-list[1]', $xArtist);
my ($xTagList) = $xpc->findnodes('mmd:tag-list[1]', $xArtist);
@@ -326,7 +327,11 @@
$artist->life_span_end( $xLifeSpan->getAttribute('end') ) if $xLifeSpan && $xLifeSpan->getAttribute('end');
$artist->score( $xArtist->getAttribute('ext:score') ) if $xArtist->getAttribute('ext:score');
$artist->alias_list( $self->_create_alias_list( $xAliasList ) ) if $xAliasList;
- $artist->relation_list( $self->_create_relation_list( $xRelationList ) ) if $xRelationList;
+ if ($self->{_multipleRelationLists}) {
+ $artist->relation_list( [ map { $self->_create_relation_list( $_ ) } @xRelationList ] );
+ } else {
+ $artist->relation_list( $self->_create_relation_list( $xRelationList[0] ) ) if @xRelationList;
+ }
$artist->release_list( $self->_create_release_list( $xReleaseList ) ) if $xReleaseList;
$artist->tag_list( $self->_create_tag_list( $xTagList ) ) if $xTagList;
@@ -373,7 +378,7 @@
my ($xDiscList) = $xpc->findnodes('mmd:disc-list[1]', $xRelease);
my ($xPuidList) = $xpc->findnodes('mmd:puid-list[1]', $xRelease);
my ($xTrackList) = $xpc->findnodes('mmd:track-list[1]', $xRelease);
- my ($xRelationList) = $xpc->findnodes('mmd:relation-list[1]', $xRelease);
+ my @xRelationList = $xpc->findnodes('mmd:relation-list', $xRelease);
my ($xTagList) = $xpc->findnodes('mmd:tag-list[1]', $xRelease);
require WebService::MusicBrainz::Response::Release;
@@ -392,7 +397,11 @@
$release->disc_list( $self->_create_disc_list( $xDiscList ) ) if $xDiscList;
$release->puid_list( $self->_create_puid_list( $xPuidList ) ) if $xPuidList;
$release->track_list( $self->_create_track_list( $xTrackList ) ) if $xTrackList;
- $release->relation_list( $self->_create_relation_list( $xRelationList ) ) if $xRelationList;
+ if ($self->{_multipleRelationLists}) {
+ $release->relation_list( [ map { $self->_create_relation_list( $_ ) } @xRelationList ] );
+ } else {
+ $release->relation_list( $self->_create_relation_list( $xRelationList[0] ) ) if @xRelationList;
+ }
$release->tag_list( $self->_create_tag_list( $xTagList ) ) if $xTagList;
return $release;
@@ -409,7 +418,7 @@
my ($xArtist) = $xpc->findnodes('mmd:artist[1]', $xTrack);
my ($xReleaseList) = $xpc->findnodes('mmd:release-list[1]', $xTrack);
my ($xPuidList) = $xpc->findnodes('mmd:puid-list[1]', $xTrack);
- my ($xRelationList) = $xpc->findnodes('mmd:relation-list[1]', $xTrack);
+ my @xRelationList = $xpc->findnodes('mmd:relation-list', $xTrack);
my ($xTagList) = $xpc->findnodes('mmd:tag-list[1]', $xTrack);
require WebService::MusicBrainz::Response::Track;
@@ -423,7 +432,11 @@
$track->artist( $self->_create_artist( $xArtist ) ) if $xArtist;
$track->release_list( $self->_create_release_list( $xReleaseList ) ) if $xReleaseList;
$track->puid_list( $self->_create_puid_list( $xPuidList ) ) if $xPuidList;
- $track->relation_list( $self->_create_relation_list( $xRelationList ) ) if $xRelationList;
+ if ($self->{_multipleRelationLists}) {
+ $track->relation_list( [ map { $self->_create_relation_list( $_ ) } @xRelationList ] );
+ } else {
+ $track->relation_list( $self->_create_relation_list( $xRelationList[0] ) ) if @xRelationList;
+ }
$track->tag_list( $self->_create_tag_list( $xTagList ) ) if $xTagList;
return $track;
@@ -443,7 +456,7 @@
my ($xLifeSpan) = $xpc->findnodes('mmd:life-span[1]', $xLabel);
my ($xAliasList) = $xpc->findnodes('mmd:alias-list[1]', $xLabel);
my ($xReleaseList) = $xpc->findnodes('mmd:release-list[1]', $xLabel);
- my ($xRelationList) = $xpc->findnodes('mmd:relation-list[1]', $xLabel);
+ my @xRelationList = $xpc->findnodes('mmd:relation-list', $xLabel);
my ($xTagList) = $xpc->findnodes('mmd:tag-list[1]', $xLabel);
require WebService::MusicBrainz::Response::Label;
@@ -462,7 +475,11 @@
$label->score( $xLabel->getAttribute('ext:score') ) if $xLabel->getAttribute('ext:score');
$label->alias_list( $self->_create_alias_list( $xAliasList ) ) if $xAliasList;
$label->release_list( $self->_create_release_list( $xReleaseList ) ) if $xReleaseList;
- $label->relation_list( $self->_create_relation_list( $xRelationList ) ) if $xRelationList;
+ if ($self->{_multipleRelationLists}) {
+ $label->relation_list( [ map { $self->_create_relation_list( $_ ) } @xRelationList ] );
+ } else {
+ $label->relation_list( $self->_create_relation_list( $xRelationList[0] ) ) if @xRelationList;
+ }
$label->tag_list( $self->_create_tag_list( $xTagList ) ) if $xTagList;
return $label;
diff -ur WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Track.pm WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Track.pm
--- WebService-MusicBrainz-0.21.orig/lib/WebService/MusicBrainz/Track.pm 2009-03-12 09:20:28.000000000 +0000
+++ WebService-MusicBrainz-0.21/lib/WebService/MusicBrainz/Track.pm 2009-03-12 09:24:20.000000000 +0000
@@ -104,8 +104,9 @@
sub search {
my $self = shift;
my $params = shift;
+ my $options = shift;
- my $response = $self->query()->get('track', $params);
+ my $response = $self->query()->get('track', $params, $options);
return $response;
}