X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FRelationships.pm;h=ecbc5c2d9570f6299d2332a949324fc8a3daa7ac;hb=09d8fb4a05e6cd025924cc08e41484f17a116695;hp=be7b5bf13f3b0f8df84938bd23b630b9da29755e;hpb=a2bd379666d729133d65c85dc775627937084b18;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/Relationships.pm b/lib/DBIx/Class/CDBICompat/Relationships.pm index be7b5bf..ecbc5c2 100644 --- a/lib/DBIx/Class/CDBICompat/Relationships.pm +++ b/lib/DBIx/Class/CDBICompat/Relationships.pm @@ -3,11 +3,13 @@ package # hide from PAUSE use strict; use warnings; -use base 'Class::Data::Inheritable'; +use base 'DBIx::Class'; use Clone; use DBIx::Class::CDBICompat::Relationship; +use Scalar::Util 'blessed'; use DBIx::Class::_Util qw(quote_sub perlstring); +use namespace::clean; __PACKAGE__->mk_classdata('__meta_info' => {}); @@ -64,7 +66,7 @@ sub _declare_has_a { } else { $self->belongs_to($col, $f_class); - $rel_info = $self->result_source_instance->relationship_info($col); + $rel_info = $self->result_source->relationship_info($col); } $rel_info->{args} = \%args; @@ -108,14 +110,14 @@ sub has_many { if( !$f_key and !@f_method ) { $class->ensure_class_loaded($f_class); - my $f_source = $f_class->result_source_instance; + my $f_source = $f_class->result_source; ($f_key) = grep { $f_source->relationship_info($_)->{class} eq $class } $f_source->relationships; } $class->next::method($rel, $f_class, $f_key, $args); - my $rel_info = $class->result_source_instance->relationship_info($rel); + my $rel_info = $class->result_source->relationship_info($rel); $args->{mapping} = \@f_method; $args->{foreign_key} = $f_key; $rel_info->{args} = $args; @@ -126,8 +128,13 @@ sub has_many { ); if (@f_method) { - quote_sub "${class}::${rel}", sprintf( <<'EOC', perlstring $rel), { '$rf' => \sub { my $o = shift; $o = $o->$_ for @f_method; $o } }; - my $rs = shift->search_related( %s => @_); + my @qsub_args = ( + { '$rf' => \sub { my $o = shift; $o = $o->$_ for @f_method; $o } }, + { attributes => [ 'DBIC_method_is_generated_from_resultsource_metadata' ] }, + ); + + quote_sub "${class}::${rel}", sprintf( <<'EOC', perlstring $rel), @qsub_args; + my $rs = shift->related_resultset(%s)->search_rs( @_); $rs->{attrs}{record_filter} = $rf; return (wantarray ? $rs->all : $rs); EOC @@ -148,7 +155,7 @@ sub might_have { { proxy => \@columns }); } - my $rel_info = $class->result_source_instance->relationship_info($rel); + my $rel_info = $class->result_source->relationship_info($rel); $rel_info->{args}{import} = \@columns; $class->_extend_meta( @@ -162,14 +169,19 @@ sub might_have { sub _extend_meta { my ($class, $type, $rel, $val) = @_; - my %hash = %{ Clone::clone($class->__meta_info || {}) }; + +### Explicitly not using the deep cloner as Clone exhibits specific behavior +### wrt CODE references - it simply passes them as-is to the new structure +### (without deparse/eval cycles). There likely is code that relies on this +### so we just let sleeping dogs lie. + my $hash = Clone::clone($class->__meta_info || {}); $val->{self_class} = $class; $val->{type} = $type; $val->{accessor} = $rel; - $hash{$type}{$rel} = DBIx::Class::CDBICompat::Relationship->new($val); - $class->__meta_info(\%hash); + $hash->{$type}{$rel} = DBIx::Class::CDBICompat::Relationship->new($val); + $class->__meta_info($hash); } @@ -195,15 +207,18 @@ sub search { : undef()); if (ref $where eq 'HASH') { foreach my $key (keys %$where) { # has_a deflation hack - $where->{$key} = ''.$where->{$key} - if eval { $where->{$key}->isa('DBIx::Class') }; + $where->{$key} = ''.$where->{$key} if ( + defined blessed $where->{$key} + and + $where->{$key}->isa('DBIx::Class') + ); } } $self->next::method($where, $attrs); } sub new_related { - return shift->search_related(shift)->new_result(shift); + return shift->search_related(shift)->new_result(@_); } =head1 FURTHER QUESTIONS?