From 5574cdf9b0301f1be41b5d4bc399687baef4630b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 21 Dec 2009 14:46:29 -0800 Subject: [PATCH] newByPropertyHashRef. Tolerate an empty properties hashref. Call $className->new. Allow propeties hashref to be empty, and take class from invocant. Add a session attribute. Change around->extraHeadTags to after->extraHeadTags. --- lib/WebGUI/Asset.pm | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 2c95ef05b..80075d382 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -143,8 +143,7 @@ property extraHeadTags => ( defaultValue => undef, customDrawMethod=> 'drawExtraHeadTags', ); -around extraHeadTags => sub { - my $orig = shift; +after extraHeadTags => sub { my $self = shift; if (@_ > 1) { my $unpacked = $_[0]; @@ -157,7 +156,6 @@ around extraHeadTags => sub { } ); $self->extraHeadTagsPacked($packed); } - $self->$orig(@_); }; property extraHeadTagsPacked => ( fieldType => 'hidden', @@ -219,6 +217,10 @@ property assetSize => ( fieldType => 'integer', defaultValue => 0, ); +has session => ( + noFormPost => 1, + is => 'ro', + ); use WebGUI::AssetBranch; use WebGUI::AssetClipboard; @@ -1671,7 +1673,8 @@ sub newByDynamicClass { =head2 newByPropertyHashRef ( session, properties ) -Constructor. This creates a standalone asset with no parent. It does not update the database. +Constructor. This creates a standalone asset with no parent. It does not persist that object +to the database. =head3 session @@ -1679,19 +1682,23 @@ A reference to the current session. =head3 properties -A properties hash reference. The className of the properties hash must be valid. +A hash reference of Asset properties. + +=head4 className + +If className is not passed, the class used to call this method will be used in its place. =cut sub newByPropertyHashRef { - my $class = shift; - my $session = shift; - my $properties = shift; - return undef unless defined $properties; - return undef unless exists $properties->{className}; + my $class = shift; + my $session = shift; + my $properties = shift || {}; + $properties->{className} //= $class; my $className = $class->loadModule($session, $properties->{className}); return undef unless (defined $className); - bless {_session=>$session, _properties => $properties}, $className; + my $object = $className->new($session, $properties); + return $object; } #-------------------------------------------------------------------