NAME
Forks::Super::Tie::Enum - tie'd scalar that can only hold values on a small list
SYNOPSIS
use Forks::Super::Tie::Enum;
tie $next_action, 'Forks::Super::Tie::Enum', 'abort', 'retry', 'fail';
$next_action = "abort"; # ok
$next_action = "retry"; # ok
$next_action = "go fishing"; # warning "Invalid assignment ..."
DESCRIPTION
This package is part of the Forks::Super distribution. But it does not depend on any other part of Forks::Super
and there is no reason it couldn't be extricated and used in a different context.
Scalar value where assignment will fail unless the new value is on a list of value provided when the tie is started. If you expect the value of $switch
to be either "on"
or "off"
and if your script would fail catastrophically if a user tried to assign
$switch = "cheesecake";
then this module might be for you!
USAGE
tie $var, "Forks::Super::Tie::Enum", @list;
Assigns the first element of the given @list
to the scalar <$var>, and ignores any future attempts to assign a value to $var
that was not in @list
at the time of tie'ing.
Assigning an invalid value will cause this package to produce the warning message
Invalid assignment to enumerated tied scalar.
AUTHOR
Marty O'Brien, <mob@cpan.org>
LICENSE AND COPYRIGHT
Copyright (c) 2009-2018, Marty O'Brien.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
See http://dev.perl.org/licenses/ for more information.