[prev] [thread] [next] [Date index for 2005/03/25]
Kingsley Kerce writes: > Consider the familiar CD schema in the SYNOPSIS of the Class::DBI POD. > Focusing on the Music::Artist class, and supposing we include a > retrieve_all method in our "top level" class Music::DBI to override > Class::DBI's retrieve_all method, we end up with the following > inheritance hierarchy. > (note: ASCII art ahead -- view in fixed-width font) > > Class::DBI > retrieve_all > | > | > Music::DBI > retrieve_all > | > | > Music::Artist > > As expected, invoking Music::Artist->retrieve_all will execute the > Music::DBI retrieve_all method. > > Now, if we instead use Class::DBI::Loader (a relatively recent > version) to set up the Music::Artist class, and -- just for purposes > of being specific in this example -- suppose we use an SQLite > datasource, we end up with a different inheritance hierarchy. > In particular, Music::Artist has had Class::DBI::SQLite included in > its @ISA (see the Class-DBI-Loader-0.17 distribution, file > Class/DBI/Loader/Generic.pm, line 179, for when this occurs). > > > Class::DBI > / retrieve_all > / \ > / \ > Class::DBI::SQLite Music::DBI > retrieve_all > \ / > \ / > \ / > Music::Artist > > In this case, invoking Music::Artist->retrieve_all will execute the > Class::DBI retrieve_all method. This seems to not be a good thing. > Am I missing something here? Is it really necessary for CDBIL to muck > with @Music::Artist::ISA? > > Thanks, > Kings To avoid any diamond inheritance issues, CDBIL should temporarily -- not permanently -- modify the ISA of a table class. Patch below. Kings $ diff -Bub Class-DBI-Loader-0.17/lib/Class/DBI/Loader/{Generic.pm.orig,Generic.pm} --- Class-DBI-Loader-0.17/lib/Class/DBI/Loader/Generic.pm.orig Fri Mar 11 19:59:45 2005 +++ Class-DBI-Loader-0.17/lib/Class/DBI/Loader/Generic.pm Fri Mar 25 13:03:23 2005 @@ -176,9 +176,10 @@ my $class = $self->_table2class($table); warn qq/Initializing "$class"/ if $self->debug; no strict 'refs'; - @{"$class\::ISA"} = $db_class; + push @{"$class\::ISA"}, $db_class; $class->set_db( Main => @{ $self->{_datasource} } ); $class->set_up_table($table); + @{"$class\::ISA"} = grep { $_ ne $db_class } @{"$class\::ISA"}; $self->{CLASSES}->{$table} = $class; my $code = "package $class;$additional_base$additional"; warn qq/Additional classes are "$code"/ if $self->debug;
Class::DBI::Loader and the CDBI inheritance hierarchy
|
[PATCH] Re: Class::DBI::Loader and the CDBI inheritance hierarchy
|
Generated at 15:09 on 27 Mar 2005 by mariachi v0.52