Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
langperl
{
  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
bgColor#ccccff
langperl
# ...

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

...