msysGit-based Git for Windows 1.x was superseded by Git for Windows 2.x
[git/mingw/4msysgit.git] / perl / Git / SVN / Memoize / YAML.pm
blob9676b8f2f73520735b68f6ff13d03d52575afaae
1 package Git::SVN::Memoize::YAML;
2 use warnings;
3 use strict;
4 use YAML::Any ();
6 # based on Memoize::Storable.
8 sub TIEHASH {
9 my $package = shift;
10 my $filename = shift;
11 my $truehash = (-e $filename) ? YAML::Any::LoadFile($filename) : {};
12 my $self = {FILENAME => $filename, H => $truehash};
13 bless $self => $package;
16 sub STORE {
17 my $self = shift;
18 $self->{H}{$_[0]} = $_[1];
21 sub FETCH {
22 my $self = shift;
23 $self->{H}{$_[0]};
26 sub EXISTS {
27 my $self = shift;
28 exists $self->{H}{$_[0]};
31 sub DESTROY {
32 my $self = shift;
33 YAML::Any::DumpFile($self->{FILENAME}, $self->{H});
36 sub SCALAR {
37 my $self = shift;
38 scalar(%{$self->{H}});
41 sub FIRSTKEY {
42 'Fake hash from Git::SVN::Memoize::YAML';
45 sub NEXTKEY {
46 undef;
50 __END__
52 =head1 NAME
54 Git::SVN::Memoize::YAML - store Memoized data in YAML format
56 =head1 SYNOPSIS
58 use Memoize;
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);
65 =head1 DESCRIPTION
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.
76 Carps on error.
78 =head1 DIAGNOSTICS
80 See L<YAML::Any>.
82 =head1 DEPENDENCIES
84 L<YAML::Any> from CPAN.
86 =head1 INCOMPATIBILITIES
88 None reported.
90 =head1 BUGS
92 The entire cache is read into a Perl hash when loading the file,
93 so this is not very scalable.