From: Peter Rabbitson Date: Wed, 11 Jun 2014 13:22:31 +0000 (+0200) Subject: Rename (with a silent compat shim) couple of badly named customcond args X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a446d7f8;p=dbsrgits%2FDBIx-Class-Historic.git Rename (with a silent compat shim) couple of badly named customcond args foreign_relname makes absolutely no sense - it *is* a relationship after all, of course it has a name. Now renamed to rel_name to be consistent with the relationship condition resolver self_rowobj uses the old rowobj nomenclature - switch to self_resultobj --- diff --git a/Changes b/Changes index 88ed825..055c6f4 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ Revision history for DBIx::Class like the rest of DBIC - DBIC::FilterColumn "from_storage" handler is now invoked on NULLs returned from storage + - Custom condition relationships are now invoked with a slightly + different signature (existing coderefs will continue to work) * Fixes - Fix Resultset delete/update affecting *THE ENTIRE TABLE* in cases diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index a924b7e..c39755a 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -232,11 +232,17 @@ clause, the C<$args> hashref passed to the subroutine contains some extra metadata. Currently the supplied coderef is executed as: $relationship_info->{cond}->({ - self_alias => The alias of the invoking resultset ('me' in case of a result object), - foreign_alias => The alias of the to-be-joined resultset (often matches relname), - self_resultsource => The invocant's resultsource, - foreign_relname => The relationship name (does *not* always match foreign_alias), - self_rowobj => The invocant itself in case of a $result_object->$relationship call + self_resultsource => The resultsource instance on which rel_name is registered + rel_name => The relationship name (does *NOT* always match foreign_alias) + + self_alias => The alias of the invoking resultset + foreign_alias => The alias of the to-be-joined resultset (does *NOT* always match rel_name) + + self_resultobj => The invocant object itself in case of a $resultobj->$rel_name() call + + # deprecated inconsistent names, will be forever available for legacy code + self_rowobj => Old deprecated slot for self_resultobj + foreign_relname => Old deprecated slot for rel_name }); =head3 attributes diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 37ef6cb..92665d6 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2214,7 +2214,7 @@ sub populate { foreach my $rel (@rels) { next unless ref $data->[$index]->{$rel} eq "HASH"; my $result = $self->related_resultset($rel)->create($data->[$index]->{$rel}); - my ($reverse_relname, $reverse_relinfo) = %{$rsrc->reverse_relationship_info($rel)}; + my (undef, $reverse_relinfo) = %{$rsrc->reverse_relationship_info($rel)}; my $related = $result->result_source->_resolve_condition( $reverse_relinfo->{cond}, $self, diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 6ef169e..13397dd 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -1771,20 +1771,26 @@ sub _resolve_relationship_condition { if (ref $args->{condition} eq 'CODE') { - my ($crosstable_cond, $joinfree_cond) = $args->{condition}->({ + my $cref_args = { + rel_name => $args->{rel_name}, + self_resultsource => $self, self_alias => $args->{self_alias}, foreign_alias => $args->{foreign_alias}, - self_resultsource => $self, - foreign_relname => $args->{rel_name}, - self_rowobj => defined $args->{self_resultobj} ? $args->{self_resultobj} : undef, - }); + self_resultobj => defined $args->{self_resultobj} ? $args->{self_resultobj} : undef, + }; + + # legacy - never remove these!!! + $cref_args->{foreign_relname} = $cref_args->{rel_name}; + $cref_args->{self_rowobj} = $cref_args->{self_resultobj}; + + my ($crosstable_cond, $joinfree_cond) = $args->{condition}->($cref_args); my @nonvalue_cols; if ($joinfree_cond) { # FIXME sanity check until things stabilize, remove at some point $self->throw_exception ( - "A join-free condition returned for relationship '$args->{rel_name}' without a row-object to chain from" + "A join-free condition returned for relationship '$args->{rel_name}' without a result object to chain from" ) unless defined $args->{self_resultobj}; my $foreign_src_fq_col_list = { map { ( "$args->{foreign_alias}.$_" => 1 ) } $self->related_source($args->{rel_name})->columns }; diff --git a/t/lib/DBICTest/Util.pm b/t/lib/DBICTest/Util.pm index e7a0525..b821243 100644 --- a/t/lib/DBICTest/Util.pm +++ b/t/lib/DBICTest/Util.pm @@ -5,7 +5,7 @@ use strict; use Config; use Carp 'confess'; -use Scalar::Util 'blessed'; +use Scalar::Util qw(blessed refaddr); use base 'Exporter'; our @EXPORT_OK = qw(local_umask stacktrace check_customcond_args); @@ -52,20 +52,28 @@ sub check_customcond_args ($) { confess "Expecting a hashref" unless ref $args eq 'HASH'; - for (qw(foreign_relname self_alias foreign_alias)) { + for (qw(rel_name foreign_relname self_alias foreign_alias)) { confess "Custom condition argument '$_' must be a plain string" if length ref $args->{$_} or ! length $args->{$_}; } + confess "Current and legacy rel_name arguments do not match" + if $args->{rel_name} ne $args->{foreign_relname}; + confess "Custom condition argument 'self_resultsource' must be a rsrc instance" unless defined blessed $args->{self_resultsource} and $args->{self_resultsource}->isa('DBIx::Class::ResultSource'); confess "Passed resultsource has no record of the supplied rel_name - likely wrong \$rsrc" - unless ref $args->{self_resultsource}->relationship_info($args->{foreign_relname}); + unless ref $args->{self_resultsource}->relationship_info($args->{rel_name}); + + if (defined $args->{self_resultobj} or defined $args->{self_rowobj} ) { + for (qw(self_resultobj self_rowobj)) { + confess "Custom condition argument '$_' must be a result instance" + unless defined blessed $args->{$_} and $args->{$_}->isa('DBIx::Class::Row'); + } - if (defined $args->{self_rowobj}) { - confess "Custom condition argument 'self_rowobj' must be a result instance" - unless defined blessed $args->{self_rowobj} and $args->{self_rowobj}->isa('DBIx::Class::Row'); + confess "Current and legacy self_resultobj arguments do not match" + if refaddr($args->{self_resultobj}) != refaddr($args->{self_rowobj}); } $args;