in reply to Re: Re^3: Seeking Wisdom: proposed fix for a broken CPAN module
in thread Seeking Wisdom: proposed fix for a broken CPAN module

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';