in reply to Curious Constructor Syntax
When you invoke a method via
method Class(args)
"Class" is passed as the first argument. That's how the new() implementation that you showed knows how to bless the anonymous hash (i.e., what Class to create an instance of). Typically, methods invoked in this fashion return new instances of some class. But this isn't always the case.
Here's a simple demonstration to show that this behavior isn't limited to new()
which displays test invoked on behalf of Foo with args: 47package Foo; sub test { print "test invoked on behalf of ", shift, " with args: @_\n"; } package main; test Foo(47);
|
|---|