package CSLocal; use strict; use base qw/Class::Singleton/; my @value_stack = (); sub undefine_value { delete $_[0]->{VALUE}; } sub value { my $self = shift; $self->{VALUE} = $_[0] if @_; $self->{VALUE}; } sub localize { my $self = shift; push @value_stack, $self->value (); $self->undefine_value (); } sub restore { my $self = shift; die "no values to restore" unless @value_stack; my $val = pop @value_stack; $self->value ($val); } 1;