I'm trying to inherit from Data::Table, but I'm having difficulty since I need to use Data::Table::FromSql to load the data. I've found a solution by inheriting from MyTable which has an instance of a Data::Table and then uses AUTOLOAD to redirect calls from TableA to Data::Table. The highly simplifed code is shown below. I've left many of the details out.
package MyTable sub new { ... } sub buildFromSql { $self->{t} = Data::Table::fromSql($dbh,$sql); } sub AUTOLOAD { my $self = shift; my $command = our $AUTOLOAD; $command =~ s/.*://; $self->{t}->$command(@_); }
package TableA @ISA = ("MyTable"); sub new { $self = $class->SUPER::new(@_); $self->buildFromSql($dbh,$sql) }
## CLIENT my $table = new TableA(); $table->html2."\n";
This works but I'm wondering if there are better ways to do this. Can anyone suggest any ways of improving this? thanks, Michael
In reply to inheriting from Data::Table by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |