Kind monks, I'd like to ask some help with my problem with Moose. I'd like to create a trait, or even better an overloaded type that does special stuff with "around" accessor. Normally, one writes

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


In reply to Moose roles by dk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.