Update to add myself to contributors and to hide Modules from the PAUSE Indexer.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / HasMany.pm
1 package # hide from PAUSE
2     DBIx::Class::CDBICompat::HasMany;
3
4 use strict;
5 use warnings;
6
7 sub has_many {
8   my ($class, $rel, $f_class, $f_key, $args) = @_;
9
10   my @f_method;
11
12   if (ref $f_class eq 'ARRAY') {
13     ($f_class, @f_method) = @$f_class;
14   }
15
16   if (ref $f_key eq 'HASH' && !$args) { $args = $f_key; undef $f_key; };
17
18   $args ||= {};
19   if (delete $args->{no_cascade_delete}) {
20     $args->{cascade_delete} = 0;
21   }
22
23   $class->next::method($rel, $f_class, $f_key, $args);
24
25   if (@f_method) {
26     no strict 'refs';
27     no warnings 'redefine';
28     my $post_proc = sub { my $o = shift; $o = $o->$_ for @f_method; $o; };
29     *{"${class}::${rel}"} =
30       sub {
31         my $rs = shift->search_related($rel => @_);
32         $rs->{attrs}{record_filter} = $post_proc;
33         return (wantarray ? $rs->all : $rs);
34       };
35     return 1;
36   }
37
38 }
39
40 1;