From: Jacob Bachmeyer Date: Thu, 3 Nov 2022 02:17:48 +0000 (-0500) Subject: Add initial structured exception infrastructure X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c4944bebe20d0beab4041eea8538a8856af3b6cd;p=gatekeeper.git Add initial structured exception infrastructure --- 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