Corrected columns_info_for indent level - 2 space indent everyone please, you may...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Relationship / ProxyMethods.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE
2 DBIx::Class::Relationship::ProxyMethods;
b28cc0ba 3
4use strict;
5use warnings;
6
1edd1722 7use base qw/DBIx::Class/;
b28cc0ba 8
71e65b39 9sub register_relationship {
10 my ($class, $rel, $info) = @_;
11 if (my $proxy_list = $info->{attrs}{proxy}) {
223b8fe3 12 $class->proxy_to_related($rel,
13 (ref $proxy_list ? @$proxy_list : $proxy_list));
b28cc0ba 14 }
71e65b39 15 $class->next::method($rel, $info);
b28cc0ba 16}
17
223b8fe3 18sub proxy_to_related {
19 my ($class, $rel, @proxy) = @_;
20 no strict 'refs';
21 no warnings 'redefine';
22 foreach my $proxy (@proxy) {
23 *{"${class}::${proxy}"} =
24 sub {
25 my $self = shift;
26 my $val = $self->$rel;
27 if (@_ && !defined $val) {
28 $val = $self->create_related($rel, { $proxy => $_[0] });
29 @_ = ();
30 }
31 return ($val ? $val->$proxy(@_) : undef);
32 }
33 }
34}
35
b28cc0ba 361;