Moose subclassing for Asset/*.pm.

This commit is contained in:
Colin Kuskie 2010-04-09 10:30:54 -07:00
parent 0c003083a0
commit c35f3b9ffb
6 changed files with 65 additions and 73 deletions

View file

@ -355,13 +355,14 @@ The url of the post
=cut =cut
sub fixUrl { around fixUrl => sub {
my $self = shift; my $orig = shift;
my $url = shift; my $self = shift;
$url =~ s/\./_/g; my $url = shift;
$url =~ s/\./_/g;
$self->SUPER::fixUrl($url); $self->$orig($url);
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -1035,9 +1036,9 @@ non-sticky, locking and unlocking posts. Calls postProcess when it is done.
=cut =cut
sub processPropertiesFromFormPost { override processPropertiesFromFormPost => sub {
my $self = shift; my $self = shift;
$self->SUPER::processPropertiesFromFormPost; super();
my $session = $self->session; my $session = $self->session;
my $form = $session->form; my $form = $session->form;
my $i18n = WebGUI::International->new($session); my $i18n = WebGUI::International->new($session);
@ -1067,7 +1068,7 @@ sub processPropertiesFromFormPost {
} }
delete $self->{_storageLocation}; delete $self->{_storageLocation};
$self->postProcess; $self->postProcess;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -1115,15 +1116,6 @@ sub postProcess {
#------------------------------------------------------------------- #-------------------------------------------------------------------
#sub publish {
# my $self = shift;
# $self->SUPER::publish(@_);
#
# $self->getThread->sumReplies;
#}
#-------------------------------------------------------------------
=head2 purge =head2 purge
Extend the base method to handle cleaning up storage locations. Extend the base method to handle cleaning up storage locations.
@ -1223,12 +1215,12 @@ the thread rating.
=cut =cut
sub restore { override restore => sub {
my $self = shift; my $self = shift;
$self->SUPER::restore(@_); super();
$self->getThread->sumReplies; $self->getThread->sumReplies;
$self->getThread->updateThreadRating; $self->getThread->updateThreadRating;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -1262,12 +1254,12 @@ An asset object to make the parent of this asset.
=cut =cut
sub setParent { override setParent => sub {
my $self = shift; my $self = shift;
my $newParent = shift; my $newParent = shift;
return 0 unless ($newParent->isa('WebGUI::Asset::Post')); return 0 unless ($newParent->isa('WebGUI::Asset::Post'));
return $self->SUPER::setParent($newParent); return super();
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -1307,9 +1299,9 @@ Moves post to the trash, updates reply counter on thread and recalculates the th
=cut =cut
sub trash { override trash => sub {
my $self = shift; my $self = shift;
$self->SUPER::trash; super();
$self->getThread->sumReplies if ($self->isReply); $self->getThread->sumReplies if ($self->isReply);
$self->getThread->updateThreadRating; $self->getThread->updateThreadRating;
if ($self->getThread->lastPostId eq $self->getId) { if ($self->getThread->lastPostId eq $self->getId) {
@ -1326,7 +1318,7 @@ sub trash {
order by creationDate desc",[$forumLineage.'%', $self->getId]); order by creationDate desc",[$forumLineage.'%', $self->getId]);
$self->getThread->getParent->update({lastPostId=>$id, lastPostDate=>$date}); $self->getThread->getParent->update({lastPostId=>$id, lastPostDate=>$date});
} }
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -1691,7 +1683,7 @@ We're extending www_editSave() here to deal with editing a post that has been de
=cut =cut
sub www_editSave { override www_editSave => sub {
my $self = shift; my $self = shift;
my $assetId = $self->session->form->param("assetId"); my $assetId = $self->session->form->param("assetId");
if($assetId eq "new" && $self->getThread->getParent->useCaptcha) { if($assetId eq "new" && $self->getThread->getParent->useCaptcha) {
@ -1715,12 +1707,12 @@ sub www_editSave {
} }
} }
} }
my $output = $self->SUPER::www_editSave(); my $output = super();
if ($currentTag) { # Go back to our original tag if ($currentTag) { # Go back to our original tag
$currentTag->setWorking; $currentTag->setWorking;
} }
return $output; return $output;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -204,9 +204,9 @@ Returns the TabForm object that will be used in generating the edit page for thi
=cut =cut
sub getEditForm { override getEditForm => sub {
my $self = shift; my $self = shift;
my $tabform = $self->SUPER::getEditForm(); my $tabform = super();
my $i18n = WebGUI::International->new($self->session,'Asset_RichEdit'); my $i18n = WebGUI::International->new($self->session,'Asset_RichEdit');
my %buttons; my %buttons;
tie %buttons, "Tie::IxHash"; tie %buttons, "Tie::IxHash";
@ -441,7 +441,7 @@ sub getEditForm {
name => "allowMedia", name => "allowMedia",
); );
return $tabform; return $tabform;
} };
@ -477,11 +477,11 @@ Returns a toolbar with a set of icons that hyperlink to functions that delete, e
=cut =cut
sub getToolbar { override getToolbar => sub {
my $self = shift; my $self = shift;
return undef if ($self->getToolbarState); return undef if ($self->getToolbarState);
return $self->SUPER::getToolbar(); return super();
} };

View file

@ -242,9 +242,9 @@ Extend the base method to duplicate shortcut overrides.
=cut =cut
sub duplicate { override duplicate => sub {
my $self = shift; my $self = shift;
my $newAsset = $self->SUPER::duplicate(@_); my $newAsset = super();
$self->session->db->write(<<'END_SQL', [$newAsset->getId, $self->getId]); $self->session->db->write(<<'END_SQL', [$newAsset->getId, $self->getId]);
INSERT INTO Shortcut_overrides (assetId, fieldName, newValue) INSERT INTO Shortcut_overrides (assetId, fieldName, newValue)
SELECT ?, fieldName, newValue SELECT ?, fieldName, newValue
@ -252,7 +252,7 @@ FROM Shortcut_overrides
WHERE assetId = ? WHERE assetId = ?
END_SQL END_SQL
return $newAsset; return $newAsset;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -278,9 +278,9 @@ Extend the base class to handle hand drawing the query build and other pieces.
=cut =cut
sub getEditForm { override getEditForm => sub {
my $self = shift; my $self = shift;
my $tabform = $self->SUPER::getEditForm(); my $tabform = super();
my $originalTemplate; my $originalTemplate;
my $i18n = WebGUI::International->new($self->session, "Asset_Shortcut"); my $i18n = WebGUI::International->new($self->session, "Asset_Shortcut");
my $shortcut = $self->getShortcut; my $shortcut = $self->getShortcut;
@ -355,7 +355,7 @@ sub getEditForm {
); );
} }
return $tabform; return $tabform;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -814,13 +814,13 @@ the scratch variables, and to uncache the overrides.
=cut =cut
sub processPropertiesFromFormPost { override processPropertiesFromFormPost => sub {
my $self = shift; my $self = shift;
$self->SUPER::processPropertiesFromFormPost; super();
my $scratchId = "Shortcut_" . $self->getId; my $scratchId = "Shortcut_" . $self->getId;
$self->session->scratch->delete($scratchId); $self->session->scratch->delete($scratchId);
$self->uncacheOverrides; $self->uncacheOverrides;
} };
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------

View file

@ -190,11 +190,11 @@ Extends the base class to add Tax information for the Sku, in a new tab.
=cut =cut
sub getEditForm { override getEditForm => sub {
my $self = shift; my $self = shift;
my $session = $self->session; my $session = $self->session;
my $tabform = $self->SUPER::getEditForm; my $tabform = super();
my $taxDriver = WebGUI::Shop::Tax->getDriver( $session ); my $taxDriver = WebGUI::Shop::Tax->getDriver( $session );
my $definition = $taxDriver->skuFormDefinition; my $definition = $taxDriver->skuFormDefinition;
@ -210,7 +210,7 @@ sub getEditForm {
} }
return $tabform; return $tabform;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -220,11 +220,11 @@ Not to be modified, just defines a new tab.
=cut =cut
sub getEditTabs { override getEditTabs => sub {
my $self = shift; my $self = shift;
my $i18n = WebGUI::International->new($self->session,"Asset_Sku"); my $i18n = WebGUI::International->new($self->session,"Asset_Sku");
return ($self->SUPER::getEditTabs(), ['shop', $i18n->get('shop'), 9]); return (super(), ['shop', $i18n->get('shop'), 9]);
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -571,10 +571,10 @@ Extends the base class to process the tax data.
=cut =cut
sub processPropertiesFromFormPost { override processPropertiesFromFormPost => sub {
my $self = shift; my $self = shift;
my $output = $self->SUPER::processPropertiesFromFormPost( @_ ); my $output = super();
my $taxDriver = WebGUI::Shop::Tax->new( $self->session )->getDriver; my $taxDriver = WebGUI::Shop::Tax->new( $self->session )->getDriver;
$self->session->log->fatal( 'Could not instanciate tax driver.' ) unless $taxDriver; $self->session->log->fatal( 'Could not instanciate tax driver.' ) unless $taxDriver;
@ -582,7 +582,7 @@ sub processPropertiesFromFormPost {
$self->setTaxConfiguration( $taxDriver->className, $taxDriver->processSkuFormPost ); $self->setTaxConfiguration( $taxDriver->className, $taxDriver->processSkuFormPost );
return $output; return $output;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -172,11 +172,11 @@ Returns a toolbar with a set of icons that hyperlink to functions that delete, e
=cut =cut
sub getToolbar { override getToolbar => sub {
my $self = shift; my $self = shift;
return undef if ($self->getToolbarState); return undef if ($self->getToolbarState);
return '<p>'.$self->SUPER::getToolbar().'</p>'; return '<p>'.super().'</p>';
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -174,14 +174,14 @@ Extra Head Tags.
=cut =cut
sub drawExtraHeadTags { override drawExtraHeadTags => sub {
my ($self, $params) = @_; my ($self) = @_;
if ($self->namespace eq 'style') { if ($self->namespace eq 'style') {
my $i18n = WebGUI::International->new($self->session); my $i18n = WebGUI::International->new($self->session);
return $i18n->get(881); return $i18n->get(881);
} }
return $self->SUPER::drawExtraHeadTags($params); return super();
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -208,12 +208,12 @@ Override to add attachments to package data
=cut =cut
sub exportAssetData { override exportAssetData => sub {
my ( $self ) = @_; my ( $self ) = @_;
my $data = $self->SUPER::exportAssetData; my $data = super();
$data->{template_attachments} = $self->getAttachments; $data->{template_attachments} = $self->getAttachments;
return $data; return $data;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -262,9 +262,9 @@ Returns the TabForm object that will be used in generating the edit page for thi
=cut =cut
sub getEditForm { override getEditForm => sub {
my $self = shift; my $self = shift;
my $tabform = $self->SUPER::getEditForm(); my $tabform = super();
my $i18n = WebGUI::International->new($self->session, 'Asset_Template'); my $i18n = WebGUI::International->new($self->session, 'Asset_Template');
$tabform->hidden({ $tabform->hidden({
name=>"returnUrl", name=>"returnUrl",
@ -392,7 +392,7 @@ sub getEditForm {
$properties->raw("<tr><td>$label</td><td>$table</td></tr>"); $properties->raw("<tr><td>$label</td><td>$table</td></tr>");
return $tabform; return $tabform;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -481,12 +481,12 @@ Override to import attachments
=cut =cut
sub importAssetCollateralData { override importAssetCollateralData => sub {
my ( $self, $data, @args ) = @_; my ( $self, $data, @args ) = @_;
$self->removeAttachments; $self->removeAttachments;
$self->addAttachments( $data->{template_attachments} ); $self->addAttachments( $data->{template_attachments} );
return $self->SUPER::importAssetCollateralData( $data, @args ); return super();
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -620,9 +620,9 @@ Extends the master class to handle template parsers, namespaces and template att
=cut =cut
sub processPropertiesFromFormPost { override processPropertiesFromFormPost => sub {
my $self = shift; my $self = shift;
$self->SUPER::processPropertiesFromFormPost; super();
# TODO: Perhaps add a way to check template syntax before it blows stuff up? # TODO: Perhaps add a way to check template syntax before it blows stuff up?
my %data; my %data;
my $needsUpdate = 0; my $needsUpdate = 0;
@ -668,7 +668,7 @@ sub processPropertiesFromFormPost {
$self->addAttachments(\@add); $self->addAttachments(\@add);
return; return;
} };
#------------------------------------------------------------------- #-------------------------------------------------------------------