better inject/use stuff
Brandon Black [Mon, 30 Jan 2006 19:09:32 +0000 (19:09 +0000)]
TODO
lib/DBIx/Class/Schema/Loader/Generic.pm

diff --git a/TODO b/TODO
index 335bf1a..24c6e2f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,7 +3,7 @@ Reminders to myself or whoever else ever looks in here...
 
 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?
index b0adf67..2e26292 100644 (file)
@@ -231,6 +231,28 @@ sub _make_cond_rel {
     $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;
@@ -256,16 +278,11 @@ sub _load_classes {
         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;