From 122bd26afa90a0c87c15d4b39c22742f5ed945fc Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 3 Mar 2010 11:03:35 -0800 Subject: [PATCH] Add keywords accessor for looking up Asset keywords. --- lib/WebGUI/Asset.pm | 21 +++++++++++++++++++++ t/Asset.t | 15 ++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 3358b178f..55b7b92cd 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -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; diff --git a/t/Asset.t b/t/Asset.t index a94ef325f..7bb06cf80 100644 --- a/t/Asset.t +++ b/t/Asset.t @@ -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'); +}