From: Peter Rabbitson Date: Wed, 23 Jul 2014 23:29:46 +0000 (+0200) Subject: Change once more the signature of the custom cond coderef (augment a446d7f8) X-Git-Tag: v0.082800~118 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=98def3efbed614ff1514c79b9da7e03b5ceb06c0;p=dbsrgits%2FDBIx-Class.git Change once more the signature of the custom cond coderef (augment a446d7f8) Since there hasn't yet been a stable release with the new naming, and given I've already mistyped the long-form twice, might as well rename things and stay consistent. --- diff --git a/Changes b/Changes index 6dcba26..b05ea3d 100644 --- a/Changes +++ b/Changes @@ -7,9 +7,9 @@ Revision history for DBIx::Class returned from storage - Custom condition relationships are now invoked with a slightly different signature (existing coderefs will continue to work) - - Add extra custom condition coderef attribute 'foreign_resultobj' + - Add extra custom condition coderef attribute 'foreign_result_object' to allow for proper reverse-relationship emulation - (i.e. $result->set_from_related($custom_cond, $foreign_resultobj) + (i.e. $result->set_from_related($custom_rel, $foreign_result_object) - When in a transaction, DBIC::Ordered now seamlesly handles result objects that went out of sync with the storage (RT#96499) diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index ab7f33c..42d0955 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -184,7 +184,7 @@ While every coderef-based condition must return a valid C clause, it may elect to additionally return a simplified join-free condition hashref when invoked as C<< $result->relationship >>, as opposed to C<< $rs->related_resultset('relationship') >>. In this case C<$result> is -passed to the coderef as C<< $args->{self_resultobj} >>, so a user can do the +passed to the coderef as C<< $args->{self_result_object} >>, so a user can do the following: sub { @@ -195,8 +195,8 @@ following: "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, "$args->{foreign_alias}.year" => { '>', "1979", '<', "1990" }, }, - $args->{self_resultobj} && { - "$args->{foreign_alias}.artist" => $args->{self_resultobj}->artistid, + $args->{self_result_object} && { + "$args->{foreign_alias}.artist" => $args->{self_result_object}->artistid, "$args->{foreign_alias}.year" => { '>', "1979", '<', "1990" }, }, ); @@ -233,20 +233,20 @@ clause, the C<$args> hashref passed to the subroutine contains some extra metadata. Currently the supplied coderef is executed as: $relationship_info->{cond}->({ - self_resultsource => The resultsource instance on which rel_name is registered - rel_name => The relationship name (does *NOT* always match foreign_alias) + 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_alias => The alias of the invoking resultset + foreign_alias => The alias of the to-be-joined resultset (does *NOT* always match rel_name) # only one of these (or none at all) will ever be supplied to aid in the # construction of a join-free condition - self_resultobj => The invocant object itself in case of a $resultobj->$rel_name() call - foreign_resultobj => The related object in case of $resultobj->set_from_related($rel_name, $foreign_resultobj) + self_result_object => The invocant object itself in case of a $result_object->$rel_name( ... ) call + foreign_result_object => The related object in case of $result_object->set_from_related( $rel_name, $foreign_result_object ) # 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 + self_rowobj => Old deprecated slot for self_result_object + foreign_relname => Old deprecated slot for rel_name }); =head3 attributes @@ -636,7 +636,7 @@ sub new_related { return $self->search_related($rel)->new_result( $self->result_source->_resolve_relationship_condition ( infer_values_based_on => $data, rel_name => $rel, - self_resultobj => $self, + self_result_object => $self, foreign_alias => $rel, self_alias => 'me', )->{inferred_values} ); @@ -784,7 +784,7 @@ sub set_from_related { $self->set_columns( $self->result_source->_resolve_relationship_condition ( infer_values_based_on => {}, rel_name => $rel, - foreign_resultobj => $f_obj, + foreign_result_object => $f_obj, foreign_alias => $rel, self_alias => 'me', )->{inferred_values} ); diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 72edcbd..4f04be8 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -1717,8 +1717,8 @@ sub _resolve_condition { # where-is-waldo block guesses relname, then further down we override it if available ( - $is_objlike[1] ? ( rel_name => $res_args[0], self_alias => $res_args[0], foreign_alias => 'me', self_resultobj => $res_args[1] ) - : $is_objlike[0] ? ( rel_name => $res_args[1], self_alias => 'me', foreign_alias => $res_args[1], foreign_resultobj => $res_args[0] ) + $is_objlike[1] ? ( rel_name => $res_args[0], self_alias => $res_args[0], foreign_alias => 'me', self_result_object => $res_args[1] ) + : $is_objlike[0] ? ( rel_name => $res_args[1], self_alias => 'me', foreign_alias => $res_args[1], foreign_result_object => $res_args[0] ) : ( rel_name => $res_args[0], self_alias => $res_args[1], foreign_alias => $res_args[0] ) ), @@ -1762,9 +1762,9 @@ Internals::SvREADONLY($UNRESOLVABLE_CONDITION => 1); ## self-explanatory API, modeled on the custom cond coderef: # rel_name # foreign_alias -# foreign_resultobj +# foreign_result_object # self_alias -# self_resultobj +# self_result_object # require_join_free_condition # infer_values_based_on (optional, mandatory hashref argument) # condition (optional, derived from $self->rel_info(rel_name)) @@ -1794,7 +1794,7 @@ sub _resolve_relationship_condition { or $self->throw_exception( "No such $exception_rel_id" ); $self->throw_exception("No practical way to resolve $exception_rel_id between two data structures") - if defined $args->{self_resultobj} and defined $args->{foreign_resultobj}; + if defined $args->{self_result_object} and defined $args->{foreign_result_object}; $self->throw_exception( "Argument to infer_values_based_on must be a hash" ) if exists $args->{infer_values_based_on} and ref $args->{infer_values_based_on} ne 'HASH'; @@ -1803,28 +1803,28 @@ sub _resolve_relationship_condition { $args->{condition} ||= $rel_info->{cond}; - if (exists $args->{self_resultobj}) { - if (defined blessed $args->{self_resultobj}) { - $self->throw_exception( "Object '$args->{self_resultobj}' must be of class '@{[ $self->result_class ]}'" ) - unless $args->{self_resultobj}->isa($self->result_class); + if (exists $args->{self_result_object}) { + if (defined blessed $args->{self_result_object}) { + $self->throw_exception( "Object '$args->{self_result_object}' must be of class '@{[ $self->result_class ]}'" ) + unless $args->{self_result_object}->isa($self->result_class); } else { - $args->{self_resultobj} = DBIx::Class::Core->new({ + $args->{self_result_object} = DBIx::Class::Core->new({ -result_source => $self, - %{ $args->{self_resultobj}||{} } + %{ $args->{self_result_object}||{} } }); } } - if (exists $args->{foreign_resultobj}) { - if (defined blessed $args->{foreign_resultobj}) { - $self->throw_exception( "Object '$args->{foreign_resultobj}' must be of class '$rel_info->{class}'" ) - unless $args->{foreign_resultobj}->isa($rel_info->{class}); + if (exists $args->{foreign_result_object}) { + if (defined blessed $args->{foreign_result_object}) { + $self->throw_exception( "Object '$args->{foreign_result_object}' must be of class '$rel_info->{class}'" ) + unless $args->{foreign_result_object}->isa($rel_info->{class}); } else { - $args->{foreign_resultobj} = DBIx::Class::Core->new({ + $args->{foreign_result_object} = DBIx::Class::Core->new({ -result_source => $self->related_source($args->{rel_name}), - %{ $args->{foreign_resultobj}||{} } + %{ $args->{foreign_result_object}||{} } }); } } @@ -1840,15 +1840,15 @@ sub _resolve_relationship_condition { foreign_alias => $args->{foreign_alias}, ( map { (exists $args->{$_}) ? ( $_ => $args->{$_} ) : () } - qw( self_resultobj foreign_resultobj ) + qw( self_result_object foreign_result_object ) ), }; # legacy - never remove these!!! $cref_args->{foreign_relname} = $cref_args->{rel_name}; - $cref_args->{self_rowobj} = $cref_args->{self_resultobj} - if exists $cref_args->{self_resultobj}; + $cref_args->{self_rowobj} = $cref_args->{self_result_object} + if exists $cref_args->{self_result_object}; ($ret->{condition}, $ret->{join_free_condition}, my @extra) = $args->{condition}->($cref_args); @@ -1863,11 +1863,11 @@ sub _resolve_relationship_condition { ) unless ref $jfc eq 'HASH'; my ($joinfree_alias, $joinfree_source); - if (defined $args->{self_resultobj}) { + if (defined $args->{self_result_object}) { $joinfree_alias = $args->{foreign_alias}; $joinfree_source = $self->related_source($args->{rel_name}); } - elsif (defined $args->{foreign_resultobj}) { + elsif (defined $args->{foreign_result_object}) { $joinfree_alias = $args->{self_alias}; $joinfree_source = $self; } @@ -1915,17 +1915,17 @@ sub _resolve_relationship_condition { $ret->{identity_map}{$l_cols[$_]} = $f_cols[$_]; }; - if (exists $args->{self_resultobj} or exists $args->{foreign_resultobj}) { + if (exists $args->{self_result_object} or exists $args->{foreign_result_object}) { - my ($obj, $obj_alias, $plain_alias, $obj_cols, $plain_cols) = defined $args->{self_resultobj} - ? ( @{$args}{qw( self_resultobj self_alias foreign_alias )}, \@l_cols, \@f_cols ) - : ( @{$args}{qw( foreign_resultobj foreign_alias self_alias )}, \@f_cols, \@l_cols ) + my ($obj, $obj_alias, $plain_alias, $obj_cols, $plain_cols) = defined $args->{self_result_object} + ? ( @{$args}{qw( self_result_object self_alias foreign_alias )}, \@l_cols, \@f_cols ) + : ( @{$args}{qw( foreign_result_object foreign_alias self_alias )}, \@f_cols, \@l_cols ) ; for my $i (0..$#$obj_cols) { if ( - defined $args->{self_resultobj} + defined $args->{self_result_object} and ! $obj->has_column_loaded($obj_cols->[$i]) ) { diff --git a/t/lib/DBICTest/Schema/Artist.pm b/t/lib/DBICTest/Schema/Artist.pm index 470796a..8087292 100644 --- a/t/lib/DBICTest/Schema/Artist.pm +++ b/t/lib/DBICTest/Schema/Artist.pm @@ -62,8 +62,8 @@ __PACKAGE__->has_many( return ( { "$args->{foreign_alias}.artist" => { '=' => { -ident => "$args->{self_alias}.artistid"} }, }, - $args->{self_resultobj} && { - "$args->{foreign_alias}.artist" => $args->{self_resultobj}->artistid, + $args->{self_result_object} && { + "$args->{foreign_alias}.artist" => $args->{self_rowobj}->artistid, # keep old rowobj syntax as a test } ); }, @@ -81,8 +81,8 @@ __PACKAGE__->has_many( { "$args->{foreign_alias}.artist" => { '=' => \ "$args->{self_alias}.artistid" }, "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, }, - $args->{self_resultobj} && { - "$args->{foreign_alias}.artist" => { '=' => \[ '?', $args->{self_resultobj}->artistid ] }, + $args->{self_result_object} && { + "$args->{foreign_alias}.artist" => { '=' => \[ '?', $args->{self_result_object}->artistid ] }, "$args->{foreign_alias}.year" => { '>' => 1979, '<' => 1990 }, } ); @@ -102,8 +102,8 @@ __PACKAGE__->has_many( { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, "$args->{foreign_alias}.year" => 1984, }, - $args->{self_resultobj} && { - "$args->{foreign_alias}.artist" => $args->{self_resultobj}->artistid, + $args->{self_result_object} && { + "$args->{foreign_alias}.artist" => $args->{self_result_object}->artistid, "$args->{foreign_alias}.year" => 1984, } ); @@ -161,8 +161,8 @@ __PACKAGE__->has_many( { "$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" }, "$args->{foreign_alias}.genreid" => undef, - }, $args->{self_resultobj} && { - "$args->{foreign_alias}.artist" => $args->{self_resultobj}->artistid, + }, $args->{self_result_object} && { + "$args->{foreign_alias}.artist" => $args->{self_result_object}->artistid, "$args->{foreign_alias}.genreid" => undef, } ), diff --git a/t/lib/DBICTest/Schema/Artwork.pm b/t/lib/DBICTest/Schema/Artwork.pm index d9ddc33..ddc87cd 100644 --- a/t/lib/DBICTest/Schema/Artwork.pm +++ b/t/lib/DBICTest/Schema/Artwork.pm @@ -36,8 +36,8 @@ __PACKAGE__->has_many('artwork_to_artist_test_m2m', 'DBICTest::Schema::Artwork_t return ( { "$args->{foreign_alias}.artwork_cd_id" => { -ident => "$args->{self_alias}.cd_id" }, }, - $args->{self_resultobj} && { - "$args->{foreign_alias}.artwork_cd_id" => $args->{self_resultobj}->cd_id, + $args->{self_result_object} && { + "$args->{foreign_alias}.artwork_cd_id" => $args->{self_result_object}->cd_id, } ); } diff --git a/t/lib/DBICTest/Schema/Artwork_to_Artist.pm b/t/lib/DBICTest/Schema/Artwork_to_Artist.pm index e4c4cf2..8a33928 100644 --- a/t/lib/DBICTest/Schema/Artwork_to_Artist.pm +++ b/t/lib/DBICTest/Schema/Artwork_to_Artist.pm @@ -33,8 +33,8 @@ __PACKAGE__->belongs_to('artist_test_m2m', 'DBICTest::Schema::Artist', { "$args->{foreign_alias}.artistid" => { -ident => "$args->{self_alias}.artist_id" }, "$args->{foreign_alias}.rank" => { '<' => 10 }, }, - $args->{self_resultobj} && { - "$args->{foreign_alias}.artistid" => $args->{self_resultobj}->artist_id, + $args->{self_result_object} && { + "$args->{foreign_alias}.artistid" => $args->{self_result_object}->artist_id, "$args->{foreign_alias}.rank" => { '<' => 10 }, } ); diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index a1cb27a..a466c39 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -66,12 +66,12 @@ sub { "$args->{foreign_alias}.cdid" => { -ident => "$args->{self_alias}.cd" }, }, - ( $args->{self_resultobj} ? { - "$args->{foreign_alias}.cdid" => $args->{self_resultobj}->cd + ( $args->{self_result_object} ? { + "$args->{foreign_alias}.cdid" => $args->{self_result_object}->cd } : () ), - ( $args->{foreign_resultobj} ? { - "$args->{self_alias}.cd" => $args->{foreign_resultobj}->cdid + ( $args->{foreign_result_object} ? { + "$args->{self_alias}.cd" => $args->{foreign_result_object}->cdid } : () ), ); } @@ -108,9 +108,9 @@ __PACKAGE__->has_many ( { "$args->{foreign_alias}.cd" => { -ident => "$args->{self_alias}.cd" }, "$args->{foreign_alias}.position" => { '>' => { -ident => "$args->{self_alias}.position" } }, }, - $args->{self_resultobj} && { - "$args->{foreign_alias}.cd" => $args->{self_resultobj}->get_column('cd'), - "$args->{foreign_alias}.position" => { '>' => $args->{self_resultobj}->pos }, + $args->{self_result_object} && { + "$args->{foreign_alias}.cd" => $args->{self_result_object}->get_column('cd'), + "$args->{foreign_alias}.position" => { '>' => $args->{self_result_object}->pos }, } ) } diff --git a/t/lib/DBICTest/Util.pm b/t/lib/DBICTest/Util.pm index a6c8dfd..0588a9d 100644 --- a/t/lib/DBICTest/Util.pm +++ b/t/lib/DBICTest/Util.pm @@ -101,22 +101,22 @@ sub check_customcond_args ($) { my $rowobj_cnt = 0; - if (defined $args->{self_resultobj} or defined $args->{self_rowobj} ) { + if (defined $args->{self_result_object} or defined $args->{self_rowobj} ) { $rowobj_cnt++; - for (qw(self_resultobj self_rowobj)) { + for (qw(self_result_object self_rowobj)) { confess "Custom condition argument '$_' must be a result instance" unless defined blessed $args->{$_} and $args->{$_}->isa('DBIx::Class::Row'); } - confess "Current and legacy self_resultobj arguments do not match" - if refaddr($args->{self_resultobj}) != refaddr($args->{self_rowobj}); + confess "Current and legacy self_result_object arguments do not match" + if refaddr($args->{self_result_object}) != refaddr($args->{self_rowobj}); } - if (defined $args->{foreign_resultobj}) { + if (defined $args->{foreign_result_object}) { $rowobj_cnt++; - confess "Custom condition argument 'foreign_resultobj' must be a result instance" - unless defined blessed $args->{foreign_resultobj} and $args->{foreign_resultobj}->isa('DBIx::Class::Row'); + confess "Custom condition argument 'foreign_result_object' must be a result instance" + unless defined blessed $args->{foreign_result_object} and $args->{foreign_result_object}->isa('DBIx::Class::Row'); } confess "Result objects supplied on both ends of a relationship"