new component to make m2ms introspectables so we can hint the reflector
[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) = @_;
13
14 $class->_m2m_metadata->{$meth_name} =
15 {
16 accessor => $meth_name,
17 relation => $link, #"link" table or imediate relation
18 foreign_relation => $far_side, #'far' table or foreign relation
19 (@_ > 3 ? (attrs => $_[3]) : ()), #only store if exist
20 rs_method => "${meth_name}_rs", #for completeness..
21 add_method => "add_to_${meth_name}",
22 set_method => "set_${meth_name}",
23 remove_method => "remove_from_${meth_name}",
24 };
25
26 $class->next::method(@_);
27}
28
291;