SQLite needs some heavy refactoring, the subroutines are becoming too complex to understand easily.
MySQL needs implicit FK support, I think.
-the base/use injection stuff needs error checking/reporting, and some testing
+Need tests for left_base_classes, additional_classes, additional_base_classes...
Consider:
If local column is UNIQUE or PK, use has_one() for relation?
$other_class->has_many( $table_relname => $table_class, $rev_cond);
}
+sub _use {
+ my $self = shift;
+ my $target = shift;
+
+ foreach (@_) {
+ $_->require or croak ($_ . "->require: $@");
+ eval "package $target; use $_;";
+ croak "use $_: $@" if $@;
+ }
+}
+
+sub _inject {
+ my $self = shift;
+ my $target = shift;
+ my $schema = $self->schema;
+
+ foreach (@_) {
+ $_->require or croak ($_ . "->require: $@");
+ $schema->inject_base($target, $_);
+ }
+}
+
# Load and setup classes
sub _load_classes {
my $self = shift;
my $table_moniker = $self->_table2moniker($db_schema, $tbl);
my $table_class = $schema . q{::} . $table_moniker;
- # XXX all of this needs require/eval error checking
- $schema->inject_base( $table_class, 'DBIx::Class::Core' );
- $_->require for @db_classes;
- $schema->inject_base( $table_class, $_ ) for @db_classes;
- $schema->inject_base( $table_class, $_ )
- for @{$self->additional_base_classes};
- eval "package $table_class; use $_;"
- for @{$self->additional_classes};
- $schema->inject_base( $table_class, $_ )
- for @{$self->left_base_classes};
+ $self->_inject($table_class, 'DBIx::Class::Core');
+ $self->_inject($table_class, @db_classes);
+ $self->_inject($table_class, @{$self->additional_base_classes});
+ $self->_use ($table_class, @{$self->additional_classes});
+ $self->_inject($table_class, @{$self->left_base_classes});
warn qq/\# Initializing table "$tablename" as "$table_class"\n/
if $self->debug;