forked from plainblack/webgui
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding around => get and set in Asset.pm did nothing; moving them
to a dedicated role and pulling them in with 'with' likewise does nothing. Can't seem to work Moose to modify get/set how they're currently being pulled in.
- Loading branch information
1 parent
b5d1757
commit 4b117ec
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package WebGUI::Role::Asset::Keywords; | ||
|
||
=head1 LEGAL | ||
------------------------------------------------------------------- | ||
WebGUI is Copyright 2001-2009 Plain Black Corporation. | ||
------------------------------------------------------------------- | ||
Please read the legal notices (docs/legal.txt) and the license | ||
(docs/license.txt) that came with this distribution before using | ||
this software. | ||
------------------------------------------------------------------- | ||
http://www.plainblack.com info@plainblack.com | ||
------------------------------------------------------------------- | ||
=cut | ||
|
||
use Moose::Role; | ||
|
||
# define tableName => '...'; | ||
|
||
=head1 NAME | ||
Package WebGUI::Role::Asset::Keywords | ||
=head1 DESCRIPTION | ||
Extend C<< get() >> and C<< set() >> to return and accept C<< keywords >> parameters. | ||
=head1 SYNOPSIS | ||
with 'WebGUI::Role::Asset::Keywords'; | ||
$self->set( keywords => '...'); | ||
... $self->get()->{keywords} | ||
=cut | ||
|
||
around set => sub { | ||
warn "set2"; | ||
my $orig = shift; | ||
my $self = shift; | ||
$self->$orig(@_); | ||
my $properties = @_ % 2 ? $_[0] : { @_ }; | ||
if(exists $properties->{keywords}) { | ||
warn "set: handling a keyword: ``$properties->{keywords}''"; | ||
$self->keywords($properties->{keywords}); | ||
} | ||
}; | ||
|
||
around get => sub { | ||
warn "get2"; | ||
my $orig = shift; | ||
my $self = shift; | ||
if( @_ and $_[0] eq 'keywords' ) { | ||
warn "get: handling a keyword: ``@{[ $self->keywords ]}''"; | ||
return $self->keywords; | ||
} | ||
my $properties = $self->$orig(@_); | ||
$properties->{keywords} = $self->keywords; | ||
return $properties; | ||
}; | ||
|
||
|
||
1; | ||
|