Skip to content

Commit

Permalink
Subclass get/set in Snippet to handle a possible 'keyword' get/set op…
Browse files Browse the repository at this point in the history
…eration.
  • Loading branch information
scottwalters committed Jun 3, 2010
1 parent 58d68a6 commit bf88cb4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/WebGUI/Asset/Snippet.pm
Expand Up @@ -295,6 +295,28 @@ sub www_view {
return $output;
}

#-------------------------------------------------------------------

override set => sub {
my $self = shift;
super();
my $properties = @_ % 2 ? shift : { @_ };
if(exists $properties->{keywords}) {
$self->keywords($properties->{keywords});
}
};

override get => sub {
my $self = shift;
if( @_ and $_[0] eq 'keywords' ) {
return $self->keywords;
}
return super();
};

#-------------------------------------------------------------------

__PACKAGE__->meta->make_immutable;

1;

2 changes: 1 addition & 1 deletion t/Keyword.t
Expand Up @@ -30,7 +30,7 @@ isa_ok($home, "WebGUI::Asset");
my $keyword = WebGUI::Keyword->new($session);
isa_ok($keyword, "WebGUI::Keyword");

$keyword->setKeywordsForAsset({ asset=>$home, keywords=>"test key, word, foo bar"});
$keyword->setKeywordsForAsset({ asset=>$home, keywords=>"test key, word, foo bar"}); # XXX does this step into the Asset and set its keyword attribute?
my ($count) = $session->db->quickArray("select count(*) from assetKeyword where assetId=?", [$home->getId]);
is($count, 3, "setKeywordsForAsset() create");
cmp_bag(
Expand Down

0 comments on commit bf88cb4

Please sign in to comment.