[mb-commits] branch, mbs-5609, updated. MBS-5609, move serializing of a group of begind/ end partialdates to a seperat...
MusicBrainz Git Server <[email protected]> Wed, 19 Dec 2012 14:15:22 +0000
| Newsgroups | gmane.comp.audio.musicbrainz.cvs |
|---|---|
| Message-ID | <E1TlKQc-0007TN-3p@wiley> |
The branch, mbs-5609 has been updated
via http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=684829a0528fdd3c2f757c61a868130f7ea7035d (commit)
from http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=66d6b59e500f40ab26bd085e4c8478d201c2fe67 (commit)
Summary of changes:
Makefile.PL | 1 +
.../WebService/Serializer/JSON/2/Relation.pm | 21 ++++++++-----------
.../WebService/Serializer/JSON/2/Role/LifeSpan.pm | 13 +----------
.../Server/WebService/Serializer/JSON/2/Utils.pm | 16 +++++++++++++++
4 files changed, 28 insertions(+), 23 deletions(-)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 684829a0528fdd3c2f757c61a868130f7ea7035d
Author: warp <[email protected]>
Date: Wed Dec 19 15:14:34 2012 +0100
MBS-5609, move serializing of a group of begind/end partialdates to a seperate function.
diff --git a/Makefile.PL b/Makefile.PL
index 08c20c3..e6c6595 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -52,6 +52,7 @@ requires 'Email::Valid';
requires 'Encode::Detect' => '1.01';
requires 'Exception::Class' => '1.29';
requires 'File::Spec';
+requires 'Hash::Merge';
requires 'HTML::FormHandler' => '0.40013';
requires 'HTML::Tiny' => '1.05';
requires 'HTML::TreeBuilder::XPath';
diff --git a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Relation.pm b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Relation.pm
index ad475ac..c2e78ad 100644
--- a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Relation.pm
+++ b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Relation.pm
@@ -1,8 +1,8 @@
package MusicBrainz::Server::WebService::Serializer::JSON::2::Relation;
-
use Moose;
+use Hash::Merge qw(merge);
use String::CamelCase qw(camelize);
-use MusicBrainz::Server::WebService::Serializer::JSON::2::Utils qw(boolean serialize_entity);
+use MusicBrainz::Server::WebService::Serializer::JSON::2::Utils qw(boolean partialdate serialize_entity);
extends 'MusicBrainz::Server::WebService::Serializer::JSON::2';
@@ -11,29 +11,26 @@ sub element { 'relation'; }
sub serialize
{
my ($self, $entity, $inc, $opts) = @_;
- my %body;
+ my $body;
- $body{type} = $entity->link->type->name;
- $body{direction} = $entity->direction == 2 ? "backward" : "forward";
+ $body->{type} = $entity->link->type->name;
+ $body->{direction} = $entity->direction == 2 ? "backward" : "forward";
- my $link = $entity->link;
- $body{begin} = $link->begin_date->is_empty ? JSON::null : $link->begin_date->format;
- $body{end} = $link->end_date->is_empty ? JSON::null : $link->end_date->format;
- $body{ended} = boolean ($link->ended);
+ $body = merge ($body, partialdate ($entity->link));
if ($entity->target_type eq 'artist' ||
$entity->target_type eq 'label' ||
$entity->target_type eq 'release' ||
$entity->target_type eq 'recording')
{
- $body{$entity->target_type} = serialize_entity ($entity->target);
+ $body->{$entity->target_type} = serialize_entity ($entity->target);
}
elsif ($entity->target_type eq 'url')
{
- $body{$entity->target_type} = $entity->target->name
+ $body->{$entity->target_type} = $entity->target->name
}
- return \%body;
+ return $body;
};
__PACKAGE__->meta->make_immutable;
diff --git a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Role/LifeSpan.pm b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Role/LifeSpan.pm
index 34ecba2..600da3b 100644
--- a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Role/LifeSpan.pm
+++ b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Role/LifeSpan.pm
@@ -1,6 +1,6 @@
package MusicBrainz::Server::WebService::Serializer::JSON::2::Role::LifeSpan;
use Moose::Role;
-use MusicBrainz::Server::WebService::Serializer::JSON::2::Utils qw( boolean );
+use MusicBrainz::Server::WebService::Serializer::JSON::2::Utils qw( boolean partialdate );
sub has_lifespan
{
@@ -18,16 +18,7 @@ around serialize => sub {
return $ret unless $toplevel;
- my %lifespan = (
- begin => JSON::null,
- end => JSON::null,
- ended => boolean ($entity->ended),
- );
-
- $lifespan{begin} = $entity->begin_date->format if !$entity->begin_date->is_empty;
- $lifespan{end} = $entity->end_date->format if !$entity->end_date->is_empty;
-
- $ret->{"life-span"} = \%lifespan;
+ $ret->{"life-span"} = partialdate ($entity);
return $ret;
};
diff --git a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Utils.pm b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Utils.pm
index 643a4cd..4e55308 100644
--- a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Utils.pm
+++ b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Utils.pm
@@ -8,6 +8,7 @@ our @EXPORT_OK = qw(
boolean
list_of
number
+ partialdate
serializer
serialize_entity
);
@@ -34,6 +35,21 @@ sub number {
return defined $value ? $value + 0 : JSON::null;
}
+sub partialdate {
+ my $entity = shift;
+
+ my %lifespan = (
+ begin => JSON::null,
+ end => JSON::null,
+ ended => boolean ($entity->ended),
+ );
+
+ $lifespan{begin} = $entity->begin_date->format if !$entity->begin_date->is_empty;
+ $lifespan{end} = $entity->end_date->format if !$entity->end_date->is_empty;
+
+ return \%lifespan;
+}
+
sub serializer
{
my $entity = shift;
-----------------------------------------------------------------------
hooks/post-receive
--
mb_server