in reply to __PACKAGE__ in subclass
I think you've got something wrong about that subclassing. The superclass doesn't know its subclasses, only the subclass knows its superclasses as they are in @ISA. The base pragma only puts a class into @ISA.
Now, whenever a method in the subclass is called and not found there, it is searched for in all classes that stand in @ISA of that package:
package Superclass; sub foo { print "Superclass::foo( @_ )\n" } sub bar { print "Superclass::bar( @_ )\n" } package Subclass; use base 'Superclass'; sub bar { print "Subclass::bar( @_ )\n" } package main; Subclass->foo; #Superclass::foo( Subclass ) Subclass->bar; #Subclass::bar( Subclass )
If you make Class::DBI create a 'sessions()' method for "Super::Person" and "Sub::Person" has "Super::Person" in its @ISA, you can be sure that perl will look for 'sessions()' in "Super::Person" if it doesn't find it in "Sub::Person", but the first parameter passed to 'sessions' will be "Sub::Person". Just get rid of that __PACKAGE__, it only makes you unflexible.
--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: __PACKAGE__ in subclass
by thpfft (Chaplain) on Oct 20, 2002 at 19:58 UTC | |
by Aristotle (Chancellor) on Oct 20, 2002 at 20:06 UTC |