From 2b39e16cc8048aff2721e5dcf1bc9bec5034718e Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 3 Mar 2010 19:22:13 -0800 Subject: [PATCH] Rough conversion of Comments and Installable to Moose. --- .../{AssetAspect => Role/Asset}/Comments.pm | 53 ++++++------------- .../Asset}/Installable.pm | 8 ++- 2 files changed, 20 insertions(+), 41 deletions(-) rename lib/WebGUI/{AssetAspect => Role/Asset}/Comments.pm (89%) rename lib/WebGUI/{AssetAspect => Role/Asset}/Installable.pm (96%) diff --git a/lib/WebGUI/AssetAspect/Comments.pm b/lib/WebGUI/Role/Asset/Comments.pm similarity index 89% rename from lib/WebGUI/AssetAspect/Comments.pm rename to lib/WebGUI/Role/Asset/Comments.pm index 59d0d2b58..c155d2f7b 100644 --- a/lib/WebGUI/AssetAspect/Comments.pm +++ b/lib/WebGUI/Role/Asset/Comments.pm @@ -1,4 +1,4 @@ -package WebGUI::AssetAspect::Comments; +package WebGUI::Role::Asset::Comments; =head1 LEGAL @@ -14,10 +14,21 @@ package WebGUI::AssetAspect::Comments; =cut -use strict; -use Class::C3; +use Moose::Role; +use WebGUI::Definition::Asset; +define tableName => 'assetAspectComments'; +property comments => ( + noFormPost => 1, + fieldType => "hidden", + default => '[]', + ); +property averageCommentRating => ( + noFormPost => 1, + fieldType => "hidden", + default => 0, + ); + use JSON; -use Tie::IxHash; use WebGUI::Exception; use WebGUI::Form; use WebGUI::HTML; @@ -25,7 +36,7 @@ use WebGUI::Utility; =head1 NAME -Package WebGUI::AssetAspect::Comments +Package WebGUI::Role::Asset::Comments =head1 DESCRIPTION @@ -33,11 +44,8 @@ This is an aspect which makes adding comments to existing assets trivial. =head1 SYNOPSIS - use Class::C3; - use base qw(WebGUI::AssetAspect::Comments WebGUI::Asset); + with 'WebGUI::Role::Asset::Comments'; -And then where-ever you would call $self->SUPER::someMethodName call $self->next::method instead. - =head1 METHODS These methods are available from this class: @@ -128,33 +136,6 @@ Extends the definition to add the comments and averageCommentRating fields. =cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift; - my %properties; - tie %properties, 'Tie::IxHash'; - %properties = ( - comments => { - noFormPost => 1, - fieldType => "hidden", - defaultValue => [], - }, - averageCommentRating => { - noFormPost => 1, - fieldType => "hidden", - defaultValue => 0, - }, - ); - push(@{$definition}, { - autoGenerateForms => 1, - tableName => 'assetAspectComments', - className => 'WebGUI::Asset::Sku::BazaarItem', - properties => \%properties - }); - return $class->next::method($session, $definition); -} - #------------------------------------------------------------------- =head2 deleteComment ( id ) diff --git a/lib/WebGUI/AssetAspect/Installable.pm b/lib/WebGUI/Role/Asset/Installable.pm similarity index 96% rename from lib/WebGUI/AssetAspect/Installable.pm rename to lib/WebGUI/Role/Asset/Installable.pm index 28dd40b62..6709bb36b 100644 --- a/lib/WebGUI/AssetAspect/Installable.pm +++ b/lib/WebGUI/Role/Asset/Installable.pm @@ -1,19 +1,17 @@ -package WebGUI::AssetAspect::Installable; +package WebGUI::Role::Asset::Installable; use strict; -use Class::C3; use WebGUI::Asset; use WebGUI::Form::DynamicField; =head1 NAME -WebGUI::AssetAspect::Installable -- Make your asset installable +WebGUI::Role::Asset::Installable -- Make your asset installable =head1 SYNOPSIS - package WebGUI::Asset::MyAsset; - use base ( 'WebGUI::AssetAspect::Installable', 'WebGUI::Asset' ); + with 'WebGUI::Role::Asset::Installable'; # Override the install method to install collateral tables sub install {