dk has asked for the wisdom of the Perl Monks concerning the following question:
has x => ( is => 'rw' ); around x => \&my_accessor;
I'd like to shorten that into
has x => ( is => 'rw', traits => ['MyAccessor']);
or even better, to
has x => ( isa => 'MyAccessor' );
possibly making MyAccessor a separate MooseX module. However, even with help of #moose I couldn't go far, and, also because IRC is not the best way of exchanging large pieces of code, I'd like to ask if you could help me here. I stopped here:
package Moose::Meta::Attribute::Custom::Trait::MyAccessor; sub register_implementation { return 'MyAccessor' } package MyAccessor; use Moose::Role; my $meta = __PACKAGE__->meta;
I thought that I should manipulate $meta, but I'm unsure how. Any ideas?
Thank you!
Update: as usual, I've asked how to do X when I wanted Y. My apologies. Actually, I'd like to use array and hash attributes in mixed list and array contexts:
@list = $obj-> prop; $obj->prop(@list); $array = $obj->prop; $obj->prop($array);
I though I could do that with "around", which prompted the original question
has prop; around prop => \&my_accessor;
Update #2: Problem solved. Proof of concept is on CPAN
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose roles
by stvn (Monsignor) on Jan 13, 2010 at 16:38 UTC | |
by dk (Chaplain) on Jan 13, 2010 at 18:02 UTC | |
by EvanCarroll (Chaplain) on Jan 13, 2010 at 21:58 UTC | |
by dk (Chaplain) on Jan 13, 2010 at 22:27 UTC | |
|
Re: Moose roles
by EvanCarroll (Chaplain) on Jan 13, 2010 at 16:38 UTC | |
by dk (Chaplain) on Jan 13, 2010 at 18:31 UTC | |
by EvanCarroll (Chaplain) on Jan 13, 2010 at 22:03 UTC |