in reply to multi-arg bless

The problem seems to me to be that:
my $self = bless {}, ref($class) || $class;
is improperly refactored as
my $self = bless {}, ref($_[0]) || @_;
when it should be
my $self = bless {}, ref($_[0]) || $_[0];

I am avoiding the arguments for and against the use of such dual nature constructors.

Be well.

Replies are listed 'Best First'.
Re^2: multi-arg bless
by ysth (Canon) on Jul 13, 2004 at 17:25 UTC
    The goal was to pass only one arg to bless when @_ is empty. In this case, $_[0] will be undef, and bless will give a warning that it is treated as an empty string and another warning that blessing to an empty string is treated as blessing into package "main" (whereas 1-arg bless would bless into the current package). Obviously there are ways to make it work; my point was just that a (to me, pointless) prototype interferes with one of the easiest.