in reply to questions about bless's second argument
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. :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |