1package IntrospectM2M;
2
3use strict;
4use warnings;
5use base 'DBIx::Class';
6
7__PACKAGE__->mk_classdata( _m2m_metadata => {} );
8
9sub many_to_many {
10  my $class = shift;
11  my ($meth_name, $link, $far_side) = @_;
12  my $store = $class->_m2m_metadata;
13  die "You are overwritting another relationship's metadata"
14    if exists $store->{$meth_name};
15
16  my $attrs = {
17    accessor => $meth_name,
18    relation => $link, #"link" table or immediate relation
19    foreign_relation => $far_side, #'far' table or foreign relation
20    (@_ > 3 ? (attrs => $_[3]) : ()), #only store if exist
21  };
22
23  #inheritable data workaround
24  $class->_m2m_metadata({ $meth_name => $attrs, %$store});
25  $class->next::method(@_);
26}
27
281;
29