Skip to content

Commit

Permalink
Adding around => get and set in Asset.pm did nothing; moving them
Browse files Browse the repository at this point in the history
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
scottwalters committed Jun 4, 2010
1 parent b5d1757 commit 4b117ec
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lib/WebGUI/Role/Asset/Keywords.pm
@@ -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;

0 comments on commit 4b117ec

Please sign in to comment.