Thanks for all suggestions, especially from Ikegami which led me to write the code under. There is also the possibility of using builtin caller(), but supporting these four ways to call seems more than enough flexibility and there is also the consideration of performance given that the particular method I am dealing with recurses millions of times for large inputs.
sub method { my $self = $_[0]; # leave it alone for obj/hashref unless( ref( $self ) || !$#_ ) { # else is immed. hash or # list of pairs my %opt = @_; $self = \%opt; } # now $self can be processed as a hashref whichever # of the four calling styles was used }

-M

Free your mind


In reply to Re: enabling OO and non-OO access to the same module using a hash reference by Moron
in thread enabling OO and non-OO access to the same module using a hash reference by Moron

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.