in reply to checking a method is not subclassed
I'm missing something here, or I wasn't clear. Here's some code:
In this example, I am cool with a user calling bleep on either 'a' or 'b'. I'm also cool with a user calling baz on either 'a' or 'b'. What I'd like to detect from Foo is that a subclass (NewFoo) overrode a certain method. That is, $b->baz calls NewFoo::Baz, as that overrode Foo::Baz.# untested package Foo; sub bleep {...} sub baz { ... } package NewFoo; use base qw(Foo); sub baz { ... } package main; my $a = Foo->new; my $b= NewFoo->new; $a->bleep; $b->bleep; $a->baz; $b->baz;
I'm looking for a way for Foo to detect and carp that a subclass took away its rights to own the code for method baz.
Probably this isn't "nice" OO -- "thou shalt never subclass me, dammnit" isnt friendly -- but I'm wondering how to do it anyway.
I really like the suggestion about just saying "never subclass baz" in the docs (++ to that post), but need something stronger.
The comments above about checking the ref on self don't seem relevant to me, as here the problem is that Foo::baz never gets involved when someone calls baz on $b... it is too late, the baz is then a NewFoo baz at that point.....?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: checking a method is not subclassed
by salva (Canon) on Feb 02, 2006 at 17:46 UTC | |
by water (Deacon) on Feb 02, 2006 at 17:51 UTC | |
Re^2: checking a method is not subclassed
by gam3 (Curate) on Feb 02, 2006 at 18:28 UTC |
In Section
Seekers of Perl Wisdom