Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Is "ref($class) || $class" a bad thing?

by adrianh (Chancellor)
on Jul 17, 2004 at 14:31 UTC ( [id://375235]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Is "ref($class) || $class" a bad thing?
in thread Is "ref($class) || $class" a bad thing?

I'm surprised nobody has mentioned called_as_method from Devel::Caller.

use Devel::Caller qw( called_as_method ); sub new { croak "must call new as method" unless called_as_method(0); ... };

Replies are listed 'Best First'.
•Re^5: Is "ref($class) || $class" a bad thing?
by merlyn (Sage) on Jul 20, 2004 at 13:32 UTC
    I'd consider that "a bit too much navel inspection". It breaks code I write that looks like this:
    my $destiny = $someobject->can("somemethod"); @_ = ($someobject, @args); goto &$destiny;
    There shouldn't be any way that this target method should be able to tell that I got there with ->can instead of a true method lookup. So if you write code that breaks that, shame on you.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      I'd consider that "a bit too much navel inspection"

      Oh I agree completely (I said I was surprised that nobody had mentioned it - not that it was a good idea :-)

      It breaks code I write that looks like this:

      ++ Good point.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://375235]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found