From: Darius Jokilehto Date: Tue, 19 Mar 2013 12:18:09 +0000 (+0000) Subject: Add deprecation warnings for cols/include_columns X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=11343b34;p=dbsrgits%2FDBIx-Class-Historic.git Add deprecation warnings for cols/include_columns * Also update docs and include test --- diff --git a/Changes b/Changes index b7b9d0f..59ec224 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for DBIx::Class + * New Features / Changes + - Officially deprecate the 'cols' and 'include_columns' resultset + attributes + 0.08209 2013-03-01 12:56 (UTC) * New Features / Changes - Debugging aid - warn on invalid result objects created by what diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 99eeed9..2436447 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -362,6 +362,8 @@ clkao: CL Kao da5id: David Jack Olrik +dariusj: Darius Jokilehto + davewood: David Schmidt debolaz: Anders Nor Berle diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index eec34b3..b64140d 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -439,6 +439,7 @@ sub search_rs { # older deprecated name, use only if {columns} is not there if (my $c = delete $new_attrs->{cols}) { + carp_unique( "Resultset attribute 'cols' is deprecated, use 'columns' instead" ); if ($new_attrs->{columns}) { carp "Resultset specifies both the 'columns' and the legacy 'cols' attributes - ignoring 'cols'"; } @@ -485,8 +486,12 @@ sub _normalize_selection { my ($self, $attrs) = @_; # legacy syntax - $attrs->{'+columns'} = $self->_merge_attr($attrs->{'+columns'}, delete $attrs->{include_columns}) - if exists $attrs->{include_columns}; + if ( exists $attrs->{include_columns} ) { + carp_unique( "Resultset attribute 'include_columns' is deprecated, use '+columns' instead" ); + $attrs->{'+columns'} = $self->_merge_attr( + $attrs->{'+columns'}, delete $attrs->{include_columns} + ); + } # columns are always placed first, however @@ -3799,7 +3804,7 @@ case the key is the C value, and the value is used as the C from that, then auto-populates C from C and L. @@ -3818,10 +3823,10 @@ is the same as =back -Indicates additional columns to be selected from storage. Works the same -as L but adds columns to the selection. (You may also use the -C attribute, as in earlier versions of DBIC). For -example:- +Indicates additional columns to be selected from storage. Works the same as +L but adds columns to the selection. (You may also use the +C attribute, as in earlier versions of DBIC, but this is +deprecated). For example:- $schema->resultset('CD')->search(undef, { '+columns' => ['artist.name'], diff --git a/t/search/deprecated_attributes.t b/t/search/deprecated_attributes.t new file mode 100644 index 0000000..498c828 --- /dev/null +++ b/t/search/deprecated_attributes.t @@ -0,0 +1,25 @@ +use strict; +use warnings; + +use Test::More; +use Test::Warn; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $cd_rs = $schema->resultset("CD"); + +warnings_exist( sub { + $cd_rs->search_rs( undef, { cols => [ { name => 'artist.name' } ], join => [ 'artist' ] }) +}, qr/Resultset attribute 'cols' is deprecated/, +'deprecation warning when passing cols attribute'); + +warnings_exist( sub { + $cd_rs->search_rs( undef, { + include_columns => [ { name => 'artist.name' } ], join => [ 'artist' ] + }) +}, qr/Resultset attribute 'include_columns' is deprecated/, +'deprecation warning when passing include_columns attribute'); + +done_testing;