Greeting monks,

I'm using Moose for the first time, and would appreciate some expert advice on some issues I'm running into.

I have a set of attributes with custom accessors, methods, etc.. I would like to group them in a single hash structure so that I can set/get/clear them globally (and keep my object nice and neat). I think I could do this by creating a new class with these various attributes in it, but I don't want to do that for a number of reasons. I'm stuck on how to move these attributes into a single place.

To illustrate, the object code currently looks like this:

package My::New::Object; has max_chunk => (is=>'rw', isa=>'Int', init_arg => 'size', clearer=>' +clear_max_chunk'); has liberal_mode => (is=>'rw', isa=>'Bool', default=>sub{1}); has fh => (is=>'rw', isa=>'My::New::Object::ProtoFileHandle', clearer= +>'clear_fh', predicate=>'has_fh', writer=>'_set_fh', coerce => 1, ini +t_arg => 'file', trigger => \&reset_temporary_variables ); [... more attributes, code, etc. ]

And dumping it gives this:

object: $VAR1 = bless( { 'liberal_mode' => 1, 'fh' => bless( \*Symbol::GEN0, 'FileHandle' ), [... other data ...] }, 'My::New::Object' );

I would like it to look like this:

object: $VAR1 = bless( { 'options' => { 'liberal_mode' => 1, 'fh' => bless( \*Symbol::GEN0, 'FileHandle' ), }, [... other data ...] }, 'My::New::Object' );

so that I could have methods like 'set_all_options' and 'clear_options' to deal with everything in the options hash, as well as preserving the various methods I already have associated with the existing attributes.

Any wisdom would be greatly appreciated! Thanks.


In reply to 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.