1 package # hide from PAUSE
2 DBIx::Class::Relationship::ProxyMethods;
6 use base 'DBIx::Class';
7 use DBIx::Class::_Util 'quote_sub';
10 our %_pod_inherit_config =
12 class_map => { 'DBIx::Class::Relationship::ProxyMethods' => 'DBIx::Class::Relationship' }
15 sub register_relationship {
16 my ($class, $rel, $info) = @_;
17 if (my $proxy_args = $info->{attrs}{proxy}) {
18 $class->proxy_to_related($rel, $proxy_args);
20 $class->next::method($rel, $info);
23 sub proxy_to_related {
24 my ($class, $rel, $proxy_args) = @_;
25 my %proxy_map = $class->_build_proxy_map_from($proxy_args);
27 my @qsub_args = ( {}, {
29 DBIC_method_is_proxy_to_relationship
30 DBIC_method_is_generated_from_resultsource_metadata
34 quote_sub "${class}::$_", sprintf( <<'EOC', $rel, $proxy_map{$_} ), @qsub_args
36 my $relobj = $self->%1$s;
37 if (@_ && !defined $relobj) {
38 $relobj = $self->create_related( q{%1$s} => { %2$s => $_[0] } );
41 $relobj ? $relobj->%2$s(@_) : undef;
46 sub _build_proxy_map_from {
47 my ( $class, $proxy_arg ) = @_;
48 my $ref = ref $proxy_arg;
53 elsif ($ref eq 'ARRAY') {
61 $class->throw_exception("Unable to process the 'proxy' argument $proxy_arg");
64 return ( $proxy_arg => $proxy_arg );