or download this
Usage:
use Tie::Constrained;
tie my $var, Tie::Constrained => \&mytest, $initval;
...
Both arguments are optional, but the default validator
function always says yes. mytest() should be designed
to return true for valid data and false for data to reject.