For example,
package Baz; sub new { my ($class) = @_; return bless({}, $class); } sub example { my ($self) = @_; if (ref($self) ne __PACKAGE__) { require Carp; Carp::croak( "Method &" . __PACKAGE__ . "::example must not be inherited" ); } print(ref($self) . " ok\n"); } package Baz::Foo; @ISA = 'Baz'; package main; Baz ->new()->example(); # ok. Baz::Foo->new()->example(); # dies.
outputs
Baz ok Method &Baz::example must not be inherited at !.pl line 28
It's possible to circumvent this by re-blessing the object.
In reply to Re^2: checking a method is not subclassed
by ikegami
in thread checking a method is not subclassed
by water
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |