contributor update
[dbsrgits/DBIx-Class-ParameterizedJoinHack.git] / lib / DBIx / Class / ParameterizedJoinHack.pm
index cfd5960..132709a 100644 (file)
@@ -13,16 +13,39 @@ __PACKAGE__->mk_group_accessors(inherited => $STORE);
 
 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;
@@ -31,6 +54,7 @@ sub parameterized_has_many {
     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
 }
@@ -133,6 +157,10 @@ DBIx::Class::ParameterizedJoinHack - Parameterized Relationship Joins
         )
         ->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
@@ -142,10 +170,14 @@ Add the component to your Result class as usual:
 
     __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
@@ -184,7 +216,7 @@ Development of this module was sponsored by
 
 =head1 CONTRIBUTORS
 
-None yet.
+ Robert Sedlacek <r.sedlacek@shadowcat.co.uk>
 
 =head1 COPYRIGHT