The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Storable::Ref - Persistent automatic variables vi Storable

SYNOPSYS

  $ cat >tesy.pl
  use Storable::Ref;
  my $v=new Storable::Ref({a=>1, b=>1},"filename");
  print "a=".($v->{a}++)." b=".($v->{b}*=2)."\n";
  ^D
  $ perl test.pl
  a=1 b=2
  $ for v in 1 2 3; do perl test.pl; done
  a=2 b=4
  a=3 b=8
  a=4 b=16
  rm filename
  $ perl test.pl
  a=1 b=2

Storable::Ref gets your reference to variable and remembers filename associated with this variable. When you construct this variable you provide to constructor default value and fully qualified filename for storing this it. If Storable::Ref finds this file and it contains valid Storable object, it uses this data to initialize variable with this data instead of default value.

this functionality my be used for storing state of interuptable scripts, or for saving important information when script throws die or uncatched exceptions.

CAUTION

Storable::Ref stores data in method DESTROY(), and if thismethod isn't called, saving is not processed. if yor perl was killed by sig9 or sig11 data will be lost.

METHODS

new($defaultvalue, $filepath)

constructor rebless variable to Storable::Ref. So you can't use persistence on blessed variables, yet.

savenow()

$variable->savenow() Implicitly stores data, use it if you convinient to death without of testating your stuff.

DESTROY()

This method called automaticaly, when perl intended to delete variable and clear it memory. Method recall in memory filename associated with this variable and stores it to this file. Works automatically when: $variable=undef; or variable leaves it scope, or when programm terminates, but perl data structures is not destroyed.

AUTHOR

Vany Serezhkin <ivan@serezhkin.com> 2009 Yandex.