hello. short version: is there an equivalent of __PACKAGE__ that will give me the name of a subclass rather than the package which immediately contains it?
er, that didn't make much sense. long version:
Class::DBI is fond of constructions like this:
package My::Actor; ... My::Actor->has_many( 'roles', 'My::Actor::Role', 'actor' );
which are normally written with __PACKAGE__ for ease of revision.
I'm consolidating a lot of shared code in a single application, which will be extendable to handle various site requirements. As part of that, I want to subclass modules like the one above, in which case I need the relationships to stick to the subclass, not the superclass.
for example, this:
package Sub::Person; use base qw(Super::Person); __PACKAGE__->has_many( 'organisations', 'Sub::Organisation', 'person' +);
package Super::Person; use base qw(Class::DBI); __PACKAGE__->table('people'); __PACKAGE__->has_many( 'sessions', 'Super::Session', 'person' ); ...
wants to define a class that inherits the session() method and database parameters from Super::Person and adds an organisations() method of its own. (has_many() defines methods that follow database relationships to return objects from the corresponding poop classes).
It works exactly as I want it to except that the has_many() defines a sessions method in Super::Person, not Sub::Person, and breaks the network of relationships. Quite reasonable of it, since __PACKAGE__ is 'Super::Person' at that point. Hence the question: how can I access the name of the current subclass while in the superclass?
But I wonder if this is even possible with class-level code like that? Any suggestions much appreciated.
thanks.
In reply to __PACKAGE__ in subclass by thpfft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |