You should always use the two argument form.
package Widget; use strict; use warnings; sub new { my ( $class, @args ) = ( shift, @_ ); my $self = {}; bless( $self, $class ); }
I shall anticipate your next question: But $class is the current package, right? So isn't this the same as a one argument bless?
No, it's different. Consider:
{ package Widget::Special; use parent 'Widget'; # We don't write a sub called `new` and rely on the parent class f +or that. } my $special = Widget::Special->new;
Now $class is "Widget::Special", so the two-argument form of bless does the right thing. The one-argument form of bless would return a plain "Widget" object from Widget::Special->new.
Always, always, always use the two-argument form of bless. One-argument bless needs to go and painfully die in a stinking hole of rancid rotting trash.
I hope that helps. :)
In reply to Re: questions about bless's second argument
by tobyink
in thread questions about bless's second argument
by Special_K
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |