...
Code Block | ||||
---|---|---|---|---|
| ||||
{ package Class; sub new { my $class = shift; my $arg = shift; my $self = bless( {Arg=>$arg}, $class); print "Class::new called with $arg\n"; return $self; } } sub new { my $arg = shift; print "::new called with $arg\n"; } my $class_to_use = Class; my $b1 = new Something; # Invokes global new my $b2 = new Class Something; # Invokes Class::new my $b3 = new $class_to_use; # Surprise! invokes global new! |
...
Code Block | ||||
---|---|---|---|---|
| ||||
# ... my $class_to_use = Class; my $b1 = new( Something); # Invokes global new my $b2 = Class->new( Something); # Invokes Class::new my $b3 = $class_to_use->new( Something); # Invokes Class::new |
...