Forks::Super::Tie::Enum - tie'd scalar that can only hold values on a small list
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 ..."
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.
Forks::Super
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
"on"
"off"
$switch = "cheesecake";
then this module might be for you!
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.
@list
$var
Assigning an invalid value will cause this package to produce the warning message
Invalid assignment to enumerated tied scalar.
Marty O'Brien, <mob@cpan.org>
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.
To install Forks::Super, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Forks::Super
CPAN shell
perl -MCPAN -e shell install Forks::Super
For more information on module installation, please visit the detailed CPAN module installation guide.