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.
This commit is contained in:
parent
030f6bccf0
commit
5574cdf9b0
1 changed files with 18 additions and 11 deletions
|
|
@ -143,8 +143,7 @@ property extraHeadTags => (
|
||||||
defaultValue => undef,
|
defaultValue => undef,
|
||||||
customDrawMethod=> 'drawExtraHeadTags',
|
customDrawMethod=> 'drawExtraHeadTags',
|
||||||
);
|
);
|
||||||
around extraHeadTags => sub {
|
after extraHeadTags => sub {
|
||||||
my $orig = shift;
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
if (@_ > 1) {
|
if (@_ > 1) {
|
||||||
my $unpacked = $_[0];
|
my $unpacked = $_[0];
|
||||||
|
|
@ -157,7 +156,6 @@ around extraHeadTags => sub {
|
||||||
} );
|
} );
|
||||||
$self->extraHeadTagsPacked($packed);
|
$self->extraHeadTagsPacked($packed);
|
||||||
}
|
}
|
||||||
$self->$orig(@_);
|
|
||||||
};
|
};
|
||||||
property extraHeadTagsPacked => (
|
property extraHeadTagsPacked => (
|
||||||
fieldType => 'hidden',
|
fieldType => 'hidden',
|
||||||
|
|
@ -219,6 +217,10 @@ property assetSize => (
|
||||||
fieldType => 'integer',
|
fieldType => 'integer',
|
||||||
defaultValue => 0,
|
defaultValue => 0,
|
||||||
);
|
);
|
||||||
|
has session => (
|
||||||
|
noFormPost => 1,
|
||||||
|
is => 'ro',
|
||||||
|
);
|
||||||
|
|
||||||
use WebGUI::AssetBranch;
|
use WebGUI::AssetBranch;
|
||||||
use WebGUI::AssetClipboard;
|
use WebGUI::AssetClipboard;
|
||||||
|
|
@ -1671,7 +1673,8 @@ sub newByDynamicClass {
|
||||||
|
|
||||||
=head2 newByPropertyHashRef ( session, properties )
|
=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
|
=head3 session
|
||||||
|
|
||||||
|
|
@ -1679,19 +1682,23 @@ A reference to the current session.
|
||||||
|
|
||||||
=head3 properties
|
=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
|
=cut
|
||||||
|
|
||||||
sub newByPropertyHashRef {
|
sub newByPropertyHashRef {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $properties = shift;
|
my $properties = shift || {};
|
||||||
return undef unless defined $properties;
|
$properties->{className} //= $class;
|
||||||
return undef unless exists $properties->{className};
|
|
||||||
my $className = $class->loadModule($session, $properties->{className});
|
my $className = $class->loadModule($session, $properties->{className});
|
||||||
return undef unless (defined $className);
|
return undef unless (defined $className);
|
||||||
bless {_session=>$session, _properties => $properties}, $className;
|
my $object = $className->new($session, $properties);
|
||||||
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue