From: Peter Rabbitson Date: Mon, 8 Nov 2010 01:54:09 +0000 (+0100) Subject: Deprecate rolled-out hash-condition in search() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=450e6dbf;p=dbsrgits%2FDBIx-Class-Historic.git Deprecate rolled-out hash-condition in search() --- diff --git a/Changes b/Changes index 58a6f70..7706e9d 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,7 @@ Revision history for DBIx::Class pairs of column name/info at once - $rs->search now throws when called in void context, as it makes no sense (and is nearly always a sign of a bug/misdesign) + - Deprecate legacy $rs->search( %condition ) syntax - NULL is now supplied unquoted to all debug-objects, in order to differentiate between a real NULL and the string 'NULL' diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index c6a68c3..25344b7 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -286,7 +286,9 @@ sub search_rs { } my $call_attrs = {}; - $call_attrs = pop(@_) if @_ > 1 and ref $_[-1] eq 'HASH'; + $call_attrs = pop(@_) if ( + @_ > 1 and ( ! defined $_[-1] or ref $_[-1] eq 'HASH' ) + ); # see if we can keep the cache (no $rs changes) my $cache; @@ -336,6 +338,9 @@ sub search_rs { } if @_; + carp 'search( %condition ) is deprecated, use search( \%condition ) instead' + if (@_ > 1 and ! $self->result_source->result_class->isa('DBIx::Class::CDBICompat') ); + for ($old_where, $call_cond) { if (defined $_) { $new_attrs->{where} = $self->_stack_cond ( diff --git a/t/60core.t b/t/60core.t index 5ec889c..5c352b2 100644 --- a/t/60core.t +++ b/t/60core.t @@ -122,6 +122,11 @@ is($new_again->ID, 'DBICTest::Artist|artist|artistid=4', 'unique object id gener $artist->delete; } +# deprecation of rolled-out search +warnings_exist { + $schema->resultset('Artist')->search_rs(id => 4) +} qr/\Qsearch( %condition ) is deprecated/, 'Deprecation warning on ->search( %condition )'; + # this has been warning for 4 years, killing throws_ok { $schema->resultset('Artist')->find(artistid => 4); diff --git a/t/64db.t b/t/64db.t index b207a29..ebe22f1 100644 --- a/t/64db.t +++ b/t/64db.t @@ -31,7 +31,7 @@ for (21..30) { } ); } $schema->storage->txn_rollback; -($artist) = $schema->resultset("Artist")->search( artistid => 25 ); +($artist) = $schema->resultset("Artist")->search({ artistid => 25 }); is($artist, undef, "Rollback ok"); is_deeply ( diff --git a/t/relationship/core.t b/t/relationship/core.t index b888d83..8996b1d 100644 --- a/t/relationship/core.t +++ b/t/relationship/core.t @@ -105,7 +105,7 @@ $track = $schema->resultset("Track")->create( { } ); $track->update_from_related( cd => $cd ); -my $t_cd = ($schema->resultset("Track")->search( cd => 4, title => 'Hidden Track 2' ))[0]->cd; +my $t_cd = ($schema->resultset("Track")->search({ cd => 4, title => 'Hidden Track 2' }))[0]->cd; is( $t_cd->cdid, 4, 'update_from_related ok' ); @@ -124,7 +124,7 @@ is( $cd->title, 'Greatest Hits', 'find_or_create_related new record ok' ); is( ($artist->search_related('cds'))[4]->title, 'Greatest Hits', 'find_or_create_related new record search ok' ); $artist->delete_related( cds => { title => 'Greatest Hits' }); -cmp_ok( $schema->resultset("CD")->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' ); +cmp_ok( $schema->resultset("CD")->search({ title => 'Greatest Hits' }), '==', 0, 'delete_related ok' ); # find_or_new_related with an existing record $cd = $artist->find_or_new_related( 'cds', { title => 'Big Flop' } ); @@ -178,7 +178,7 @@ my @producers = $cd->producers(); is( $producers[0]->name, 'Matt S Trout', 'many_to_many ok' ); is( $cd->producers_sorted->next->name, 'Bob The Builder', 'sorted many_to_many ok' ); -is( $cd->producers_sorted(producerid => 3)->next->name, 'Fred The Phenotype', +is( $cd->producers_sorted({producerid => 3})->next->name, 'Fred The Phenotype', 'sorted many_to_many with search condition ok' ); $cd = $schema->resultset('CD')->find(2); diff --git a/t/relationship/doesnt_exist.t b/t/relationship/doesnt_exist.t index b68d083..7575122 100644 --- a/t/relationship/doesnt_exist.t +++ b/t/relationship/doesnt_exist.t @@ -15,7 +15,7 @@ my $link_id = $link->id; ok $link->id; $link->delete; -is $schema->resultset("Link")->search(id => $link_id)->count, 0, +is $schema->resultset("Link")->search({id => $link_id})->count, 0, "link $link_id was deleted"; # Get a fresh object with nothing cached @@ -24,5 +24,5 @@ $bookmark = $schema->resultset("Bookmark")->find($bookmark->id); # This would create a new link row if none existed $bookmark->link; -is $schema->resultset("Link")->search(id => $link_id)->count, 0, +is $schema->resultset("Link")->search({id => $link_id})->count, 0, 'accessor did not create a link object where there was none';