X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRelationship%2FManyToMany.pm;h=76042c0d68bf9068da62a59c1146964ad8808ad5;hp=451e43501b18ba99678e0b1685f00f6c64dd9455;hb=ddc0a6c89d212433eb5716b2aa963f63b1f348d1;hpb=c959e8d06362537fbc865d703786b399d0806212 diff --git a/lib/DBIx/Class/Relationship/ManyToMany.pm b/lib/DBIx/Class/Relationship/ManyToMany.pm index 451e435..76042c0 100644 --- a/lib/DBIx/Class/Relationship/ManyToMany.pm +++ b/lib/DBIx/Class/Relationship/ManyToMany.pm @@ -3,6 +3,7 @@ package # hide from PAUSE use strict; use warnings; +use Sub::Name (); sub many_to_many { my ($class, $meth, $rel, $f_rel, $rel_attrs) = @_; @@ -33,7 +34,8 @@ sub many_to_many { $rel_attrs->{alias} ||= $f_rel; - *{"${class}::${meth}_rs"} = sub { + my $rs_meth_name = join '::', $class, $rs_meth; + *$rs_meth_name = Sub::Name::subname $rs_meth_name, sub { my $self = shift; my $attrs = @_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {}; my @args = ($f_rel, @_ > 0 ? @_ : undef, { %{$rel_attrs||{}}, %$attrs }); @@ -43,13 +45,15 @@ sub many_to_many { return $rs; }; - *{"${class}::${meth}"} = sub { + my $meth_name = join '::', $class, $meth; + *$meth_name = Sub::Name::subname $meth_name, sub { my $self = shift; my $rs = $self->$rs_meth( @_ ); return (wantarray ? $rs->all : $rs); }; - *{"${class}::${add_meth}"} = sub { + my $add_meth_name = join '::', $class, $add_meth; + *$add_meth_name = Sub::Name::subname $add_meth_name, sub { my $self = shift; @_ > 0 or $self->throw_exception( "${add_meth} needs an object or hashref" @@ -79,7 +83,8 @@ sub many_to_many { return $obj; }; - *{"${class}::${set_meth}"} = sub { + my $set_meth_name = join '::', $class, $set_meth; + *$set_meth_name = Sub::Name::subname $set_meth_name, sub { my $self = shift; @_ > 0 or $self->throw_exception( "{$set_meth} needs a list of objects or hashrefs" @@ -89,7 +94,8 @@ sub many_to_many { $self->$add_meth($_) for (@to_set); }; - *{"${class}::${remove_meth}"} = sub { + my $remove_meth_name = join '::', $class, $remove_meth; + *$remove_meth_name = Sub::Name::subname $remove_meth_name, sub { my $self = shift; @_ > 0 && ref $_[0] ne 'HASH' or $self->throw_exception("${remove_meth} needs an object");