Skip to content

Instantly share code, notes, and snippets.

@ocharles
Created June 12, 2009 23:39
Show Gist options
  • Save ocharles/129009 to your computer and use it in GitHub Desktop.
Save ocharles/129009 to your computer and use it in GitHub Desktop.
package MusicBrainz::Server::Edit::Artist::Edit;
use Moose;
use MusicBrainz::Server::Constants qw( $EDIT_ARTIST_EDIT );
use MusicBrainz::Server::Types;
extends 'MusicBrainz::Server::Edit';
sub name { 'Edit Artist' }
sub edit_type { $EDIT_ARTIST_EDIT }
has 'artist' => (
traits => [qw( DoNotSerialize )],
isa => 'Artist',
is => 'rw',
);
for my $attr (qw( comment name sort_name ))
{
has $attr => (
is => 'ro',
isa => 'Change',
coerce => 1,
lazy => 1,
default => sub { MusicBrainz::Server::Edit::Change->new(
old_value => shift->artist->$attr
)},
);
}
sub to_hash
{
my $self = shift;
my %hash = ( artist => $self->artist->id );
for my $attr (qw( comment name sort_name ))
{
if ($self->$attr->has_new_value) {
$hash{$attr} = {
new_value => $self->$attr->new_value,
old_value => $self->$attr->old_value,
}
}
}
return \%hash;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment