From: Michael G Schwern Date: Thu, 21 Feb 2008 06:34:10 +0000 (-0800) Subject: Add in a warning if a column is declared as TEMP but it's already declared X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a6c527389f8d7f8fafcf36fe5887b2348c3e9105;p=dbsrgits%2FDBIx-Class-Historic.git Add in a warning if a column is declared as TEMP but it's already declared real. --- diff --git a/lib/DBIx/Class/CDBICompat/TempColumns.pm b/lib/DBIx/Class/CDBICompat/TempColumns.pm index d025bb8..923e895 100644 --- a/lib/DBIx/Class/CDBICompat/TempColumns.pm +++ b/lib/DBIx/Class/CDBICompat/TempColumns.pm @@ -5,19 +5,29 @@ use strict; use warnings; use base qw/DBIx::Class/; +use Carp; + __PACKAGE__->mk_classdata('_temp_columns' => { }); sub _add_column_group { my ($class, $group, @cols) = @_; - if ($group eq 'TEMP') { - $class->_register_column_group($group => @cols); - $class->mk_group_accessors('temp' => @cols); - my %tmp = %{$class->_temp_columns}; - $tmp{$_} = 1 for @cols; - $class->_temp_columns(\%tmp); - } else { - return $class->next::method($group, @cols); + + return $class->next::method($group, @cols) unless $group eq 'TEMP'; + + my %new_cols = map { $_ => 1 } @cols; + my %tmp_cols = %{$class->_temp_columns}; + + for my $existing_col ( grep $new_cols{$_}, $class->columns ) { + # Already been declared TEMP + next if $tmp_cols{$existing_col}; + + carp "Declaring column $existing_col as TEMP but it already exists"; } + + $class->_register_column_group($group => @cols); + $class->mk_group_accessors('temp' => @cols); + + $class->_temp_columns({ %tmp_cols, %new_cols }); } sub new { diff --git a/t/cdbi-t/04-lazy.t b/t/cdbi-t/04-lazy.t index 39d3efd..27e7ab5 100644 --- a/t/cdbi-t/04-lazy.t +++ b/t/cdbi-t/04-lazy.t @@ -1,6 +1,8 @@ +#!/usr/bin/perl -w + use strict; use Test::More; - +use Test::Warn; #---------------------------------------------------------------------- # Test lazy loading @@ -13,7 +15,7 @@ BEGIN { next; } eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 34); + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 35); } INIT { @@ -80,6 +82,10 @@ eval { # Multiple false columns ok($@, $@); +warning_is { + Lazy->columns( TEMP => qw(that) ); +} "Declaring column that as TEMP but it already exists"; + # Test that create() and update() throws out columns that changed { my $l = Lazy->create({