From: Robert Sedlacek Date: Wed, 30 Sep 2015 03:25:42 +0000 (+0000) Subject: join argument validation X-Git-Tag: v0.000001~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=598b28ef7b90c9e781fd4136601808e53cb49d86;p=dbsrgits%2FDBIx-Class-ParameterizedJoinHack.git join argument validation --- diff --git a/lib/DBIx/Class/ResultSet/ParameterizedJoinHack.pm b/lib/DBIx/Class/ResultSet/ParameterizedJoinHack.pm index 4de2973..75db8b7 100644 --- a/lib/DBIx/Class/ResultSet/ParameterizedJoinHack.pm +++ b/lib/DBIx/Class/ResultSet/ParameterizedJoinHack.pm @@ -12,6 +12,15 @@ sub _parameterized_join_store { sub with_parameterized_join { my ($self, $rel, $params) = @_; + die "Missing relation name in with_parameterized_join" + unless defined $rel; + { + my $params_ref = ref($params); + $params_ref = 'non-reference-value' + unless $params_ref; + die "Parameters value must be a hash ref, not ${params_ref}" + unless $params_ref eq 'HASH'; + } $self->search_rs( {}, { join => $rel, diff --git a/t/00basic.t b/t/00basic.t index fa997e3..5da8cfe 100644 --- a/t/00basic.t +++ b/t/00basic.t @@ -115,6 +115,15 @@ subtest 'has_many' => sub { ->$search ->$fetch_count; }, qr{__invalid__}, 'unknown relation'; + like exception { + $people->with_parameterized_join(undef, {}); + }, qr{relation.+name}i, 'missing relation name'; + like exception { + $people->with_parameterized_join(foo => []); + }, qr{parameters.+hash.+not.+ARRAY}i, 'invalid parameters'; + like exception { + $people->with_parameterized_join(foo => 23); + }, qr{parameters.+hash.+not.+non-reference}i, 'non ref parameters'; }; };