Dan Kogai > Tie-SaveLater > Tie::SaveLater

Download:
Tie-SaveLater-0.04.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  

NAME ^

Tie::SaveLater - A base class for tie modules that "save later".

SYNOPSIS ^

  package Tie::Storable;
  use base 'Tie::SaveLater';
  use Storable qw(retrieve nstore);
  __PACKAGE__->make_subclasses;
  sub load{ retrieve($_[1]) };
  sub save{ nstore($_[0], $_[0]->filename) };
  1;

  # later
  use Tie::Storable;
  {
      tie my $scalar => 'Tie::Storable', 'scalar.po';
      $scalar = 42;
  } # scalar is automatically saved as 'scalar.po'.
  {
      tie my @array => 'Tie::Storable', 'array.po';
      @array = qw(Sun Mon Tue Wed Fri Sat);
  } # array is automatically saved as 'array.po'.
  {
      tie my %hash => 'Tie::Storable', 'hash.po';
      %hash = (Sun=>0, Mon=>1, Tue=>2, Wed=>3, Thu=>4, Fri=>5, Sat=>6);
  } # hash is automatically saved as 'hash.po'.
  {
      tie my $object => 'Tie::Storable', 'object.po';
      $object = bless { First => 'Dan', Last => 'Kogai' }, 'DANKOGAI';
  } # You can save an object; just pass a scalar
  {
      tie my $object => 'Tie::Storable', 'object.po';
      $object->{WIFE} =  { First => 'Naomi', Last => 'Kogai' };
      # you can save before you untie like this
      tied($object)->save;
  }

DESCRIPTION ^

Tie::SaveLater make you easy to write a modules that "save later", that is, save on untie.

WHY?

Today we have a number of serializers that store complex data structures, from Data::Dumper to Storable. If those core modules are not enough, you have YAML and DBI and more via CPAN.

Problem? You have to save AFTER you are done with your data structure. Don't forget to save when you are out of scope just like locking the door before you leave.

But can't you make it so it autosaves as Hotel doors autolocks? That's exactly what this module is for. This module comes with Tie::DataDumper, Tie::Storable, and Tie::YAML so you can make your data structures autosave today!

DETAILS

"SYNOPSIS" illustrates how to implement Tie::Storable in seven lines. Suppose your module is Tie::Them, Your module needs to do the following;

EXPORT

None by default.

SEE ALSO ^

perltie, Tie::Scalar, Tie::Array, Tie::Hash

Tie::Storable, Tie::YAML, Tie::DataDumper

AUTHOR ^

Dan Kogai, <dankogai@dan.co.jp>

COPYRIGHT AND LICENSE ^

Copyright (C) 2006 by Dan Kogai

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: