From: Rafael Kitover Date: Thu, 13 May 2010 14:45:32 +0000 (-0400) Subject: try to support bizarre column names X-Git-Tag: 0.07000~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Schema-Loader.git;a=commitdiff_plain;h=df55c5fa6330a8443a23d74ded0b23f383be5563 try to support bizarre column names --- diff --git a/TODO b/TODO index 0a020f3..7268147 100644 --- a/TODO +++ b/TODO @@ -33,6 +33,7 @@ - add common tests for preserve_case option - check rel accessors for method conflicts - add an option to add extra code to Result classes + - redo in-memory schema as an @INC coderef rather than temp files - Relationships - Re-scan relations/tables after initial relation setup to find diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 090e429..85374ec 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -1507,14 +1507,21 @@ sub _setup_src_meta { my $cols = $self->_table_columns($table); my $col_info = $self->__columns_info_for($table); + + while (my ($col, $info) = each %$col_info) { + if ($col =~ /\W/) { + ($info->{accessor} = $col) =~ s/\W+/_/g; + } + } + if ($self->preserve_case) { - for my $col (keys %$col_info) { + while (my ($col, $info) = each %$col_info) { if ($col ne lc($col)) { if ((not exists $self->naming->{column_accessors}) || (($self->naming->{column_accessors} =~ /(\d+)/)[0] >= 7)) { - $col_info->{$col}{accessor} = $self->_make_column_accessor_name($col); + $info->{accessor} = $self->_make_column_accessor_name($info->{accessor} || $col); } else { - $col_info->{$col}{accessor} = lc $col; + $info->{accessor} = lc($info->{accessor} || $col); } } }