From 6c99df7f1c5212ca5038a32754d97d20bb3e4215 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Tue, 8 Aug 2023 19:09:36 -0500 Subject: [PATCH] Add empty operation list predicate and use it to test for empty directives --- gatekeeper.pl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index 0c22f74..edd205a 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -1641,6 +1641,19 @@ arrayrefs as described below. bless \@ops, $class } +=item $oplist->is_empty + +Return true iff OPLIST contains no actual commands. + +=cut + + sub is_empty { + my $self = shift; + + # There is currently always a header at index 0. + return $#$self < 1; + } + =item $oplist->check Validate the operations in OPLIST. This allows to detect some types of @@ -2629,7 +2642,6 @@ An exception is thrown if validation fails. sub Local::Packet::Directive::_validate_directive { my $packet = shift; - my $ops = $packet->{oplist}; my $stem = $packet->file_name_stem; @@ -2645,7 +2657,7 @@ sub Local::Packet::Directive::_validate_directive { (CONF_DIR_ConfigBase, $packet->target_package, 'email'); # Check that we actually have at least one command in the directive - unless ($#$ops > 0) { + if ($packet->{oplist}->is_empty) { if (not $packet->has_uploaded_file) { throw directive_syntax => trace => [], target_directory => $packet->target_directory, -- 2.25.1