sub parameterized_has_many {
my ($class, $rel, $f_source, $cond, $attrs) = @_;
+
+ die "Missing relation name for parameterized_has_many"
+ unless defined $rel;
+ die "Missing foreign source"
+ unless defined $f_source;
+
{
my $cond_ref = ref($cond);
- die "Condition needs to be [ \\\@args, \$code ], not ${cond_ref}"
+ $cond_ref = 'non-reference value'
+ unless $cond_ref;
+ die "Condition needs to be [ \\\@args, \&code ], not ${cond_ref}"
unless $cond_ref eq 'ARRAY';
}
my ($args, $code) = @$cond;
+
+ {
+ my $arg_ref = ref($cond->[0]);
+ $arg_ref = 'non-reference value'
+ unless $arg_ref;
+ die "Arguments must be declared as array ref of names, not ${arg_ref}"
+ unless $arg_ref eq 'ARRAY';
+ my $code_ref = ref($cond->[1]);
+ $code_ref = 'non-reference value'
+ unless $code_ref;
+ die "Condition builder must be declared as code ref, not ${code_ref}"
+ unless $code_ref eq 'CODE';
+ }
+
my $store = $class->$STORE({
%{$class->$STORE||{}},
$rel => { params => {}, args => $args },
})->{$rel};
+
my $wrapped_code = sub {
my $params = $store->{params};
my @missing = grep !exists $params->{$_}, @$args;
local *_ = $params;
&$code;
};
+
$class->has_many($rel, $f_source, $wrapped_code, $attrs);
return; # no, you are not going to accidentally rely on a return value
}
)
->all;
+=head1 WARNING
+
+This module uses L<DBIx::Class> internals and may break at any time.
+
=head1 DESCRIPTION
This L<DBIx::Class> component allows to declare dynamically parameterized
__PACKAGE__->load_components(qw( ParameterizedJoinHack ));
-See L<parameterized_has_many> for details on declaring relations.
+See L</parameterized_has_many> for details on declaring relations.
See L<DBIx::Class::ResultSet::ParameterizedJoinHack> for ResultSet usage.
+B<Note:> Currently only L</parameterized_has_many> is implemented, since
+it is the most requested use-case. However, adding support for other
+relationship types is possible if a use-case is found.
+
=head1 METHODS
=head2 parameterized_has_many
=head1 CONTRIBUTORS
-None yet.
+ Robert Sedlacek <r.sedlacek@shadowcat.co.uk>
=head1 COPYRIGHT