update my own contrib entry
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / HasMany.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE
2 DBIx::Class::CDBICompat::HasMany;
b8e1e21f 3
4use strict;
5use warnings;
6
7sub has_many {
8 my ($class, $rel, $f_class, $f_key, $args) = @_;
95a70f01 9
33ce49d6 10 my @f_method;
95a70f01 11
12 if (ref $f_class eq 'ARRAY') {
33ce49d6 13 ($f_class, @f_method) = @$f_class;
95a70f01 14 }
15
07037f89 16 if (ref $f_key eq 'HASH' && !$args) { $args = $f_key; undef $f_key; };
95a70f01 17
07037f89 18 $args ||= {};
19 if (delete $args->{no_cascade_delete}) {
20 $args->{cascade_delete} = 0;
9bc6db13 21 }
95a70f01 22
147dd158 23 $class->next::method($rel, $f_class, $f_key, $args);
33ce49d6 24
33ce49d6 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
b8e1e21f 38}
39
b8e1e21f 401;