1 package Git::SVN::Memoize::YAML;
6 # based on Memoize::Storable.
11 my $truehash = (-e $filename) ? YAML::Any::LoadFile($filename) : {};
12 my $self = {FILENAME => $filename, H => $truehash};
13 bless $self => $package;
18 $self->{H}{$_[0]} = $_[1];
28 exists $self->{H}{$_[0]};
33 YAML::Any::DumpFile($self->{FILENAME}, $self->{H});
38 scalar(%{$self->{H}});
42 'Fake hash from Git::SVN::Memoize::YAML';
54 Git::SVN::Memoize::YAML - store Memoized data in YAML format
59 use Git::SVN::Memoize::YAML;
61 tie my %cache => 'Git::SVN::Memoize::YAML', $filename;
62 memoize('slow_function', SCALAR_CACHE => [HASH => \%cache]);
63 slow_function(arguments);
67 This module provides a class that can be used to tie a hash to a
68 YAML file. The file is read when the hash is initialized and
69 rewritten when the hash is destroyed.
71 The intent is to allow L<Memoize> to back its cache with a file in
72 YAML format, just like L<Memoize::Storable> allows L<Memoize> to
73 back its cache with a file in Storable format. Unlike the Storable
74 format, the YAML format is platform-independent and fairly stable.
84 L<YAML::Any> from CPAN.
86 =head1 INCOMPATIBILITIES
92 The entire cache is read into a Perl hash when loading the file,
93 so this is not very scalable.