X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;h=e0a42fa9708c7ff16604894f0160d5159ad33548;hb=020f3c3ab66a216064907bfcee815f2d77bbb63f;hp=5c395b925c7309e47cab2270cdb0a2654c1faa04;hpb=45be2ce774dc5af71a60397db33bc952c22aa489;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 5c395b9..e0a42fa 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -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 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) {