Commit | Line | Data |
c4ac9963 |
1 | package IntrospectM2M; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use base 'DBIx::Class'; |
6 | |
7 | __PACKAGE__->mk_classdata( _m2m_metadata => {} ); |
8 | |
9 | sub 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 | |
28 | 1; |