From: Peter Rabbitson Date: Tue, 19 May 2009 17:34:19 +0000 (+0000) Subject: Hide resultsource methods that should have never been documented X-Git-Tag: v0.08103~64^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6d0ee587eb31c41e28a432de3caf261a66b4c2ca;p=dbsrgits%2FDBIx-Class.git Hide resultsource methods that should have never been documented --- diff --git a/lib/DBIx/Class/CDBICompat/ImaDBI.pm b/lib/DBIx/Class/CDBICompat/ImaDBI.pm index 7a3b4f0..db844e8 100644 --- a/lib/DBIx/Class/CDBICompat/ImaDBI.pm +++ b/lib/DBIx/Class/CDBICompat/ImaDBI.pm @@ -55,7 +55,7 @@ __PACKAGE__->mk_classdata('_transform_sql_handlers' => $self->throw_exception( "No relationship to JOIN from ${from_class} to ${to_class}" ) unless $rel_obj; my $join = $from_class->storage->sql_maker->_join_condition( - $from_class->result_source_instance->resolve_condition( + $from_class->result_source_instance->_resolve_condition( $rel_obj->{cond}, $to, $from) ); return $join; } diff --git a/lib/DBIx/Class/Relationship/Accessor.pm b/lib/DBIx/Class/Relationship/Accessor.pm index 065cf69..c10d4e4 100644 --- a/lib/DBIx/Class/Relationship/Accessor.pm +++ b/lib/DBIx/Class/Relationship/Accessor.pm @@ -27,7 +27,7 @@ sub add_relationship_accessor { } elsif (exists $self->{_relationship_data}{$rel}) { return $self->{_relationship_data}{$rel}; } else { - my $cond = $self->result_source->resolve_condition( + my $cond = $self->result_source->_resolve_condition( $rel_info->{cond}, $rel, $self ); if ($rel_info->{attrs}->{undef_on_null_fk}){ diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 64ae001..8c2e4fd 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -189,7 +189,7 @@ sub related_resultset { my $query = ((@_ > 1) ? {@_} : shift); my $source = $self->result_source; - my $cond = $source->resolve_condition( + my $cond = $source->_resolve_condition( $rel_obj->{cond}, $rel, $self ); if ($cond eq $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION) { @@ -404,7 +404,7 @@ sub set_from_related { unless Scalar::Util::blessed($f_obj) and $f_obj->isa($f_class); } $self->set_columns( - $self->result_source->resolve_condition( + $self->result_source->_resolve_condition( $rel_obj->{cond}, $f_obj, $rel)); return 1; } diff --git a/lib/DBIx/Class/Relationship/ManyToMany.pm b/lib/DBIx/Class/Relationship/ManyToMany.pm index 06c862d..e953a44 100644 --- a/lib/DBIx/Class/Relationship/ManyToMany.pm +++ b/lib/DBIx/Class/Relationship/ManyToMany.pm @@ -119,7 +119,7 @@ EOW my $obj = shift; my $rel_source = $self->search_related($rel)->result_source; my $cond = $rel_source->relationship_info($f_rel)->{cond}; - my $link_cond = $rel_source->resolve_condition( + my $link_cond = $rel_source->_resolve_condition( $cond, $obj, $f_rel ); $self->search_related($rel, $link_cond)->delete; diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 42b100a..e0bd00b 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -505,7 +505,7 @@ sub find { && ($info = $self->result_source->relationship_info($key))) { my $val = delete $input_query->{$key}; next KEY if (ref($val) eq 'ARRAY'); # has_many for multi_create - my $rel_q = $self->result_source->resolve_condition( + my $rel_q = $self->result_source->_resolve_condition( $info->{cond}, $val, $key ); die "Can't handle OR join condition in find" if ref($rel_q) eq 'ARRAY'; @@ -1626,7 +1626,7 @@ sub populate { next unless $data->[$index]->{$rel} && ref $data->[$index]->{$rel} eq "HASH"; my $result = $self->related_resultset($rel)->create($data->[$index]->{$rel}); my ($reverse) = keys %{$self->result_source->reverse_relationship_info($rel)}; - my $related = $result->result_source->resolve_condition( + my $related = $result->result_source->_resolve_condition( $result->result_source->relationship_info($reverse)->{cond}, $self, $result, @@ -1659,7 +1659,7 @@ sub populate { my $child = $parent->$rel; - my $related = $child->result_source->resolve_condition( + my $related = $child->result_source->_resolve_condition( $parent->result_source->relationship_info($rel)->{cond}, $child, $parent, @@ -2446,14 +2446,14 @@ sub _resolve_from { my $seen = { %{$attrs->{seen_join}||{}} }; # we need to take the prefetch the attrs into account before we - # ->resolve_join as otherwise they get lost - captainL + # ->_resolve_join as otherwise they get lost - captainL my $merged = $self->_merge_attr( $attrs->{join}, $attrs->{prefetch} ); - push @$from, $source->resolve_join($merged, $attrs->{alias}, $seen) if ($merged); + push @$from, $source->_resolve_join($merged, $attrs->{alias}, $seen) if ($merged); ++$seen->{-relation_chain_depth}; - push @$from, $source->resolve_join($extra_join, $attrs->{alias}, $seen); + push @$from, $source->_resolve_join($extra_join, $attrs->{alias}, $seen); ++$seen->{-relation_chain_depth}; @@ -2553,7 +2553,7 @@ sub _resolved_attrs { $attrs->{from} = # have to copy here to avoid corrupting the original [ @{ $attrs->{from} }, - $source->resolve_join( + $source->_resolve_join( $join, $alias, { %{ $attrs->{seen_join} || {} } } ) ]; @@ -2582,7 +2582,7 @@ sub _resolved_attrs { # bring joins back to level of current class my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join}); my @prefetch = - $source->resolve_prefetch( $p, $alias, $join_map, \@pre_order, $collapse ); + $source->_resolve_prefetch( $p, $alias, $join_map, \@pre_order, $collapse ); push( @{ $attrs->{select} }, map { $_->[0] } @prefetch ); push( @{ $attrs->{as} }, map { $_->[1] } @prefetch ); } diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 97e45fa..1ef8dce 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -841,7 +841,7 @@ relationship. =back Throws an exception if the condition is improperly supplied, or cannot -be resolved using L. +be resolved. =cut @@ -881,7 +881,7 @@ sub add_relationship { } return unless $f_source; # Can't test rel without f_source - eval { $self->resolve_join($rel, 'me') }; + eval { $self->_resolve_join($rel, 'me') }; if ($@) { # If the resolve failed, back out and re-throw the error delete $rels{$rel}; # @@ -1015,29 +1015,22 @@ sub reverse_relationship_info { my @other_cond = keys(%$othercond); my @other_refkeys = map {/^\w+\.(\w+)$/} @other_cond; my @other_keys = map {$othercond->{$_} =~ /^\w+\.(\w+)$/} @other_cond; - next if (!$self->compare_relationship_keys(\@refkeys, \@other_keys) || - !$self->compare_relationship_keys(\@other_refkeys, \@keys)); + next if (!$self->_compare_relationship_keys(\@refkeys, \@other_keys) || + !$self->_compare_relationship_keys(\@other_refkeys, \@keys)); $ret->{$otherrel} = $otherrel_info; } } return $ret; } -=head2 compare_relationship_keys - -=over 4 - -=item Arguments: \@keys1, \@keys2 - -=item Return value: 1/0 (true/false) - -=back - -Returns true if both sets of keynames are the same, false otherwise. - -=cut - sub compare_relationship_keys { + carp 'compare_relationship_keys is a private method, stop calling it'; + my $self = shift; + $self->_compare_relationship_keys (@_); +} + +# Returns true if both sets of keynames are the same, false otherwise. +sub _compare_relationship_keys { my ($self, $keys1, $keys2) = @_; # Make sure every keys1 is in keys2 @@ -1070,25 +1063,18 @@ sub compare_relationship_keys { return $found; } -=head2 resolve_join - -=over 4 - -=item Arguments: $relation - -=item Return value: Join condition arrayref - -=back - -Returns the join structure required for the related result source. - -=cut - sub resolve_join { + carp 'resolve_join is a private method, stop calling it'; + my $self = shift; + $self->_resolve_join (@_); +} + +# Returns the {from} structure used to express JOIN conditions +sub _resolve_join { my ($self, $join, $alias, $seen, $force_left, $jpath) = @_; # we need a supplied one, because we do in-place modifications, no returns - $self->throw_exception ('You must supply a seen hashref as the 3rd argument to resolve_join') + $self->throw_exception ('You must supply a seen hashref as the 3rd argument to _resolve_join') unless $seen; $force_left ||= { force => 0 }; @@ -1104,7 +1090,7 @@ sub resolve_join { return map { local $force_left->{force} = $force_left->{force}; - $self->resolve_join($_, $alias, $seen, $force_left, [@$jpath]); + $self->_resolve_join($_, $alias, $seen, $force_left, [@$jpath]); } @$join; } elsif (ref $join eq 'HASH') { return @@ -1112,8 +1098,8 @@ sub resolve_join { my $as = ($seen->{$_} ? join ('_', $_, $seen->{$_} + 1) : $_); # the actual seen value will be incremented below local $force_left->{force} = $force_left->{force}; ( - $self->resolve_join($_, $alias, $seen, $force_left, [@$jpath]), - $self->related_source($_)->resolve_join( + $self->_resolve_join($_, $alias, $seen, $force_left, [@$jpath]), + $self->related_source($_)->_resolve_join( $join->{$_}, $as, $seen, $force_left, [@$jpath, $_] ) ); @@ -1140,27 +1126,20 @@ sub resolve_join { -join_alias => $as, -relation_chain_depth => $seen->{-relation_chain_depth} || 0, }, - $self->resolve_condition($rel_info->{cond}, $as, $alias) ]; + $self->_resolve_condition($rel_info->{cond}, $as, $alias) ]; } } -=head2 pk_depends_on - -=over 4 - -=item Arguments: $relname, $rel_data - -=item Return value: 1/0 (true/false) - -=back - -Determines whether a relation is dependent on an object from this source -having already been inserted. Takes the name of the relationship and a -hashref of columns of the related object. - -=cut - sub pk_depends_on { + carp 'pk_depends_on is a private method, stop calling it'; + my $self = shift; + $self->_pk_depends_on (@_); +} + +# Determines whether a relation is dependent on an object from this source +# having already been inserted. Takes the name of the relationship and a +# hashref of columns of the related object. +sub _pk_depends_on { my ($self, $relname, $rel_data) = @_; my $cond = $self->relationship_info($relname)->{cond}; @@ -1189,23 +1168,18 @@ sub pk_depends_on { return 1; } -=head2 resolve_condition - -=over 4 - -=item Arguments: $cond, $as, $alias|$object - -=back - -Resolves the passed condition to a concrete query fragment. If given an alias, -returns a join condition; if given an object, inverts that object to produce -a related conditional from that object. - -=cut +sub resolve_condition { + carp 'resolve_condition is a private method, stop calling it'; + my $self = shift; + $self->_resolve_condition (@_); +} +# Resolves the passed condition to a concrete query fragment. If given an alias, +# returns a join condition; if given an object, inverts that object to produce +# a related conditional from that object. our $UNRESOLVABLE_CONDITION = \'1 = 0'; -sub resolve_condition { +sub _resolve_condition { my ($self, $cond, $as, $for) = @_; #warn %$cond; if (ref $cond eq 'HASH') { @@ -1246,75 +1220,38 @@ sub resolve_condition { } return \%ret; } elsif (ref $cond eq 'ARRAY') { - return [ map { $self->resolve_condition($_, $as, $for) } @$cond ]; + return [ map { $self->_resolve_condition($_, $as, $for) } @$cond ]; } else { die("Can't handle this yet :("); } } -=head2 resolve_prefetch - -=over 4 - -=item Arguments: hashref/arrayref/scalar - -=back - -Accepts one or more relationships for the current source and returns an -array of column names for each of those relationships. Column names are -prefixed relative to the current source, in accordance with where they appear -in the supplied relationships. Examples: - - my $source = $schema->resultset('Tag')->source; - @columns = $source->resolve_prefetch( { cd => 'artist' } ); - - # @columns = - #( - # 'cd.cdid', - # 'cd.artist', - # 'cd.title', - # 'cd.year', - # 'cd.artist.artistid', - # 'cd.artist.name' - #) - - @columns = $source->resolve_prefetch( qw[/ cd /] ); - - # @columns = - #( - # 'cd.cdid', - # 'cd.artist', - # 'cd.title', - # 'cd.year' - #) - - $source = $schema->resultset('CD')->source; - @columns = $source->resolve_prefetch( qw[/ artist producer /] ); - - # @columns = - #( - # 'artist.artistid', - # 'artist.name', - # 'producer.producerid', - # 'producer.name' - #) +sub resolve_prefetch { + carp 'resolve_prefetch is a private method, stop calling it'; + my $self = shift; + $self->_resolve_prefetch (@_); +} -=cut +# Accepts one or more relationships for the current source and returns an +# array of column names for each of those relationships. Column names are +# prefixed relative to the current source, in accordance with where they appear +# in the supplied relationships. Needs an alias_map generated by +# $rs->_joinpath_aliases -sub resolve_prefetch { +sub _resolve_prefetch { my ($self, $pre, $alias, $alias_map, $order, $collapse, $pref_path) = @_; $pref_path ||= []; if( ref $pre eq 'ARRAY' ) { return - map { $self->resolve_prefetch( $_, $alias, $alias_map, $order, $collapse, [ @$pref_path ] ) } + map { $self->_resolve_prefetch( $_, $alias, $alias_map, $order, $collapse, [ @$pref_path ] ) } @$pre; } elsif( ref $pre eq 'HASH' ) { my @ret = map { - $self->resolve_prefetch($_, $alias, $alias_map, $order, $collapse, [ @$pref_path ] ), - $self->related_source($_)->resolve_prefetch( + $self->_resolve_prefetch($_, $alias, $alias_map, $order, $collapse, [ @$pref_path ] ), + $self->related_source($_)->_resolve_prefetch( $pre->{$_}, "${alias}.$_", $alias_map, $order, $collapse, [ @$pref_path, $_] ) } keys %$pre; return @ret; diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index da7ab36..c08c00d 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -112,7 +112,7 @@ sub __new_related_find_or_new_helper { ->resultset ->new_result($data); } - if ($self->result_source->pk_depends_on($relname, $data)) { + if ($self->result_source->_pk_depends_on($relname, $data)) { MULTICREATE_DEBUG and warn "MC $self constructing $relname via find_or_new"; return $self->result_source ->related_source($relname) @@ -132,7 +132,7 @@ sub __their_pk_needs_us { # this should maybe be in resultsource. foreach my $key (keys %$reverse) { # if their primary key depends on us, then we have to # just create a result and we'll fill it out afterwards - return 1 if $rel_source->pk_depends_on($key, $us); + return 1 if $rel_source->_pk_depends_on($key, $us); } return 0; } @@ -304,7 +304,7 @@ sub insert { next REL unless (Scalar::Util::blessed($rel_obj) && $rel_obj->isa('DBIx::Class::Row')); - next REL unless $source->pk_depends_on( + next REL unless $source->_pk_depends_on( $relname, { $rel_obj->get_columns } ); @@ -913,7 +913,7 @@ sub copy { next unless $rel_info->{attrs}{cascade_copy}; - my $resolved = $self->result_source->resolve_condition( + my $resolved = $self->result_source->_resolve_condition( $rel_info->{cond}, $rel, $new ); diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 58db779..97e333c 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -113,7 +113,7 @@ sub parse { my @primary = $source->primary_columns; my %unique_constraints = $source->unique_constraints; foreach my $uniq (sort keys %unique_constraints) { - if (!$source->compare_relationship_keys($unique_constraints{$uniq}, \@primary)) { + if (!$source->_compare_relationship_keys($unique_constraints{$uniq}, \@primary)) { $table->add_constraint( type => 'unique', name => $uniq, @@ -167,7 +167,7 @@ sub parse { # this is supposed to indicate a has_one/might_have... # where's the introspection!!?? :) else { - $fk_constraint = not $source->compare_relationship_keys(\@keys, \@primary); + $fk_constraint = not $source->_compare_relationship_keys(\@keys, \@primary); } my $cascade;