| 1 | package DBIx::Class::IntrospectableM2M; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use base 'DBIx::Class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '0.001001'; | |||||||||
| 8 | |||||||||||
| 9 | #namespace pollution. sadface. | ||||||||||
| 10 | 1 | __PACKAGE__->mk_classdata( _m2m_metadata => {} ); | |||||||||
| 11 | |||||||||||
| 12 | sub many_to_many { | ||||||||||
| 13 | 2 | ▶ | my $class = shift; | ||||||||
|
Subroutine
many_to_many: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 14 | 2 | my ($meth_name, $link, $far_side) = @_; | |||||||||
| 15 | 2 | my $store = $class->_m2m_metadata; | |||||||||
| 16 | warn("You are overwritting another relationship's metadata") | ||||||||||
| 17 | 2 | ▶ | if exists $store->{$meth_name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | my $attrs = { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | accessor => $meth_name, | ||||||||||
| 21 | relation => $link, #"link" table or imediate relation | ||||||||||
| 22 | foreign_relation => $far_side, #'far' table or foreign relation | ||||||||||
| 23 | (@_ > 3 ? (attrs => $_[3]) : ()), #only store if exist | ||||||||||
| 24 | rs_method => "${meth_name}_rs", #for completeness.. | ||||||||||
| 25 | add_method => "add_to_${meth_name}", | ||||||||||
| 26 | set_method => "set_${meth_name}", | ||||||||||
| 27 | remove_method => "remove_from_${meth_name}", | ||||||||||
| 28 | }; | ||||||||||
| 29 | |||||||||||
| 30 | #inheritable data workaround | ||||||||||
| 31 | 2 | $class->_m2m_metadata({ $meth_name => $attrs, %$store}); | |||||||||
| 32 | 2 | $class->next::method(@_); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 1 | 1; | |||||||||
| 36 | |||||||||||
| 37 | __END__; | ||||||||||