From 0c003083a034969ee8157248eb1143d6896f1863 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 9 Apr 2010 10:16:59 -0700 Subject: [PATCH] Moose overrides in Event, File, Post --- lib/WebGUI/Asset/Event.pm | 6 +++--- lib/WebGUI/Asset/File.pm | 31 ++++++++++++++++--------------- lib/WebGUI/Asset/Post.pm | 12 ++++++------ 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 6bb9b0da4..cece7df8b 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -1515,9 +1515,9 @@ Requests that the events be committed =cut -sub processPropertiesFromFormPost { +override processPropertiesFromFormPost => sub { my $self = shift; - $self->SUPER::processPropertiesFromFormPost; # Updates the event + super(); my $session = $self->session; my $form = $session->form; @@ -1742,7 +1742,7 @@ sub processPropertiesFromFormPost { delete $self->{_storageLocation}; return undef; -} +}; #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index bd054a450..e3603027e 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -132,13 +132,13 @@ Extend the master method to duplicate the storage location. =cut -sub duplicate { +override duplicate => sub { my $self = shift; - my $newAsset = $self->SUPER::duplicate(@_); + my $newAsset = super(); my $newStorage = $self->getStorageLocation->copy; $newAsset->update({storageId=>$newStorage->getId}); return $newAsset; -} +}; #------------------------------------------------------------------- @@ -149,12 +149,12 @@ See WebGUI::AssetPackage::exportAssetData() for details. =cut -sub exportAssetData { +override exportAssetData => sub { my $self = shift; - my $data = $self->SUPER::exportAssetData; + my $data = super(); push(@{$data->{storage}}, $self->storageId) if ($self->storageId ne ""); return $data; -} +}; #------------------------------------------------------------------- @@ -201,9 +201,9 @@ Returns the TabForm object that will be used in generating the edit page for thi =cut -sub getEditForm { +override getEditForm => sub { my $self = shift; - my $tabform = $self->SUPER::getEditForm(); + my $tabform = super(); my $i18n = WebGUI::International->new($self->session, 'Asset_File'); $tabform->getTab("properties")->raw( @@ -213,7 +213,7 @@ sub getEditForm { ); return $tabform; -} +}; #---------------------------------------------------------------------------- @@ -390,11 +390,11 @@ Extend the master method to handle file uploads and applying constraints. =cut -sub processPropertiesFromFormPost { +override processPropertiesFromFormPost => sub { my $self = shift; my $session = $self->session; - my $errors = $self->SUPER::processPropertiesFromFormPost || []; + my $errors = super() || []; return $errors if @$errors; if (my $storageId = $session->form->get('newFile','File')) { @@ -409,7 +409,7 @@ sub processPropertiesFromFormPost { } return undef; -} +}; #------------------------------------------------------------------- @@ -500,7 +500,8 @@ the asset size. =cut -sub setSize { +around setSize => sub { + my $orig = shift; my $self = shift; my $fileSize = shift || 0; my $storage = $self->getStorageLocation; @@ -509,8 +510,8 @@ sub setSize { $fileSize += $storage->getFileSize($file); } } - return $self->SUPER::setSize($fileSize); -} + return $self->$orig($fileSize); +}; #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index f8934994e..8ca568e13 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -321,11 +321,11 @@ Extend the base method to delete the locally cached thread object. =cut -sub DESTROY { +override DESTROY => sub { my $self = shift; $self->{_thread}->DESTROY if (exists $self->{_thread} && ref $self->{_thread} =~ /Thread/); - $self->SUPER::DESTROY; -} + super(); +}; #------------------------------------------------------------------- @@ -336,12 +336,12 @@ Extend the base class to handle storage locations. =cut -sub exportAssetData { +override exportAssetData => sub { my $self = shift; - my $data = $self->SUPER::exportAssetData; + my $data = super(); push(@{$data->{storage}}, $self->storageId) if ($self->storageId ne ""); return $data; -} +}; #-------------------------------------------------------------------