I suppose my first thought was that foo( bar => { hoo => hah } ) would be 3 parameters (which would not coerce back) when I now realise it is 2, with the second being a hash reference to the (anonymous) nested hash.

But the problem I am actually having with providing support for a coerced hash (or even an ordered list of parameters for that matter) is this:

my $oref = OtherModule -> new(); Package::method( $oref, 'gotcha' );
Just to make it clearer we'll say OtherModule is a subclass of Package. So the problem is that testing for OO-access in Package::method will go false-positive if the above non-oo construction is used. Requiring all non-OO users to use a hash reference for their parameters makes it (a) easier to test access method and (b) code applying to the object reference that normally arrives will work compatibly at once if a hash reference is passed non-oo intead. So this is why I am hoping I can go that route. For example, perlbot even suggests testing ref($_[0]) as an alternative to the forbidden (ref($_[0]) eq 'ClassName'). But that would prevent some trivial methods from having say a file handle as parameter owing to the same false-positive result I am trying to avoid. And I don;t want to have to test all possible references that aren't to some class! (update: because a class is not allowed to make assumptions about subclasses so that would be what had to be tested for a completely generic test for oo-ness)

-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.