It sounds like you may want to have multiple methods for your object's user to use, but may be able to get away with doing all the dirty work with only one method which you'd want to keep internal to your object. like:
$obj->add_condiment('Cheeze');
Then in your object's package:
package whatever; ... sub add_condiment { my $obj = shift @_; $obj->set_property("add", "condiment", "cheeze"); } sub add_color { my $obj = shift @_; $obj->set_property("add", "favoriteColor", "blue"); } sub set_property { my $obj = shift @_; my $action_type = $_[0]; my $property_type = $_[1]; my $item = $_[2]; if( $action_type =~ m/add/i && exists $obj->{'properties'}->{"$prope +rty_type"} ) { push @{$obj->{'properties'}->{'$property_type'}}, $item; } elsif( $action_type =~ m/remove/i && exists $obj->{'properties'}->{" +$property_type"} ) { ## loop over the items till you find what you want to ## remove, then remove it } else { die "Something unplanned happened"; }
Technically the larger method doing the dirty work could be called as a function(maybe more efficient) by explicity passing the object reference as the first arguement(i.e. <code>set_property($obj, "add", "condiment", "cheeze") ) Hope mantaining all those properties doesn't seem like such a daunting task now. :) toodlez.

In reply to Re: Re: Generally accepted style in Perl objects by blueAdept
in thread Generally accepted style in Perl objects by Hot Pastrami

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.