X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=lib%2FOnis%2FData%2FCore.pm;h=701e08634b3827b6d069a4c295542d30638cb6e8;hb=ca16504096dbade16df66456ad23a2cc18fd18de;hp=4e7e05be44eb86f0f24a04361f47ca528d99417b;hpb=2dfc95bddb9ea3e5c85503b1e6f529c4945cfe30;p=onis.git diff --git a/lib/Onis/Data/Core.pm b/lib/Onis/Data/Core.pm index 4e7e05b..701e086 100644 --- a/lib/Onis/Data/Core.pm +++ b/lib/Onis/Data/Core.pm @@ -34,7 +34,8 @@ the F defines a mapping of B -E B. =cut -our $Nick2Ident = Onis::Data::Persistent->new ('Nick2Ident', 'nick', 'ident'); +our $GeneralCounters = Onis::Data::Persistent->new ('GeneralCounters', 'key', 'value'); +our $NickToIdentCache = Onis::Data::Persistent->new ('NickToIdentCache', 'nick', 'ident'); our $ChatterList = Onis::Data::Persistent->new ('ChatterList', 'chatter', 'counter'); our $ChannelNames = Onis::Data::Persistent->new ('ChannelNames', 'channel', 'counter'); @@ -47,19 +48,16 @@ qw( ); @Onis::Data::Core::ISA = ('Exporter'); +our $LinesThisRun = 0; + our $PluginCallbacks = {}; -our $OUTPUT = []; +our $OutputCallbacks = []; our @AllNicks = (); -our @ALLNAMES = (); our %NickToNick = (); our %NickToIdent = (); our %IdentToNick = (); -our $LASTRUN_DAYS = 0; - - - our $UNSHARP = 'MEDIUM'; if (get_config ('unsharp')) { @@ -137,14 +135,14 @@ sub store $data->{'user'} = $user; $data->{'ident'} = $ident; - $Nick2Ident->put ($nick, $ident); + $NickToIdentCache->put ($nick, $ident); $chatter = "$nick!$ident"; ($counter) = $ChatterList->get ($chatter); $counter ||= 0; $counter++; $ChatterList->put ($chatter, $counter); } - elsif (($ident) = $Nick2Ident->get ($nick)) + elsif (($ident) = $NickToIdentCache->get ($nick)) { my $chatter = "$nick!$ident"; my $counter; @@ -195,8 +193,14 @@ sub store } } - # TODO - #$DATA->{'total_lines'}++; + { + my ($counter) = $GeneralCounters->get ('lines_total'); + $counter ||= 0; + $counter++; + $GeneralCounters->put ('lines_total', $counter); + + $LinesThisRun++; + } if (defined ($PluginCallbacks->{$type})) { @@ -577,7 +581,7 @@ sub nick_to_ident } else { - ($ident) = $Nick2Ident->get ($nick); + ($ident) = $NickToIdentCache->get ($nick); $ident ||= ''; } @@ -634,8 +638,11 @@ Returns the total number of lines parsed so far. sub get_total_lines { - # TODO - #return ($DATA->{'total_lines'}); + my ($total) = $GeneralCounters->get ('lines_total'); + + return (qw()) unless ($total); + + return ($total, $LinesThisRun); } =item B (I<$old_nick>, I<$new_nick>) @@ -650,11 +657,11 @@ sub nick_rename my $new_nick = shift; my $ident; - ($ident) = $Nick2Ident->get ($old_nick); + ($ident) = $NickToIdentCache->get ($old_nick); if (defined ($ident) and ($ident)) { - $Nick2Ident->put ($new_nick, $ident); + $NickToIdentCache->put ($new_nick, $ident); } } @@ -667,7 +674,7 @@ Print the output. Should be called only once.. sub print_output { # FIXME FIXME FIXME - if (!get_total_lines () and 0) + if (!get_total_lines ()) { print STDERR <<'MESSAGE'; @@ -684,7 +691,7 @@ MESSAGE calculate_nicks (); - for (@$OUTPUT) + for (@$OutputCallbacks) { &$_ (); } @@ -711,7 +718,7 @@ sub register_plugin if ($type eq 'OUTPUT') { - push (@$OUTPUT, $sub_ref); + push (@$OutputCallbacks, $sub_ref); } else {