<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package # hide from PAUSE
    DBIx::Class::Relationship::ProxyMethods;

use strict;
use warnings;
use Sub::Name ();
use base qw/DBIx::Class/;

our %_pod_inherit_config =
  (
   class_map =&gt; { 'DBIx::Class::Relationship::ProxyMethods' =&gt; 'DBIx::Class::Relationship' }
  );

sub register_relationship {
  my ($class, $rel, $info) = @_;
  if (my $proxy_args = $info-&gt;{attrs}{proxy}) {
    $class-&gt;proxy_to_related($rel, $proxy_args);
  }
  $class-&gt;next::method($rel, $info);
}

sub proxy_to_related {
  my ($class, $rel, $proxy_args) = @_;
  my %proxy_map = $class-&gt;_build_proxy_map_from($proxy_args);
  no strict 'refs';
  no warnings 'redefine';
  foreach my $meth_name ( keys %proxy_map ) {
    my $proxy_to_col = $proxy_map{$meth_name};
    my $name = join '::', $class, $meth_name;
    *$name = Sub::Name::subname $name =&gt; sub {
      my $self = shift;
      my $relobj = $self-&gt;$rel;
      if (@_ &amp;&amp; !defined $relobj) {
        $relobj = $self-&gt;create_related($rel, { $proxy_to_col =&gt; $_[0] });
        @_ = ();
      }
      return ($relobj ? $relobj-&gt;$proxy_to_col(@_) : undef);
   }
  }
}

sub _build_proxy_map_from {
  my ( $class, $proxy_arg ) = @_;
  my $ref = ref $proxy_arg;

  if ($ref eq 'HASH') {
    return %$proxy_arg;
  }
  elsif ($ref eq 'ARRAY') {
    return map {
      (ref $_ eq 'HASH')
        ? (%$_)
        : ($_ =&gt; $_)
    } @$proxy_arg;
  }
  elsif ($ref) {
    $class-&gt;throw_exception("Unable to process the 'proxy' argument $proxy_arg");
  }
  else {
    return ( $proxy_arg =&gt; $proxy_arg );
  }
}

1;
</pre></body></html>