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; }