fix case issues for MSSQL
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Base.pm
index 5c395b9..e0a42fa 100644 (file)
@@ -61,6 +61,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 naming
                                 datetime_timezone
                                 datetime_locale
+                                config_file
 /);
 
 
@@ -418,6 +419,11 @@ columns with the DATE/DATETIME/TIMESTAMP data_types.
 Sets the locale attribute for L<DBIx::Class::InflateColumn::DateTime> for all
 columns with the DATE/DATETIME/TIMESTAMP data_types.
 
+=head1 config_file
+
+File in Perl format, which should return a HASH reference, from which to read
+loader options.
+
 =head1 METHODS
 
 None of these methods are intended for direct invocation by regular
@@ -459,6 +465,18 @@ sub new {
 
     bless $self => $class;
 
+    if (my $config_file = $self->config_file) {
+        my $config_opts = do $config_file;
+
+        croak "Error reading config from $config_file: $@" if $@;
+
+        croak "Config file $config_file must be a hashref" unless ref($config_opts) eq 'HASH';
+
+        while (my ($k, $v) = each %$config_opts) {
+            $self->{$k} = $v unless exists $self->{$k};
+        }
+    }
+
     $self->_ensure_arrayref(qw/additional_classes
                                additional_base_classes
                                left_base_classes
@@ -914,6 +932,34 @@ sub _load_tables {
     }
 
     $self->_make_src_class($_) for @tables;
+
+
+    # sanity-check for moniker clashes
+    my $inverse_moniker_idx;
+    for (keys %{$self->monikers}) {
+      push @{$inverse_moniker_idx->{$self->monikers->{$_}}}, $_;
+    }
+
+    my @clashes;
+    for (keys %$inverse_moniker_idx) {
+      my $tables = $inverse_moniker_idx->{$_};
+      if (@$tables > 1) {
+        push @clashes, sprintf ("tables %s reduced to the same source moniker '%s'",
+          join (', ', map { "'$_'" } @$tables),
+          $_,
+        );
+      }
+    }
+
+    if (@clashes) {
+      die   'Unable to load schema - chosen moniker/class naming style results in moniker clashes. '
+          . 'Either change the naming style, or supply an explicit moniker_map: '
+          . join ('; ', @clashes)
+          . "\n"
+      ;
+    }
+
+
     $self->_setup_src_meta($_) for @tables;
 
     if(!$self->skip_relationships) {