Skip to content

Commit

Permalink
Add checking in sub requires() and optional() that the passed lists a…
Browse files Browse the repository at this point in the history
…re uneven in number
  • Loading branch information
peterdragon authored and khrt committed Sep 7, 2024
1 parent 64634b4 commit 48d6ed0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/Raisin/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,19 @@ sub _check_params {
}
sub params { _check_params(\@_); $SETTINGS{params} = \@_ }

sub requires { (requires => { name => @_ }) }
sub optional { (optional => { name => @_ }) }
sub requires {
if ( scalar(@_) % 2 != 1 ) {
Carp::confess "Even-sized list supplied to requires(). Does the block have a misplaced semicolon or closing bracket? "
. "params dump: ", Dumper(\@_);
}
(requires => { name => @_ }) }

sub optional {
if ( scalar(@_) % 2 != 1 ) {
Carp::confess "Even-sized list supplied to optional(). Does the block have a misplaced semicolon or closing bracket? "
. "params dump: ", Dumper(\@_);
}
(optional => { name => @_ }) }

sub group(&) { (encloses => [shift->()]) }

Expand Down

0 comments on commit 48d6ed0

Please sign in to comment.