Did you read/run the code snippets in the EXAMPLES section of the POD? Did you read the BUGS section of the POD docs for Devel::Caller?

Yes and yes. Your code fails in several undocumented ways (see below). called_as_method does not. The issue with call frame optimisation for called_as_method would not apply for its use to implement the functionality of your routines.

In theory, it's not such a mix as it might seem. I submit that, as polymorphism is one of the core principles of OO, this kind of inheritable (there's another one); shareable; importable/exportable; polymorphic interface is more extensible and useful than you claim; and more focused too.

I think we are just going to have to agree to differ over this. In my experience mixing OO and functional/procedural APIs always causes more problems than it solves.

The origin of this method's name has to do with what it does.

In $args = coerce_array($a, $b, $c, $d) where is the array? :-)

Coerced into what?

The name does not describe what it does. Something like list_to_hashargs might be closer.

Did you test this? It doesn't fail in my tests or examples (which show in fact this very thing.)

No I didn't, since it was obvious from reading the code definition that it would fail. However, here are some tests to prove it. This isn't the only way they can foul up - try to find some more, then reconsider using called_as_method :-)

#! /usr/bin/perl -Tw use strict; use warnings; use Test::More tests => 9; { package Foo; use Class::OOorNO qw(myself OOorNO myargs coerce_array); sub get_myself { return myself(@_) }; sub get_OOorNO { return OOorNO(@_) }; sub get_myargs { return myargs(@_) }; }; # These three tests work as expected... is Foo::get_myself(Bar=>1), undef, 'myself: not called as method'; ok(! Foo::get_OOorNO(Bar => 1), 'OOorNO: not called as method'); is_deeply [ Foo::get_myargs( Bar => 1 ) ], [Bar => 1], 'myargs: leaves non-method call args alone'; # But these fail because your tests think they're being called # as a class method is Foo::get_myself(Foo=>1), undef, 'myself: not called as method'; ok(! Foo::get_OOorNO(Foo => 1), 'OOorNO: not called as method'); is_deeply [ Foo::get_myargs( Foo => 1 ) ], [Bar => 1], 'myargs: leaves non-method call args alone'; # Even worse, once we load another class eval q< { package Bar; use base qw(Foo); }; >; # the original test fail too - evil side effects. is Foo::get_myself(Bar=>1), undef, 'myself: not called as method'; ok(! Foo::get_OOorNO(Bar => 1), 'OOorNO: not called as method'); is_deeply [ Foo::get_myargs( Bar => 1 ) ], [Bar => 1], 'myargs: leaves non-method call args alone';

In reply to Re^5: Seeking Wisdom: proposed fix for a broken CPAN module by adrianh
in thread Seeking Wisdom: proposed fix for a broken CPAN module by Tommy

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.