=head1 NAME SuikaWiki::DB::FileSystem::LeafFile - SuikaWiki Directory-Structured Simple Database =head1 SYNOPSIS require SuikaWiki::DB::FileSystem::LeafFile; my $db = SuikaWiki::DB::FileSystem::LeafFile->new (base_directory => $path_to_db, directory_suffix => '.ns', file_suffix => '.txt', -lock => { ..lock property.. }); =head1 DESCRIPTION C provides simple database which maps namespaces to filesystem directories and keys to files. Directories and files names are encoded by base 16 so that user does not need to make key names filesystem safe (but file names is to be unreadable by human). This module is part of SuikaWiki. =cut package SuikaWiki::DB::FileSystem::LeafFile; use strict; our $VERSION=do{my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; require SuikaWiki::DB::FileSystem::Base; push our @ISA, 'SuikaWiki::DB::FileSystem::Base'; use IO::File; sub get ($$$;%) { my ($self, $prop, $key, %opt) = @_; report SuikaWiki::DB::Util::Error -type => 'KEY_INVALID_NAME', key => $key, -object => $self, method => 'get' unless $opt{no_key_check} or $self->__check_key (key => $key); unless ($self->{opened}->{$prop}) { local $Error::Depth = $Error::Depth + 1; $self->open_prop (prop => $prop); } my $path = $self->__key2filepath (key => $key); if (-e $path) { my $file = new IO::File $path, '<' or report SuikaWiki::DB::Util::Error -type => 'FILE_READ_FAILURE', -object => $self, method => 'get', file => $path, msg => $!; binmode $file; local $/ = undef; return scalar <$file>; } else { return undef; } } sub set ($$$$;%) { my ($self, $prop, $key, $val, %opt) = @_; report SuikaWiki::DB::Util::Error -type => 'KEY_INVALID_NAME', key => $key, -object => $self, method => 'set' unless $opt{no_key_check} or $self->__check_key (key => $key); unless ($self->{opened}->{$prop}) { local $Error::Depth = $Error::Depth + 1; $self->open_prop (prop => $prop); } if ($self->{lock} and not $self->{lock}->writable) { report SuikaWiki::DB::Util::Error -type => 'KEY_SAVE_LOCKED', -object => $self, method => 'set', key => $key, prop => $prop; return 0; } $self->__make_directory (directory => $self->__key2dirpath (fullkey => $key)); my $path = $self->__key2filepath (key => $key); my $file = new IO::File $path, '>' or report SuikaWiki::DB::Util::Error -type => 'FILE_WRITE_FAILURE', -object => $self, method => 'set', file => $path, msg => $!; binmode $file; print $file $val; close $file; 1; } sub _content_id ($$$;%) { my ($self, $prop, $key, %opt) = @_; require Digest::SHA1; Digest::SHA1::sha1 ($self->get ($prop, $key, %opt)); } =head1 SEE ALSO C. =head1 LICENSE Copyright 2004 Wakaba . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # $Date: 2004/11/08 09:57:49 $