Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inheriting from Data::Table
by GrandFather (Saint) on Mar 17, 2012 at 02:02 UTC | |
by Anonymous Monk on Mar 17, 2012 at 12:06 UTC | |
by glasswalk3r (Friar) on Mar 17, 2012 at 17:36 UTC | |
by Anonymous Monk on Mar 17, 2012 at 17:09 UTC | |
by GrandFather (Saint) on Mar 18, 2012 at 04:40 UTC |