Restricting a Method to Class-Only o Instance-Only

物理狂人發表於2012-05-04
use Carp qw(croak);

sub instance_only {
ref(my $self = shift ) or croak "instance variable needed";
... use $self as the instance ...
}

sub class_only {
ref(my $self = shift) and croak "class name needed";
... use $class as the class..
}

instance variable needed at their_code line 1234

告訴使用者引起問題的行號
croak->die
crap->warn

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24104518/viewspace-722725/,如需轉載,請註明出處,否則將追究法律責任。

相關文章