summaryrefslogtreecommitdiff
path: root/fml/lib/IO
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-01-26 07:27:43 +0000
committerfukachan <fukachan>2001-01-26 07:27:43 +0000
commitd1d6fd1fe6bf0cce7c85b3336ce6fdcee691fc1f (patch)
tree9d52172683d8a5cef77c30fdb5889853a51f5872 /fml/lib/IO
parentf9d8cade872c90e26212384f77ed81e81f11014f (diff)
downloadfml8-d1d6fd1fe6bf0cce7c85b3336ce6fdcee691fc1f.tar.gz
fml8-d1d6fd1fe6bf0cce7c85b3336ce6fdcee691fc1f.tar.bz2
fml8-d1d6fd1fe6bf0cce7c85b3336ce6fdcee691fc1f.zip
rename IO:: to Tie::
Diffstat (limited to 'fml/lib/IO')
-rw-r--r--fml/lib/IO/LogFileDB.pm182
1 files changed, 0 insertions, 182 deletions
diff --git a/fml/lib/IO/LogFileDB.pm b/fml/lib/IO/LogFileDB.pm
deleted file mode 100644
index 3e7bb7c5..00000000
--- a/fml/lib/IO/LogFileDB.pm
+++ /dev/null
@@ -1,182 +0,0 @@
-#-*- perl -*-
-#
-# Copyright (C) 2001 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.
-#
-# $Id$
-# $FML$
-#
-
-package IO::LogFileDB;
-
-use strict;
-use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
-use Carp;
-
-require Exporter;
-@ISA = qw(Exporter);
-
-
-sub new
-{
- my ($self, $args) = @_;
- my ($type) = ref($self) || $self;
- my $me = {};
-
- $me->{ _file } = $args->{ file };
-
- if ($args->{ first_match }) {
- $me->{ _match_style } = 'first';
- }
- elsif ($args->{ last_match }) {
- $me->{ _match_style } = 'last';
- }
- else {
- $me->{ _match_style } = 'first';
- }
-
- return bless $me, $type;
-}
-
-
-sub TIEHASH
-{
- my ($self, $args) = @_;
- my ($type) = ref($self) || $self;
- new($self, $args);
-}
-
-
-sub grep
-{
- my ($self, $key) = @_;
- my $rarray = $self->_fetch($key, 'array');
- return @$rarray;
-}
-
-
-sub FETCH
-{
- my ($self, $key) = @_;
- $self->_fetch($key, 'scalar');
-}
-
-
-sub STORE
-{
- my ($self, $key, $value) = @_;
-}
-
-
-sub _fetch
-{
- my ($self, $key, $mode) = @_;
- my $prekey = $key;
-
- # the first 1 byte of the key
- if ($key =~ /^(.)/) { $prekey = $1;}
-
- use IO::File;
- my $fh = new IO::File;
- $fh->open( $self->{ _file }, "r");
-
- my ($xkey, $xvalue) = ();
- my (@values) = ();
- SEARCH:
- while (<$fh>) {
- next SEARCH if /^\#*$/;
- next SEARCH if /^\s*$/;
- next SEARCH unless /^$prekey/i;
- next SEARCH unless /^$key/i;
-
- chop;
- ($xkey, $xvalue) = split(/\s+/, $_, 2);
- if ($xkey eq $key) {
- if ($mode eq 'scalar') {
- # firstmatch: exit loop ASAP if the $key is found.
- if ($self->{ _match_style } eq 'first') {
- last SEARCH;
- }
- }
- if ($mode eq 'array') {
- push(@values, $xvalue);
- }
- }
- }
- close($fh);
-
- if ($mode eq 'scalar') {
- return( $xvalue || undef );
- }
- if ($mode eq 'array') {
- return \@values;
- }
-}
-
-
-=head1 NAME
-
-IO::LogFileDB.pm - what is this
-
-=head1 SYNOPSIS
-
- use IO::LogFileDB;
- $db = new IO::LogFileDB { file => 'cache.txt' };
-
- # all entries with the key = 'rudo'
- @values = $db->grep( rudo );
-
-or
-
- use IO::LogFileDB;
- tie %db, 'IO::LogFileDB', { file => 'cache.txt' };
- print $db{ rudo }, "\n";
-
-where cache file "cache.txt" format is "key value" for each line.
-For example
-
- rudo teddy bear
- kenken north fox
- .....
-
-By default, FETCH() returns the first value with the key.
-
- use IO::LogFileDB;
- tie %db, 'IO::LogFileDB', { first_match => 1, file => 'cache.txt' };
- print $db{ rudo }, "\n";
-
-if you find the latest value (so at the later line somewhere in the
-file) for the $key
-
- use IO::LogFileDB;
- tie %db, 'IO::LogFileDB', { last_match => 1, file => 'cache.txt' };
- print $db{ rudo }, "\n";
-
-
-
-=head1 DESCRIPTION
-
-=head2 new
-
-=item Function()
-
-
-=head1 AUTHOR
-
-Ken'ichi Fukamachi
-
-=head1 COPYRIGHT
-
-Copyright (C) 2001 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
-
-IO::LogFileDB.pm appeared in fml5.
-
-=cut
-
-1;