From 48d6ed0fbe81512865a644b258d683a78dd75321 Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Wed, 4 Sep 2024 15:11:27 +0100 Subject: [PATCH] Add checking in sub requires() and optional() that the passed lists are uneven in number --- lib/Raisin/API.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Raisin/API.pm b/lib/Raisin/API.pm index cc003d8..255fd86 100644 --- a/lib/Raisin/API.pm +++ b/lib/Raisin/API.pm @@ -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->()]) }