package Exception; use warnings; use strict; # Enable Perl 6 knock offs. use 5.010; use Carp; use Exporter 'import'; our @EXPORT_OK = qw(create_exception delete_exception); # Global stores for all exceptions. # NOTE: In this module each exception is just a Exception class, # and not it's own class; instead the data about each exception is created with # create_exception() and destroyed with delete_exception() while being stored in # %exception_{desc,param}. state %exception_desc; state %exception_param; # It is a hash of hashes. Each key in the first hash is the name or type of # exception, while the key in the second hash is 'description' for the type's # description, or 'params' for the list of parameters that exception takes. # Constructs new Exception objects in order to throw exceptions # coupled with die. For example: # die Exception->throw('SomeException'); sub throw { my($class, $exception_type, @params) = @_; croak < $exception_type, _description => $exception_desc{$exception_type} }, $class; # shift off the name of the parameter. while (defined(my $param = shift @params)) { if (grep $param eq $_, @{$exception_param{$exception_type}}) { # Store parameter inside this exception object. $self->{$param} = (shift @params // croak < '1', b => '2', c => '3') EOC # Also, substitute this paramter for its value in this exception's # description. #BUGALERT# be sure to test that this actually works. $self->{_description} =~ s/$param/$self->{$param}/g; } else { croak <