Data::Table isn't an object factory. The various "from" constructors are just that, constructors. Data::Table has multiple constructors, but there is nothing particularly magical about them. The SQLness of fromSQL isn't provided by a separate class, it is simply what the fromSQL constructor does.
Can you give an example of the problem you are trying to solve in the context of the following code?
use strict;
use warnings;
package Table;
sub MakeTypeA {
my ($class, %params) = @_;
return $class->TypeA::new(%params);
}
sub MakeTypeB {
my ($class, %params) = @_;
return $class->TypeB::new(%params);
}
sub ShowType {
my ($self) = @_;
print "$self->{type}\n";
}
package TypeA;
push @TypeA::ISA, 'Table';
sub new {
my ($class, %params) = @_;
return bless {type => 'TypeA', %params}, $class;
}
sub foo {
print "TypeA::foo\n";
}
package TypeB;
push @TypeB::ISA, 'Table';
sub new {
my ($class, %params) = @_;
return bless {type => 'TypeB', %params}, $class;
}
sub baa {
print "TypeA::baa\n";
}
package MiddleMan;
push @MiddleMan::ISA, 'Table';
sub ShowType {
my ($self) = @_;
print 'MiddleMan, ';
$self->SUPER::ShowType();
}
sub ShowClass {
my ($self) = @_;
print ref $self, "\n";
}
package MyClass1;
push @MyClass1::ISA, 'MiddleMan';
package MyClass2;
push @MyClass2::ISA, 'MiddleMan';
package main;
my $obj1 = MyClass1->MakeTypeA();
my $obj2a = MyClass2->MakeTypeA();
my $obj2b = MyClass2->MakeTypeB();
$obj1->ShowType();
$obj1->ShowClass();
$obj2a->ShowType();
$obj2a->ShowClass();
$obj2b->ShowType();
$obj2b->ShowClass();
True laziness is hard work
|