View on
Ivan B. Serezhkin > Storable-Ref > Storable::Ref



Annotate this POD

View/Report Bugs
Module Version: 1.1   Source  


Storable::Ref - Persistent automatic variables vi Storable


  $ cat >
  use Storable::Ref;
  my $v=new Storable::Ref({a=>1, b=>1},"filename");
  print "a=".($v->{a}++)." b=".($v->{b}*=2)."\n";
  $ perl
  a=1 b=2
  $ for v in 1 2 3; do perl; done
  a=2 b=4
  a=3 b=8
  a=4 b=16
  rm filename
  $ perl
  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.


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.


new($defaultvalue, $filepath)

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


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


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.


Vany Serezhkin <> 2009 Yandex.

syntax highlighting: