Add keywords accessor for looking up Asset keywords.

This commit is contained in:
Colin Kuskie 2010-03-03 11:03:35 -08:00
parent d932543159
commit 122bd26afa
2 changed files with 35 additions and 1 deletions

View file

@ -294,6 +294,27 @@ sub _build_className {
my $self = shift;
return ref $self;
}
has keywords => (
is => 'rw',
init_arg => undef,
builder => '_build_assetKeywords',
lazy => 1,
);
sub _build_assetKeywords {
my $session = shift->session;
return WebGUI::Keyword->new($session);
}
around keywords => sub {
my $orig = shift;
my $self = shift;
if (@_) {
return $self->$orig->setKeywordsForAsset({asset => $self, keywords => $_[0], });
}
else {
return $self->$orig->getKeywordsForAsset({asset => $self});
}
};
around BUILDARGS => sub {
my $orig = shift;

View file

@ -21,7 +21,7 @@ use Test::Deep;
use Test::Exception;
use WebGUI::Exception;
plan tests => 59;
plan tests => 62;
my $session = WebGUI::Test->session;
@ -288,3 +288,16 @@ my $session = WebGUI::Test->session;
is $properties->{assetId}, $asset->assetId, '... works on assetId';
is $properties->{parentId}, 'I have a parent', '... works on parentId';
}
{
note "keywords";
my $default = WebGUI::Asset->getDefault($session);
my $asset = $default->addChild({
className => 'WebGUI::Asset::Snippet',
});
addToCleanup($asset);
can_ok($asset, 'keywords');
$asset->keywords('chess set');
is ($asset->keywords, 'chess set', 'set and get of keywords via direct accessor');
is ($asset->get('keywords'), 'chess set', 'via get method');
}