[CDBI] Register child classes on 'use'?

Aaron Turner synfinatic at gmail.com
Wed Mar 22 17:43:15 GMT 2006


I have a parent class which all my Class::DBI modules inherit from. 
One thing I would like to do is have each module, when it is loaded
(use MyModule) to register with the parent class.

I was planning on doing something like:

package ParentClass;
use base 'Class::DBI::Pg';

my %children;
sub register() {
  my $self = shift;
  $children{$self} = 1;
}

package SubClass;
use base 'ParentClass';
BEGIN {
__PACKAGE__->register();
}

# other Class::DBI stuff here

But, while this works for some modules, others blow up:

perl -wc Channel.pm
options method already exists in Mu::TestRunRagChannel
   at /Library/Perl/5.8.6/Class/DBI/Relationship/HasMany.pm line 18
Can't call method "clear_object_index" on an undefined value at
   /Library/Perl/5.8.6/Class/DBI/Relationship.pm line 23.
Compilation failed in require at ../Mu/Channel.pm line 5.
BEGIN failed--compilation aborted at ../Mu/Channel.pm line 5.
Compilation failed in require at ../Mu/ChannelOption.pm line 4.
BEGIN failed--compilation aborted at ../Mu/ChannelOption.pm line 4.
Compilation failed in require at Channel.pm line 4.
BEGIN failed--compilation aborted at Channel.pm line 4.

I'm guessing the problem has to do with Channel.pm importing
ChannelOption.pm and ChannelOption.pm importing Channel.pm (it's a
parent/child relationship).

Suggestions?

--
Aaron Turner
http://synfin.net/




More information about the ClassDBI mailing list