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;
use File::Temp 'tempfile';
use namespace::clean;
-our $VERSION = '0.07043';
+our $VERSION = '0.07045';
__PACKAGE__->mk_group_ro_accessors('simple', qw/
schema
Exclude matching tables.
-These can be specified either as a regex (preferrably on the C<qr//>
+These can be specified either as a regex (preferably on the C<qr//>
form), or as an arrayref of arrayrefs. Regexes are matched against
the (unqualified) table name, while arrayrefs are matched according to
L</moniker_parts>.
=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</moniker_parts>, 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,
}
coderef ref that can be called with a hashref map
-the L<table object|DBIx::Class::Schema::Loader::Table> stringifies to the
-unqualified table name.
+The L<column|DBIx::Class::Schema::Loader::Column> and
+L<table|DBIx::Class::Schema::Loader::Table> objects stringify to their
+unqualified names.
=head2 rel_name_map
sub load {
my $self = shift;
- $self->_load_tables(
- $self->_tables_list({ constraint => $self->constraint, exclude => $self->exclude })
- );
+ $self->_load_tables($self->_tables_list);
}
=head2 rescan
$self->_relbuilder->{schema} = $schema;
my @created;
- my @current = $self->_tables_list({ constraint => $self->constraint, exclude => $self->exclude });
+ my @current = $self->_tables_list;
foreach my $table (@current) {
if(!exists $self->_tables->{$table->sql_name}) {
$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 {
my $default_ident = $default_code->( $ident, @extra );
my $new_ident;
if( $map && ref $map eq 'HASH' ) {
- if (my @parts = try{ @{ $ident } }) {
+ if (my @parts = try { @{ $ident } }) {
my $part_map = $map;
while (@parts) {
my $part = shift @parts;
return 0;
}
+sub _view_definition { undef }
+
# Set up metadata (cols, pks, etc)
sub _setup_src_meta {
my ($self, $table) = @_;
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);
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);