Asset work related to class dispatch.
This commit is contained in:
parent
1af2acbc9d
commit
fde81306c6
2 changed files with 42 additions and 12 deletions
|
|
@ -260,16 +260,16 @@ has className => (
|
||||||
);
|
);
|
||||||
|
|
||||||
around BUILDARGS => sub {
|
around BUILDARGS => sub {
|
||||||
my $orig = shift;
|
my $orig = shift;
|
||||||
my $className = shift;
|
my $className = shift;
|
||||||
return $className->$orig(@_);
|
|
||||||
##Original arguments start here.
|
##Original arguments start here.
|
||||||
if (ref $_[0] eq 'HASH') {
|
if (ref $_[0] eq 'HASH') {
|
||||||
return $className->$orig(@_);
|
return $className->$orig(@_);
|
||||||
}
|
}
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $assetId = shift;
|
my $assetId = shift;
|
||||||
my $revisionDate = shift;
|
my $revisionDate = shift;
|
||||||
|
|
||||||
unless (defined $assetId) {
|
unless (defined $assetId) {
|
||||||
$session->errorHandler->error("Asset constructor new() requires an assetId.");
|
$session->errorHandler->error("Asset constructor new() requires an assetId.");
|
||||||
|
|
@ -1268,7 +1268,7 @@ A reference to the current session.
|
||||||
sub getRoot {
|
sub getRoot {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
return WebGUI::Asset->new($session, "PBasset000000000000001");
|
return WebGUI::Asset->newById($session, "PBasset000000000000001");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1608,9 +1608,21 @@ If specified this value will be used to set the title after it goes through some
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 new ( session, assetId [, revisionDate ] )
|
=head2 new ( propertyHashRef )
|
||||||
|
|
||||||
Constructor. This does not create an asset.
|
Asset Constructor. This does not create an asset in the database, or look up
|
||||||
|
properties in the database, but creates a WebGUI::Asset object.
|
||||||
|
|
||||||
|
=head3 propertyHashRef
|
||||||
|
|
||||||
|
A hash reference of properties to assign to the object.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
=head2 new ( session, assetId [, className, revisionDate ] )
|
||||||
|
|
||||||
|
Instanciator. This does not create an asset in the database, but looks up the object's
|
||||||
|
properties in the database and returns an object with the correct WebGUI::Asset subclass.
|
||||||
|
|
||||||
=head3 session
|
=head3 session
|
||||||
|
|
||||||
|
|
@ -1631,7 +1643,7 @@ no revision date is available it will return undef.
|
||||||
|
|
||||||
=head2 newById ( session, assetId [ , revisionDate ] )
|
=head2 newById ( session, assetId [ , revisionDate ] )
|
||||||
|
|
||||||
Instances an existing Asset, by looking up the classname of the asset specified by the assetId, and then calling new.
|
Instances an existing Asset, by looking up the className of the asset specified by the assetId, and then calling new.
|
||||||
Returns undef if it can't find the classname.
|
Returns undef if it can't find the classname.
|
||||||
|
|
||||||
=head3 session
|
=head3 session
|
||||||
|
|
@ -1682,7 +1694,7 @@ sub newById {
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
return WebGUI::Asset->new($session,$assetId,$className,$revisionDate);
|
return $className->new($session, $assetId, $revisionDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
20
t/Asset.t
20
t/Asset.t
|
|
@ -20,7 +20,7 @@ use Test::More;
|
||||||
use Test::Deep;
|
use Test::Deep;
|
||||||
use Test::Exception;
|
use Test::Exception;
|
||||||
|
|
||||||
plan tests => 20;
|
plan tests => 22;
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
|
|
@ -80,3 +80,21 @@ my $session = WebGUI::Test->session;
|
||||||
});
|
});
|
||||||
is $asset->menuTitle, 'menuTitle asset', '... set via constructor';
|
is $asset->menuTitle, 'menuTitle asset', '... set via constructor';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $asset = WebGUI::Asset->new({
|
||||||
|
session => $session,
|
||||||
|
title => 'testing snippet',
|
||||||
|
className => 'WebGUI::Asset::Snippet',
|
||||||
|
});
|
||||||
|
|
||||||
|
isa_ok $asset, 'WebGUI::Asset';
|
||||||
|
|
||||||
|
use WebGUI::Asset::Snippet;
|
||||||
|
$asset = WebGUI::Asset::Snippet->new({
|
||||||
|
session => $session,
|
||||||
|
title => 'testing snippet',
|
||||||
|
});
|
||||||
|
|
||||||
|
isa_ok $asset, 'WebGUI::Asset::Snippet';
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue