bless REF, CLASSNAME bless REF |
告诉REF所引用的实体,它现在是一个对象在CLASSNAME包,或CLASSNAME包,如果被省略。建议使用两个参数形式bless函数。
参考的对象blessed CLASSNAME
bless包的类创建的对象引用。例如:
package Person; sub new { my $class = shift; my $self = { _firstName => shift, _lastName => shift, _ssn => shift, }; # Print all the values just for clarification. # by www.gitbook.net print "First Name is $self->{_firstName}\n"; print "Last Name is $self->{_lastName}\n"; print "SSN is $self->{_ssn}\n"; bless $self, $class; return $self; }