Add initial structured exception infrastructure
authorJacob Bachmeyer <jcb@gnu.org>
Thu, 3 Nov 2022 02:17:48 +0000 (21:17 -0500)
committerJacob Bachmeyer <jcb@gnu.org>
Thu, 3 Nov 2022 02:17:48 +0000 (21:17 -0500)
gatekeeper.pl

index c5eb442fafa4c2d5718dbee335f2a7ce5d74a4e4..ec23cefc9d5833fcfa4e4ef67527fd86714c238e 100755 (executable)
@@ -529,6 +529,39 @@ BEGIN {
   }
 }
 
+\f
+#
+# - 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<summary> option.
+
+=cut
+
+sub throw {
+  my $type = shift;
+
+  die bless {type => $type, @_}, 'Local::Exception::'.$type;
+}
+
 \f
 #
 # - GPG helpers