Tie::Scalar::RestrictUpdates - Limit the number of times a value is stored in a scalar.


Tie-Scalar-RestrictUpdates documentation Contained in the Tie-Scalar-RestrictUpdates distribution.

Index


Code Index:

NAME

Top

Tie::Scalar::RestrictUpdates - Limit the number of times a value is stored in a scalar.

SYNOPSIS

Top

  use Tie::Scalar::RestrictUpdates;

  my $foo;
  tie $foo,"Tie::Scalar::RestrictUpdates",5;
  for(1..10) { $foo = $_; print $foo; }
  # This will print 1234555555

DESCRIPTION

Top

This module limits the number of times a value can be stored in a scalar.

TODO

Top

Loads probably. This is a very early draft.

DISCLAIMER

Top

This code is released under GPL (GNU Public License). More information can be found on http://www.gnu.org/copyleft/gpl.html

VERSION

Top

This is Tie::Scalar::RestrictUpdates 0.0.1.

AUTHOR

Top

Hendrik Van Belleghem (beatnik@quickndirty.org)

SEE ALSO

Top

GNU & GPL - http://www.gnu.org/copyleft/gpl.html


Tie-Scalar-RestrictUpdates documentation Contained in the Tie-Scalar-RestrictUpdates distribution.

package Tie::Scalar::RestrictUpdates;

use strict;
use vars qw($VERSION);

$VERSION = '0.01';

sub TIESCALAR { 
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{_COUNTER} = 0; 
$self->{_VAR} = undef;
bless $self, $class; 
$self->{_COUNTER} = shift || 1; 
return $self;
}

sub STORE { 
my $self = shift; 
if ($self->{_COUNTER}) 
 { $self->{_VAR} = shift; $self->{_COUNTER}--; } 
 else { warn "Cannot set variable again!";  }
}

sub FETCH { my $self = shift; return $self->{_VAR}; }

1;
__END__