in reply to Re^2: Is "ref($class) || $class" a bad thing?
in thread Is "ref($class) || $class" a bad thing?
Seems like it'd be less work to write:
sub new { croak "new() called as a function, not a method\n" unless @_; bless {}, shift; }
If you really want to be paranoid, though, you should make something similar a precondition of all of your methods. (For convenience sake of everyone else, though, please use [CPAN://Scalar::Util]::blessed(). Also, you ought to call isa() directly, not through UNIVERSAL::, in case someone overrides it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Is "ref($class) || $class" a bad thing?
by stvn (Monsignor) on Jul 13, 2004 at 01:11 UTC | |
by chromatic (Archbishop) on Jul 13, 2004 at 03:37 UTC | |
|
Re^4: Is "ref($class) || $class" a bad thing?
by adrianh (Chancellor) on Jul 17, 2004 at 14:31 UTC | |
by merlyn (Sage) on Jul 20, 2004 at 13:32 UTC | |
by adrianh (Chancellor) on Jul 20, 2004 at 16:46 UTC |