Remove get and update overrides in Asset::Role::Comments

This commit is contained in:
Colin Kuskie 2010-03-18 09:10:45 -07:00
parent e076ecbfe2
commit b0cad3b155
2 changed files with 18 additions and 42 deletions

View file

@ -20,6 +20,16 @@ use JSON;
use HTML::Packer;
use Moose;
use Moose::Util::TypeConstraints;
subtype 'WebGUI::Type::JSONArray'
=> as 'ArrayRef'
;
coerce 'WebGUI::Type::JSONArray'
=> from Str
=> via { my $struct = eval { JSON::from_json($_); }; $struct ||= []; return $struct },
;
use WebGUI::Definition::Asset;
define assetName => ['asset', 'Asset'];
define tableName => 'assetData';
@ -2355,6 +2365,9 @@ sub write {
my $property = $self->meta->find_attribute_by_name($property_name);
my $tableName = $property->tableName;
my $value = $self->$property_name;
if ($property->does('WebGUI::Definition::Meta::Property::Serialize')) {
$value = eval { JSON::from_json($value); } || '';
}
push @{ $data_by_table{$tableName}->{NAMES} }, $property_name;
push @{ $data_by_table{$tableName}->{VALUES} }, $value;
}

View file

@ -20,7 +20,10 @@ define tableName => 'assetAspectComments';
property comments => (
noFormPost => 1,
fieldType => "hidden",
default => '[]',
default => sub { [] },
traits => ['Array', 'WebGUI::Definition::Meta::Property::Serialize',],
isa => 'WebGUI::Type::JSONArray',
coerce => 1,
);
property averageCommentRating => (
noFormPost => 1,
@ -187,23 +190,7 @@ sub deleteComment {
}
}
##-------------------------------------------------------------------
#
#=head2 get ()
#
#See SUPER::get(). Extends the get() method to automatically decode the comments field into a Perl hash structure.
#
#=cut
#
#sub get {
# my $self = shift;
# my $param = shift;
# if ($param eq 'comments') {
# return JSON->new->decode($self->next::method('comments')||'[]');
# }
# return $self->next::method($param, @_);
#}
#
#-------------------------------------------------------------------
=head2 getAverageCommentRatingIcon ()
@ -279,30 +266,6 @@ sub getKarmaAmountPerComment {
}
##-------------------------------------------------------------------
#
#=head2 update ()
#
#See SUPER::update(). Extends the update() method to encode the comments field into something storable in the database.
#
#=cut
#
#sub update {
# my $self = shift;
# my $properties = shift;
# if (exists $properties->{comments}) {
# my $comments = $properties->{comments};
# if (ref $comments ne 'ARRAY') {
# $comments = eval{JSON->new->decode($comments)};
# if (WebGUI::Error->caught || ref $comments ne 'ARRAY') {
# $comments = [];
# }
# }
# $properties->{comments} = JSON->new->encode($comments);
# }
# $self->next::method($properties, @_);
#}
#
#-------------------------------------------------------------------
=head2 www_addComment ()