* use $^X instead of assuming /usr/bin/perl
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Base.pm
index b4c9951..f7e1051 100644 (file)
@@ -418,6 +418,8 @@ sub _reload_classes {
     my ($self, @tables) = @_;
 
     $self->_dump_to_dir(map { $self->classes->{$_} } @tables);
+
+    unshift @INC, $self->dump_directory;
     
     for my $table (@tables) {
         my $moniker = $self->monikers->{$table};
@@ -469,11 +471,10 @@ sub _ensure_dump_subdirs {
 sub _dump_to_dir {
     my ($self, @classes) = @_;
 
-    my $target_dir = $self->dump_directory;
-
     my $schema_class = $self->schema_class;
     my $schema_base_class = $self->schema_base_class || 'DBIx::Class::Schema';
 
+    my $target_dir = $self->dump_directory;
     warn "Dumping manual schema for $schema_class to directory $target_dir ...\n"
         unless $self->{dynamic} or $self->{quiet};
 
@@ -482,7 +483,6 @@ sub _dump_to_dir {
         . qq|use strict;\nuse warnings;\n\n|
         . qq|use base '$schema_base_class';\n\n|;
 
-    
     if ($self->use_namespaces) {
         $schema_text .= qq|__PACKAGE__->load_namespaces|;
         my $namespace_options;
@@ -498,7 +498,6 @@ sub _dump_to_dir {
     }
     else {
         $schema_text .= qq|__PACKAGE__->load_classes;\n|;
-
     }
 
     $self->_write_classfile($schema_class, $schema_text);
@@ -516,7 +515,6 @@ sub _dump_to_dir {
 
     warn "Schema dump completed.\n" unless $self->{dynamic} or $self->{quiet};
 
-    unshift @INC, $target_dir;
 }
 
 sub _write_classfile {
@@ -531,6 +529,11 @@ sub _write_classfile {
         unlink($filename);
     }    
 
+    my $custom_content = $self->_get_custom_content($class, $filename);
+    $custom_content ||= qq|\n\n# You can replace this text with custom|
+        . qq| content, and it will be preserved on regeneration|
+        . qq|\n1;\n|;
+
     $text .= qq|$_\n|
         for @{$self->{_dump_storage}->{$class} || []};
 
@@ -550,16 +553,10 @@ sub _write_classfile {
         for @{$self->{_ext_storage}->{$class} || []};
 
     # Write out any custom content the user has added
-    my $custom_content = $self->_get_custom_content($class, $filename);
-
-    $custom_content ||= qq|\n\n# You can replace this text with custom|
-        . qq| content, and it will be preserved on regeneration|
-        . qq|\n1;\n|;
-
     print $fh $custom_content;
 
     close($fh)
-        or croak "Cannot close '$filename': $!";
+        or croak "Error closing '$filename': $!";
 }
 
 sub _get_custom_content {