X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;h=a0b252d019b075b82c62f4b925eb76474c212f6e;hb=70b801a45466230a822b99551411211a65b59386;hp=57b6f1c33d9d3afc90a347fbc2eb26d0469c58d2;hpb=3c162f3a933db440b4ba442d2ff81d5b9cb87487;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 57b6f1c..a0b252d 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -20,6 +20,7 @@ use File::Temp (); use Class::Unload; use Class::Inspector (); use Scalar::Util 'looks_like_number'; +use DBIx::Class::Schema::Loader::Column; use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed eval_package_without_redefine_warnings class_path slurp_file sigwarn_silencer firstidx uniq/; use DBIx::Class::Schema::Loader::Optional::Dependencies (); use Try::Tiny; @@ -29,7 +30,7 @@ use List::Util qw/all any none/; use File::Temp 'tempfile'; use namespace::clean; -our $VERSION = '0.07043'; +our $VERSION = '0.07046'; __PACKAGE__->mk_group_ro_accessors('simple', qw/ schema @@ -411,7 +412,7 @@ L relationships, they default to off. Can also be a coderef, for more precise control, in which case the coderef gets -this hash of parameters (as a list:) +this hash of parameters (as a list): rel_name # the name of the relationship rel_type # the type of the relationship: 'belongs_to', 'has_many' or 'might_have' @@ -560,11 +561,7 @@ database and/or schema. Only load matching tables. -=head2 exclude - -Exclude matching tables. - -These can be specified either as a regex (preferrably on the C +These can be specified either as a regex (preferably on the C form), or as an arrayref of arrayrefs. Regexes are matched against the (unqualified) table name, while arrayrefs are matched according to L. @@ -581,6 +578,13 @@ For example: In this case only the tables C and C in C and C in C will be dumped. +=head2 exclude + +Exclude matching tables. + +The tables to exclude are specified in the same way as for the +L option. + =head2 moniker_map Overrides the default table name to moniker translation. Either @@ -609,14 +613,27 @@ a hashref of unqualified table name keys and moniker values =item * -a coderef for a translator function taking a L argument (which stringifies to the -unqualified table name) and returning a scalar moniker +a coderef that returns the moniker, which is called with the following +arguments: + +=over -The function is also passed a coderef that can be called with either -of the hashref forms to get the moniker mapped accordingly. This is -useful if you need to handle some monikers specially, but want to use -the hashref form for the rest. +=item * + +the L object for the table + +=item * + +the default moniker that DBIC would ordinarily give this table + +=item * + +a coderef that can be called with either of the hashref forms to get +the moniker mapped accordingly. This is useful if you need to handle +some monikers specially, but want to use the hashref form for the +rest. + +=back =back @@ -639,7 +656,7 @@ together. Examples: Map for overriding the monikerization of individual L. The keys are the moniker part to override, the value is either a -hashref of coderef for mapping the corresponding part of the +hashref or coderef for mapping the corresponding part of the moniker. If a coderef is used, it gets called with the moniker part and the hash key the code ref was found under. @@ -657,10 +674,12 @@ L takes precedence over this. =head2 col_accessor_map -Same as moniker_map, but for column accessor names. If a coderef is +Same as moniker_map, but for column accessor names. The nested +hashref form is traversed according to L, with an +extra level at the bottom for the column name. If a coderef is passed, the code is called with arguments of - the name of the column in the underlying database, + the DBIx::Class::Schema::Loader::Column object for the column, default accessor name that DBICSL would ordinarily give this column, { table_class => name of the DBIC class we are building, @@ -672,8 +691,9 @@ passed, the code is called with arguments of } coderef ref that can be called with a hashref map -the L
stringifies to the -unqualified table name. +The L and +L objects stringify to their +unqualified names. =head2 rel_name_map @@ -1981,7 +2001,8 @@ sub _dump_to_dir { my @attr = qw/resultset_namespace default_resultset_class/; - unshift @attr, 'result_namespace' unless (not $self->result_namespace) || $self->result_namespace eq 'Result'; + unshift @attr, 'result_namespace' + if $self->result_namespace && $self->result_namespace ne 'Result'; for my $attr (@attr) { if ($self->$attr) { @@ -2248,9 +2269,16 @@ sub _parse_generated_file { $gen .= $pre_md5; $real_md5 = Digest::MD5::md5_base64(encode 'UTF-8', $gen); - croak "Checksum mismatch in '$fn', the auto-generated part of the file has been modified outside of this loader. Aborting.\nIf you want to overwrite these modifications, set the 'overwrite_modifications' loader option.\n" - if !$self->overwrite_modifications && $real_md5 ne $mark_md5; - + if ($real_md5 ne $mark_md5) { + if ($self->overwrite_modifications) { + # Setting this to something that is not a valid MD5 forces + # the file to be rewritten. + $real_md5 = 'not an MD5'; + } + else { + croak "Checksum mismatch in '$fn', the auto-generated part of the file has been modified outside of this loader. Aborting.\nIf you want to overwrite these modifications, set the 'overwrite_modifications' loader option.\n"; + } + } last; } else { @@ -2566,6 +2594,8 @@ sub _table_is_view { return 0; } +sub _view_definition { undef } + # Set up metadata (cols, pks, etc) sub _setup_src_meta { my ($self, $table) = @_; @@ -2576,11 +2606,17 @@ sub _setup_src_meta { my $table_class = $self->classes->{$table->sql_name}; my $table_moniker = $self->monikers->{$table->sql_name}; + # Must come before ->table $self->_dbic_stmt($table_class, 'table_class', 'DBIx::Class::ResultSource::View') - if $self->_table_is_view($table); + if my $is_view = $self->_table_is_view($table); $self->_dbic_stmt($table_class, 'table', $table->dbic_name); + # Must come after ->table + if ($is_view and my $view_def = $self->_view_definition($table)) { + $self->_dbic_stmt($table_class, 'result_source_instance->view_definition', $view_def); + } + my $cols = $self->_table_columns($table); my $col_info = $self->__columns_info_for($table); @@ -2597,8 +2633,12 @@ sub _setup_src_meta { schema_class => $schema_class, column_info => $info, }; + my $col_obj = DBIx::Class::Schema::Loader::Column->new( + table => $table, + name => $col, + ); - $info->{accessor} = $self->_make_column_accessor_name( $col, $context ); + $info->{accessor} = $self->_make_column_accessor_name( $col_obj, $context ); } $self->_resolve_col_accessor_collisions($table, $col_info);