From: octo Date: Sun, 10 Apr 2005 12:09:11 +0000 (+0000) Subject: Fixed syntactic errors in Onis::Plugins::Core, Onis::Data::Persistent::None, Onis... X-Git-Tag: Release-0.8.0~20^2~36 X-Git-Url: https://git.octo.it/?p=onis.git;a=commitdiff_plain;h=f980a0f03f3f7727a602b94251f8d6d1e3a15178 Fixed syntactic errors in Onis::Plugins::Core, Onis::Data::Persistent::None, Onis::Data::Core, Onis::Data::Persistent and Onis::Users --- diff --git a/lib/Onis/Data/Core.pm b/lib/Onis/Data/Core.pm index 6e33224..e505dc4 100644 --- a/lib/Onis/Data/Core.pm +++ b/lib/Onis/Data/Core.pm @@ -43,12 +43,10 @@ qw( store unsharp calculate_nicks get_all_nicks get_channel get_main_nick nick_to_ident ident_to_nick - get_total_lines nick_rename print_output register_plugin merge_idents + get_total_lines nick_rename print_output register_plugin ); @Onis::Data::Core::ISA = ('Exporter'); -our $DATA = init ('$DATA', 'hash'); - our $PluginCallbacks = {}; our $OUTPUT = []; our @AllNicks = (); @@ -82,30 +80,9 @@ if (get_config ('unsharp')) } } -if (!%$DATA) -{ - $DATA->{'idents_of_nick'} = {}; - $DATA->{'channel'} = {}; - $DATA->{'total_lines'} = 0; -} - -if (defined ($DATA->{'lastrun'})) -{ - my $last = $DATA->{'lastrun'}; - my $now = time; - - my $diff = ($now - $last) % 86400; - - if ($diff > 0) - { - $DATA->{'lastrun'} = $now; - $LASTRUN_DAYS = $diff; - } -} -else -{ - $DATA->{'lastrun'} = time; -} +# TODO +# - lastrun +# - total lines my $VERSION = '$Id: Core.pm,v 1.14 2004/10/31 15:00:32 octo Exp $'; print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG); @@ -170,6 +147,7 @@ sub store elsif (($ident) = $Nick2Ident->get ($nick)) { my $chatter = "$nick!$ident"; + my $counter; ($user, $host) = split (m/@/, $ident); $data->{'host'} = $host; @@ -217,7 +195,7 @@ sub store } } - # FIXME + # TODO #$DATA->{'total_lines'}++; if (defined ($PluginCallbacks->{$type})) @@ -349,8 +327,8 @@ sub calculate_nicks my $name = ident_to_name ($ident); my ($counter) = $ChatterList->get ($chatter); - $nicks->{$nick}{$temp} = 0 unless (defined ($nicks->{$nick}{$temp})); - $nicks->{$nick}{$temp} += $counter; + $nicks->{$nick}{$ident} = 0 unless (defined ($nicks->{$nick}{$ident})); + $nicks->{$nick}{$ident} += $counter; } for (keys %$nicks) @@ -392,12 +370,12 @@ sub calculate_nicks if ($this_ident ne 'unidentified') { - if ($name) + if ($this_name) { - $name2nick->{$this_name}{$this_nick} = 0 unless (defined ($names->{$this_name}{$this_nick})); + $name2nick->{$this_name}{$this_nick} = 0 unless (defined ($name2nick->{$this_name}{$this_nick})); $name2nick->{$this_name}{$this_nick} += $this_total; - $name2ident->{$this_name}{$this_ident} = 0 unless (defined ($names->{$this_name}{$this_ident})); + $name2ident->{$this_name}{$this_ident} = 0 unless (defined ($name2nick->{$this_name}{$this_ident})); $name2ident->{$this_name}{$this_ident} += $this_total; } else @@ -634,7 +612,8 @@ Returns the total number of lines parsed so far. sub get_total_lines { - return ($DATA->{'total_lines'}); + # TODO + #return ($DATA->{'total_lines'}); } =item B (I<$old_nick>, I<$new_nick>) @@ -665,7 +644,7 @@ Print the output. Should be called only once.. sub print_output { - if (!$DATA->{'total_lines'}) + if (!get_total_lines ()) { print STDERR <<'MESSAGE'; @@ -681,14 +660,11 @@ MESSAGE } calculate_nicks (); - merge_idents (); for (@$OUTPUT) { &$_ (); } - - delete ($DATA->{'byname'}); } =item I<$data> = B (I<$type>, I<$sub_ref>) @@ -727,97 +703,6 @@ sub register_plugin print STDERR $/, __FILE__, ': ', scalar (caller ()), " registered for ``$type''." if ($::DEBUG & 0x800); } -=item B () - -Merges idents. Does magic, don't interfere ;) - -=cut - -sub merge_idents -{ - my @idents = keys (%IdentToNick); - - for (@idents) - { - my $ident = $_; - my $name = ident_to_name ($ident); - - if (!defined ($DATA->{'byident'}{$ident})) - { - next; - } - - if (!defined ($DATA->{'byname'}{$name})) - { - $DATA->{'byname'}{$name} = {}; - } - - add_hash ($DATA->{'byname'}{$name}, $DATA->{'byident'}{$ident}); - } -} - -sub add_hash -{ - my $dst = shift; - my $src = shift; - - my @keys = keys (%$src); - - for (@keys) - { - my $key = $_; - my $val = $src->{$key}; - - if (!defined ($dst->{$key})) - { - $dst->{$key} = $val; - } - elsif (!ref ($val)) - { - if ($val =~ m/\D/) - { - # FIXME - print STDERR $/, __FILE__, ": ``$key'' = ``$val''" if ($::DEBUG); - } - else - { - $dst->{$key} += $val; - } - } - elsif (ref ($val) ne ref ($dst->{$key})) - { - print STDERR $/, __FILE__, ": Destination and source type do not match!" if ($::DEBUG); - } - elsif (ref ($val) eq "HASH") - { - add_hash ($dst->{$key}, $val); - } - elsif (ref ($val) eq "ARRAY") - { - my $i = 0; - for (@$val) - { - my $j = $_; - if ($j =~ m/\D/) - { - # FIXME - print STDERR $/, __FILE__, ": ``", $key, '[', $i, "]'' = ``$j''" if ($::DEBUG); - } - else - { - $dst->{$key}->[$i] += $j; - } - $i++; - } - } - else - { - my $type = ref ($val); - print STDERR $/, __FILE__, ": Reference type ``$type'' is not supported!", $/; - } - } -} - =back =head1 AUTHOR diff --git a/lib/Onis/Data/Persistent.pm b/lib/Onis/Data/Persistent.pm index eb53355..8c08f28 100644 --- a/lib/Onis/Data/Persistent.pm +++ b/lib/Onis/Data/Persistent.pm @@ -56,13 +56,14 @@ if (get_config ('storage_module')) if ($@) { print STDERR $/, __FILE__, ": Could not load storage module ``$StoreModule''. Are you sure it exists?"; + print STDERR $/, __FILE__, ": Error while loading was: $@"; exit (1); } unshift (@Onis::Data::Persistent::ISA, $mod_name); } -return (0); +return (1); =head1 INTERFACE diff --git a/lib/Onis/Data/Persistent/None.pm b/lib/Onis/Data/Persistent/None.pm index 5532561..b9a7020 100644 --- a/lib/Onis/Data/Persistent/None.pm +++ b/lib/Onis/Data/Persistent/None.pm @@ -107,14 +107,14 @@ sub keys push (@field_indizes, $obj->{'field_index'}{$field}); } - return (sort (sub - { + return (sort + sub { for (@field_indizes) { my $d = $obj->{'data'}{$a}[$_] cmp $obj->{'data'}{$b}[$_]; return ($d) if ($d); } - }, @keys)); + }, @keys); } =head1 AUTHOR diff --git a/lib/Onis/Plugins/Core.pm b/lib/Onis/Plugins/Core.pm index b8e3571..3f01666 100644 --- a/lib/Onis/Plugins/Core.pm +++ b/lib/Onis/Plugins/Core.pm @@ -44,7 +44,7 @@ our $NickCharsCounter = Onis::Data::Persistent->new ('NickCharsCounter', 'nick', our $QuoteCache = {}; # Saves per-nick information without any modification our $QuoteData = {}; # Is generated before output. Nicks are merged according to Data::Core. -our $NickData = {}: # Same as above, but for nicks rather than quotes. +our $NickData = {}; # Same as above, but for nicks rather than quotes. our @H_IMAGES = qw#dark-theme/h-red.png dark-theme/h-blue.png dark-theme/h-yellow.png dark-theme/h-green.png#; our $QuoteCacheSize = 10; @@ -273,7 +273,7 @@ sub add { @counter = qw(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0); } - $counter[$hour]++ + $counter[$hour]++; $NickLinesCounter->put ($nick, @counter); @counter = $NickWordsCounter->get ($nick); @@ -721,7 +721,7 @@ EOF $total = $NickData->{$nick}{'chars_total'}; } - my $title = $realname; + my $title = $name ? get_realname ($name) : ''; if (!$title) { $title = "User: $name; " if ($name); diff --git a/lib/Onis/Users.pm b/lib/Onis/Users.pm index d8be529..9b07f15 100644 --- a/lib/Onis/Users.pm +++ b/lib/Onis/Users.pm @@ -7,7 +7,11 @@ use Onis::Config qw#get_config#; use Onis::Data::Core qw(nick_to_ident); use Onis::Data::Persistent; -@Onis::Users::EXPORT_OK = qw#host_to_username nick_to_username get_link get_image get_realname#; +@Onis::Users::EXPORT_OK = +(qw( + ident_to_name chatter_to_name nick_to_name name_to_ident + get_realname get_link get_image +)); @Onis::Users::ISA = ('Exporter'); =head1 NAME