From c4944bebe20d0beab4041eea8538a8856af3b6cd Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Wed, 2 Nov 2022 21:17:48 -0500 Subject: [PATCH] Add initial structured exception infrastructure --- gatekeeper.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gatekeeper.pl b/gatekeeper.pl index c5eb442..ec23cef 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -529,6 +529,39 @@ BEGIN { } } + +# +# - Local exception definitions and utilities +# + +{ + package Local::Exception; + + sub type { (shift)->{type} } + sub summary { (shift)->{summary} } + + sub type_p { + my $self = shift; + my $query = shift; + + return $self->{type} eq $query + } +} + +=item throw $type => ($key => $value)... + +Throw a TYPE exception, with further options specified as key/value pairs. + +All types include a brief summary given with the C option. + +=cut + +sub throw { + my $type = shift; + + die bless {type => $type, @_}, 'Local::Exception::'.$type; +} + # # - GPG helpers -- 2.25.1