summaryrefslogtreecommitdiff
path: root/fml/lib/FML/Cache
diff options
context:
space:
mode:
authorfukachan <fukachan>2003-11-22 05:41:50 +0000
committerfukachan <fukachan>2003-11-22 05:41:50 +0000
commit4c69052bf40ec76b14319cb5c670ff9ebffbc35f (patch)
tree23e70dc42beae25648d48102460b470a79e177df /fml/lib/FML/Cache
parent425f6c8fe24698f2def90091c05f2c56f7b431ab (diff)
downloadfml8-4c69052bf40ec76b14319cb5c670ff9ebffbc35f.tar.gz
fml8-4c69052bf40ec76b14319cb5c670ff9ebffbc35f.tar.bz2
fml8-4c69052bf40ec76b14319cb5c670ff9ebffbc35f.zip
separete database part in FML::Confirm to FML::Cache::Journal which
can be shared between other modules. change FML::Confirm::new() to take $curproc.
Diffstat (limited to 'fml/lib/FML/Cache')
-rw-r--r--fml/lib/FML/Cache/Journal.pm111
1 files changed, 111 insertions, 0 deletions
diff --git a/fml/lib/FML/Cache/Journal.pm b/fml/lib/FML/Cache/Journal.pm
new file mode 100644
index 00000000..70e44b72
--- /dev/null
+++ b/fml/lib/FML/Cache/Journal.pm
@@ -0,0 +1,111 @@
+#-*- perl -*-
+#
+# Copyright (C) 2003 Ken'ichi Fukamachi
+# All rights reserved. This program is free software; you can
+# redistribute it and/or modify it under the same terms as Perl itself.
+#
+# $FML: @template.pm,v 1.7 2003/01/01 02:06:22 fukachan Exp $
+#
+
+package FML::Cache::Journal;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
+
+=head1 NAME
+
+FML::Cache::Journal - inteface into Tie::JournaledDir
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=head2 new($curproc)
+
+=head2 open_db()
+
+=head2 close_db()
+
+=cut
+
+
+# Descriptions: constructor.
+# Arguments: OBJ($self) OBJ($curproc)
+# Side Effects: create object
+# Return Value: OBJ
+sub new
+{
+ my ($self, $curproc) = @_;
+ my ($type) = ref($self) || $self;
+ my $me = { _curproc => $curproc };
+
+ return bless $me, $type;
+}
+
+
+# Descriptions: open database by Tie::JournaledDir.
+# Arguments: OBJ($self) STR($cache_dir) STR($class)
+# Side Effects: open database, mkdir if needed
+# Return Value: HASH_REF to dabase
+sub open
+{
+ my ($self, $cache_dir, $class) = @_;
+ my (%db) = ();
+
+ # XXX-TODO: dir_mode hard-coded.
+ my $mode = $self->{ _dir_mode } || 0700;
+
+ use File::Spec;
+ my $dir = File::Spec->catfile($cache_dir, $class);
+ unless (-d $dir) {
+ my $curproc = $self->{ _curproc };
+ $curproc->mkdir($dir, $mode);
+ }
+
+ use Tie::JournaledDir;
+ tie %db, 'Tie::JournaledDir', { dir => $dir };
+
+ $self->{ _db } = \%db;
+
+ return \%db;
+}
+
+
+# Descriptions: close database.
+# Arguments: OBJ($self)
+# Side Effects: none
+# Return Value: none
+sub close
+{
+ my ($self) = @_;
+ my $db = $self->{ _db };
+ untie %$db;
+}
+
+
+=head1 CODING STYLE
+
+See C<http://www.fml.org/software/FNF/> on fml coding style guide.
+
+=head1 AUTHOR
+
+Ken'ichi Fukamachi
+
+=head1 COPYRIGHT
+
+Copyright (C) 2003 Ken'ichi Fukamachi
+
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the same terms as Perl itself.
+
+=head1 HISTORY
+
+FML::Cache::Journal appeared in fml8 mailing list driver package.
+See C<http://www.fml.org/> for more details.
+
+=cut
+
+
+1;