glwtta has asked for the wisdom of the Perl Monks concerning the following question:
Say I have a class: My::Foo::Bar which inherits from My::Foo, calling My::Foo::Bar->can('a_method') will return true whether a_method is defined in My::Foo::Bar or My::Foo - is there a way to differentate between the two? In other words can I find out not only if a class "can" a method, but also that it's not inherited?
A bit of background on why I need this: I have a set of Class::DBI classes all inheriting from a base class and all defined for the same table. In the base class I have an init() which looks at a specific field and reblesses itself to one of the inheriting classes depending on the value. At this point, I want to call the init() on the newly reblessed reference, only if it defines one (obviously bad things happen if it doesn't).
Sure, there are dozens of trivial workarounds, but this is about learning things, right? :)
Thanks,
PS Sorry if something similar has been answered before - for some reason I am having little luck Super Searching for "can"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inheritance and can
by chromatic (Archbishop) on Aug 10, 2003 at 06:16 UTC | |
|
Re: inheritance and can
by PodMaster (Abbot) on Aug 10, 2003 at 05:33 UTC | |
by glwtta (Hermit) on Aug 10, 2003 at 06:14 UTC | |
by bean (Monk) on Aug 10, 2003 at 07:00 UTC | |
by bean (Monk) on Aug 10, 2003 at 07:43 UTC | |
by glwtta (Hermit) on Aug 10, 2003 at 07:26 UTC | |
by bean (Monk) on Aug 10, 2003 at 08:02 UTC | |
|
Re: inheritance and can
by perrin (Chancellor) on Aug 10, 2003 at 12:27 UTC | |
|
Re: inheritance and can
by bbfu (Curate) on Aug 10, 2003 at 17:04 UTC | |
|
Re: inheritance and can
by ehdonhon (Curate) on Aug 11, 2003 at 12:43 UTC |