sub new { my $this = {}; print "n /* n ** Created by Cocoa.pm n ** Use at own risk"; print "n ** Did this code even get pass the javac compiler? "; print "n **/ n"; bless $this; return $this; } 也可以简单地调用包内或包外的其它函数来做更多的初始化工作,如:
sub new { my $this = {} bless $this; $this->doInitialization(); return $this; } 创建类时,应该允许它可被继承,应该可以把类名作为第一个参数来调用new函数,那么new函数就象下面的语句:
· sub new { my $class = shift; # Get the request class name my $this = {}; bless $this, $class # Use class name to bless() reference $this->doInitialization(); return $this; } 此方法使用户可以下列三种方式之一来进行调用: