From: Dagfinn Ilmari Mannsåker Date: Mon, 28 Jan 2008 21:03:25 +0000 (+0000) Subject: Merge _column_is_auto_increment() and _column_extra_attr() into X-Git-Tag: 0.04999_01~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a8df03450bdfb3a5131e679274dab15f6e2db7f0;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Merge _column_is_auto_increment() and _column_extra_attr() into _extra_column_info() that gets merged into the column_info hash. --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index d29f8e7..f27d882 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -222,15 +222,9 @@ sub _columns_info_for { my $col_name = $info->{COLUMN_NAME}; $col_name =~ s/^\"(.*)\"$/$1/; - if ($self->_column_is_auto_increment($info)) { - $column_info{is_auto_increment} = 1; - } + my $extra_info = $self->_extra_column_info($info) || {}; - if (my $extra = $self->_column_extra_attr($info)) { - $column_info{extra} = $extra; - } - - $result{$col_name} = \%column_info; + $result{$col_name} = { %column_info, %$extra_info }; } $sth->finish; }; @@ -255,15 +249,9 @@ sub _columns_info_for { $column_info{size} = $2; } - if ($self->_column_is_auto_increment($table, $columns[$i], $sth, $i)) { - $column_info{is_auto_increment} = 1; - } + my $extra_info = $self->_extra_column_info($table, $columns[$i], $sth, $i) || {}; - if (my $extra = $self->_column_extra_attr($table, $columns[$i], $sth, $i)) { - $column_info{extra} = $extra; - } - - $result{$columns[$i]} = \%column_info; + $result{$columns[$i]} = { %column_info, %$extra_info }; } $sth->finish; @@ -281,12 +269,9 @@ sub _columns_info_for { return \%result; } -# Override this in vendor class to return whether a column is -# auto-incremented -sub _column_is_auto_increment {} - -# Override this in vendor class to return any "extra" column attributes -sub _column_extra_attr {} +# Override this in vendor class to return any additional column +# attributes +sub _extra_column_info {} =head1 SEE ALSO diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index d5fc32e..c962e0b 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -95,10 +95,15 @@ sub _table_uniq_info { return \@uniqs; } -sub _column_is_auto_increment { +sub _extra_column_info { my ($self, $info) = @_; + my %extra_info; - return $info->{COLUMN_DEF} && $info->{COLUMN_DEF} =~ /\bnextval\(/i; + if ($info->{COLUMN_DEF} && $info->{COLUMN_DEF} =~ /\bnextval\(/i) { + $extra_info{is_auto_increment} = 1; + } + + return \%extra_info; } =head1 SEE ALSO diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index 3998fe8..4f21f86 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -146,13 +146,18 @@ sub _sqlite_parse_table { return { rels => \@rels, uniqs => \@uniqs, auto_inc => \%auto_inc }; } -sub _column_is_auto_increment { +sub _extra_column_info { my ($self, $table, $col_name, $sth, $col_num) = @_; - + my %extra_info; + $self->{_sqlite_parse_data}->{$table} ||= $self->_sqlite_parse_table($table); - return $self->{_sqlite_parse_data}->{$table}->{auto_inc}->{$col_name}; + if ($self->{_sqlite_parse_data}->{$table}->{auto_inc}->{$col_name}) { + $extra_info{is_auto_increment} = 1; + } + + return \%extra_info; } sub _table_fk_info { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index a4f795a..23b5deb 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -121,21 +121,18 @@ sub _table_uniq_info { return \@uniqs; } -sub _column_is_auto_increment { +sub _extra_column_info { my ($self, $info) = @_; + my %extra_info; - return $info->{mysql_is_auto_increment}; -} - -sub _column_extra_attr { - my ($self, $info) = @_; - - my $extra_attr; + if ($info->{mysql_is_auto_increment}) { + $extra_info{is_auto_increment} = 1 + } if ($info->{mysql_type_name} =~ /\bunsigned\b/i) { - $extra_attr->{unsigned} = 1; + $extra_info{extra} = { unsigned => 1 }; } - return $extra_attr; + return \%extra_info; } =head1 SEE ALSO