*grumble*inheritable classdata *grumble*
[catagits/Reaction.git] / lib / DBIx / Class / IntrospectableM2M.pm
CommitLineData
df9a9c12 1package DBIx::Class::IntrospectableM2M;
2
3use strict;
4use warnings;
5use base 'DBIx::Class';
6
7#namespace pollution. sadface.
8__PACKAGE__->mk_classdata( _m2m_metadata => {} );
9
10sub many_to_many {
11 my $class = shift;
12 my ($meth_name, $link, $far_side) = @_;
dcd5fef7 13 my $store = $class->_m2m_metadata;
14 die("You are overwritting another relationship's metadata")
15 if exists $store->{$meth_name};
df9a9c12 16
dcd5fef7 17 my $attrs =
df9a9c12 18 {
dcd5fef7 19 accessor => $meth_name,
df9a9c12 20 relation => $link, #"link" table or imediate relation
21 foreign_relation => $far_side, #'far' table or foreign relation
22 (@_ > 3 ? (attrs => $_[3]) : ()), #only store if exist
23 rs_method => "${meth_name}_rs", #for completeness..
24 add_method => "add_to_${meth_name}",
25 set_method => "set_${meth_name}",
26 remove_method => "remove_from_${meth_name}",
27 };
28
dcd5fef7 29 #inheritable data workaround/
30 $class->_m2m_metadata({ $meth_name => $attrs, %$store});
31
df9a9c12 32 $class->next::method(@_);
33}
34
351;