Any reason why "(ref $class || $class)" is deprecated?
It can make the semantics of your constuctor confusing. If I want a new object of class Foo then I want to call Foo->new. I'd probably expect $foo->new to clone $foo, but if the class author wanted that functionality they should have created an object method called "clone" or something like that.
In general, it's a good idea to have class methods and object methods completely separate from each other. The ref $class || $class idiom breaks that distinction.
It is useful if you want a new instance based on the same class as an existing object, without having to hard-code the class name.
Well, you can always use (ref $foo)->new if that's what you want.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re^3: bless with => separated args
by davorg
in thread bless with => separated args
by jaa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |