In larger programs, I like to guard against typos in hash keys (when the keys are a known, fixed set) using Hash::Util's lock_keys, or I'll retrofit a large program with this module for the same purpose.
Is there something like this for scalars? I.e. something that lets me restrict the value of a scalar to a set of allowed values? (I've searched, but not found anything yet.) Something like this:
tie my $state, 'Scalar::Restrict', qw/ idle waiting active /;
# or maybe
lock_scalar my $state, qw/ idle waiting active /;
# $state may now only be "idle", "waiting", or "active"
Thanks in advance for your thoughts.