From 3be8114d3632498723c23dc0faffb286078d4a69 Mon Sep 17 00:00:00 2001 From: octo Date: Mon, 11 Apr 2005 18:03:50 +0000 Subject: [PATCH] First runnable version. Still many bugs. To be continued.. --- lib/Onis/Data/Persistent/None.pm | 37 ++++++++++++++++++++++++++-------- lib/Onis/Plugins/Interestingnumbers.pm | 2 +- lib/Onis/Plugins/Nicks.pm | 2 +- onis | 27 ++++++++++++++----------- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/lib/Onis/Data/Persistent/None.pm b/lib/Onis/Data/Persistent/None.pm index 35a0dec..1dccf93 100644 --- a/lib/Onis/Data/Persistent/None.pm +++ b/lib/Onis/Data/Persistent/None.pm @@ -3,9 +3,7 @@ package Onis::Data::Persistent::None; use strict; use warnings; -use vars (qw($TREE)); - -use Carp qw(confess); +use Carp qw(carp confess); =head1 NAME @@ -21,7 +19,12 @@ None. =cut -$TREE = {}; +our $Tree = {}; + +if ($::DEBUG & 0x0200) +{ + require Data::Dumper; +} return (1); @@ -37,20 +40,28 @@ sub new my $id = $caller . ':' . $name; - if (exists ($TREE->{$id})) + if (exists ($Tree->{$id})) { print STDERR $/, __FILE__, ": Name $name has been used in context $caller before."; return (undef); } - $TREE->{$id} = {}; - $obj->{'data'} = $TREE->{$id}; + $Tree->{$id} = {}; + $obj->{'data'} = $Tree->{$id}; $obj->{'key'} = $key; $obj->{'fields'} = [@fields]; $obj->{'num_fields'} = scalar (@fields); $obj->{'field_index'} = {map { $_ => $i++ } (@fields)}; $obj->{'id'} = $id; + + if ($::DEBUG & 0x0200) + { + my $prefix = __FILE__ . ': '; + my $dbg = Data::Dumper->Dump ([$obj], ['obj']); + $dbg =~ s/^/$prefix/mg; chomp ($dbg); + print STDOUT $/, $dbg; + } return (bless ($obj, $pkg)); } @@ -64,10 +75,15 @@ sub put if ($obj->{'num_fields'} != scalar (@fields)) { my $id = $obj->{'id'}; - print STDERR $/, __FILE__, ": Number of fields do not match ($id)."; + carp ("Number of fields do not match ($id)."); return; } + if ($::DEBUG & 0x0200) + { + print STDOUT $/, __FILE__, ': PUT(', $obj->{'id'}, ', ', $key, ') = (' . join (', ', @fields) . ')'; + } + $obj->{'data'}{$key} = [@fields]; } @@ -81,6 +97,11 @@ sub get return (qw()); } + if ($::DEBUG & 0x0200) + { + print STDOUT $/, __FILE__, ': GET(', $obj->{'id'}, ', ', $key, ') = (' . join (', ', @{$obj->{'fields'}}) . ')'; + } + return (@{$obj->{'data'}{$key}}); } diff --git a/lib/Onis/Plugins/Interestingnumbers.pm b/lib/Onis/Plugins/Interestingnumbers.pm index 57becb6..6554bd4 100644 --- a/lib/Onis/Plugins/Interestingnumbers.pm +++ b/lib/Onis/Plugins/Interestingnumbers.pm @@ -47,7 +47,7 @@ sub get_or_empty { my $nick = shift; my @data = $InterestingNumbersCache->get ($nick); - @data = (0, 0, 0, 0, 0, 0) unless (@data); + @data = (0, 0, 0, 0, 0, 0, 0) unless (@data); return (@data); } diff --git a/lib/Onis/Plugins/Nicks.pm b/lib/Onis/Plugins/Nicks.pm index a90e3a9..6d30c6e 100644 --- a/lib/Onis/Plugins/Nicks.pm +++ b/lib/Onis/Plugins/Nicks.pm @@ -5,7 +5,7 @@ use warnings; use Onis::Html (qw(get_filehandle)); use Onis::Language (qw(translate)); -use Onis::Data::Core (qw(register_plugin)); +use Onis::Data::Core (qw(register_plugin nick_to_ident)); use Onis::Data::Persistent (); use Onis::Users (qw(nick_to_name)); diff --git a/onis b/onis index 7d794b0..94bcc73 100755 --- a/onis +++ b/onis @@ -27,7 +27,7 @@ BEGIN # 0x0400 Data::Core (dump incoming data to stderr) # 0x0800 Data::Core (initializing) # 0x1000 Onis::Users - $::DEBUG = 0x0000; + $::DEBUG = 0x0200; } use strict; @@ -48,7 +48,7 @@ if (!$VERSION) $VERSION =~ s/^\D*(\d+).*/r$1/; } -our $FILEINFO; +our $FileInfo; our $PURGE_LOGS = 0; print STDERR $/, __FILE__, ': $Id$' if ($::DEBUG); @@ -126,11 +126,11 @@ if (get_config ('logtype')) require "Onis/Parser/$logtype.pm"; require Onis::Parser::Persistent; require Onis::Data::Persistent; -import Onis::Parser qw/parse last_date/; -import Onis::Parser::Persistent qw#newfile#; -import Onis::Data::Persistent qw#init#; +import Onis::Parser (qw(parse last_date)); +import Onis::Parser::Persistent (qw(newfile)); +import Onis::Data::Persistent (); -$FILEINFO = init ('$FILEINFO', 'hash'); +$FileInfo = Onis::Data::Persistent->new ('FileInfo', 'inode', qw(mtime)); if (get_config ('purge_logs')) { @@ -167,15 +167,18 @@ for (get_config ('input')) } else { + my ($old_mtime) = $FileInfo->get ($inode); + print STDERR $/, __FILE__, ": ``$file'': " if ($::DEBUG & 0x200); - if (defined ($FILEINFO->{$inode}{'mtime'})) + + if (defined ($old_mtime)) { - if ($FILEINFO->{$inode}{'mtime'} == $mtime) + if ($old_mtime == $mtime) { print STDERR "File did not change. Skipping." if ($::DEBUG & 0x200); next; } - elsif ($FILEINFO->{$inode}{'mtime'} < $mtime) + elsif ($old_mtime < $mtime) { print STDERR "File changed. Reading it again." if ($::DEBUG & 0x200); } @@ -188,7 +191,7 @@ for (get_config ('input')) { print STDERR "File appears to be new. Reading it." if ($::DEBUG & 0x200); } - $FILEINFO->{$inode}{'mtime'} = $mtime; + $FileInfo->put ($inode, $mtime); } # truncate @@ -228,7 +231,7 @@ for (get_config ('input')) } } - newfile ($FILEINFO->{$inode}); + newfile ($FileInfo->{$inode}); while (<$logfile>) { s/\n|\r//g; @@ -279,7 +282,7 @@ for (get_config ('input')) { print STDERR $/, __FILE__, ": Unable to delete empty file ``$file'': $!"; } - delete ($FILEINFO->{$inode}); + delete ($FileInfo->{$inode}); } else { -- 2.11.0