You might want to look at MooseX::AttributeHelpers. It lets you create handlers for hashrefs and arrayref types (among other types), something like this (based on the example in the documentation):

has 'options' => ( metaclass => 'Collection::Hash', is => 'rw', isa => 'HashRef[Str]', default => sub { {} }, provides => { exists => 'option_exists', kv => 'options', get => 'get_option', set => 'set_option', clear => 'clear_options', accessor => 'option', }, curries => { set => { set_quantity => [ 'quantity' ] } } );

This lets you use the get_option and set_option methods, or option to use accessor syntax like $obj->option('test') to get an option or $obj->option( test => 'value') to set the value, and clear_options clears the whole hash. The curries hash lets you pass parameters to the handler methods in object methods, e.g. $obj->set_quantity(42) (using the code above) would be equivalent to $obj->set_option(quantity => 42)

See MooseX::AttributeHelpers::MethodProvider::Hash for the options available for hash objects.

In reply to Re: Moose question by james2vegas
in thread Moose question by gwg

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.