The problem is actually in the constructor, specifically in the line _title => $args{title} || die "Sorry, we need a title for this menu!". I believe that perl is parsing this such that the remainder of the hash population is read as parameters to the die statement (recall that die can take a list). Try removing the die statement and you'll get the behavior you want. (Update I just grokked dpuu's comment before. Same point). More generally, it's a good idea to separate data validation from the population of data structures precisely to avoid wierd bugs like this one.

Some other comments:

  1. first of all, for an initial attempt at module writing, this is readable and fairly sophisticated, so kudos.
  2. Secondly, in your constructor, it would make more sense to change $self to $class, as the first element of @_ in a class method is the name of the package, not a reference to an instance (with the exception of constructors that double as clone methods, as discussed in perl oo)
  3. Next, I would standardize your argument passing conventions since at present you're passing both hashes (set_choices) and named lists (new).
  4. Finally, in set_choices, since it's getting complex, assign $_ to an intelligible temporary variable. Tracking its value in anything other than simple loops, maps, etc., can get hairy.


In reply to Re: Designing a package object by djantzen
in thread Designing a package object by fuzzyping

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.