X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRelationship%2FProxyMethods.pm;h=11e4879f50ce90eee0461fe37c64f108087d1772;hb=d52170d466537df84dc1d86c84d9cd5a8e58407a;hp=ede62a7e00952f76370da77aaa1daf4e0c60a5e0;hpb=b28cc0ba2d1d443728c9cb48d97e5a2cdccf8cb4;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Relationship/ProxyMethods.pm b/lib/DBIx/Class/Relationship/ProxyMethods.pm index ede62a7..11e4879 100644 --- a/lib/DBIx/Class/Relationship/ProxyMethods.pm +++ b/lib/DBIx/Class/Relationship/ProxyMethods.pm @@ -1,30 +1,36 @@ -package DBIx::Class::Relationship::ProxyMethods; +package # hide from PAUSE + DBIx::Class::Relationship::ProxyMethods; use strict; use warnings; -use base qw/Class::Data::Inheritable/; +use base qw/DBIx::Class/; -sub add_relationship { - my ($class, $rel, @rest) = @_; - my $ret = $class->NEXT::ACTUAL::add_relationship($rel => @rest); - if (my $proxy_list = $class->_relationships->{$rel}->{attrs}{proxy}) { - no strict 'refs'; - no warnings 'redefine'; - foreach my $proxy (ref $proxy_list ? @$proxy_list : $proxy_list) { - *{"${class}::${proxy}"} = - sub { - my $self = shift; - my $val = $self->$rel; - if (@_ && !defined $val) { - $val = $self->create_related($rel, { $proxy => $_[0] }); - @_ = (); - } - return ($val ? $val->$proxy(@_) : undef); - } - } +sub register_relationship { + my ($class, $rel, $info) = @_; + if (my $proxy_list = $info->{attrs}{proxy}) { + $class->proxy_to_related($rel, + (ref $proxy_list ? @$proxy_list : $proxy_list)); + } + $class->next::method($rel, $info); +} + +sub proxy_to_related { + my ($class, $rel, @proxy) = @_; + no strict 'refs'; + no warnings 'redefine'; + foreach my $proxy (@proxy) { + *{"${class}::${proxy}"} = + sub { + my $self = shift; + my $val = $self->$rel; + if (@_ && !defined $val) { + $val = $self->create_related($rel, { $proxy => $_[0] }); + @_ = (); + } + return ($val ? $val->$proxy(@_) : undef); + } } - return $ret; } 1;