$self->status('unknown') or $self->status('good') set an object's status, whereas $self->status('ungnown') generates an error. I would like this also to be available
####
use strict;
use warnings;
my $a_or_b;
$a_or_b->{a} = 'a'; #should be okay
$a_or_b->{b} = 'b'; #should be okay
$a_or_b->{c} = 'c'; #should generate an error
####
$status->{good} = '1'; #should be okay
$status->{bad} = '1'; #should be okay
$a_or_b->{ungnown} = '1'; #should generate an error
####
use strict;
use warnings;
my($status);
tie $status, 'Status';
$status = 'ungnown'; # warning, and value does not get set.
$status = 'good'; # works
print "$status";
package Status;
use Tie::Scalar;
use Carp;
use base qw(Tie::StdScalar);
sub TIESCALAR {
my $class = shift;
my $status = shift;
bless \$status, $class;
}
sub STORE
{
my($me, $value) = @_;
unless ($value eq 'good'){
warn("invalid status: $value. Status not set");
return undef;
}
${$me} = $value;
}
sub FETCH
{
my($status) = @_;
return ${$status};
}