Просмотр исходного кода

Remove globals from the code, define these in the object instead, to be more
correct.

Also found a small bug in mbot.pm where it was written $^T instead of $^W.

Morten Brix Pedersen 25 лет назад
Родитель
Сommit
fea54026eb

+ 23 - 24
modules/Pisg/Parser/Format/Template.pm

@@ -1,32 +1,31 @@
-# This is a template for creating your own logfile parser.  After making the
-# necessary changes to the template, you will need to add the new module to
-# pisg.pl and add an entry for it in the choose_log_format subroutine.
+# This is a template for creating your own logfile parser. You can also look
+# in the other .pm files in this directory as good examples.
 
 package Pisg::Parser::Format::Template;
 
 use strict;
 $^W = 1;
 
-# These three variables are regular expressions for extracting information
-# from the logfile.  $normalline is for lines where the person merely said
-# something, $actionline is for lines where the person performed an action,
-# and# $thirdline matches everything else, including things like kicks, nick
+# The 3 variables in the new subrountine, 'normalline', 'actionline' and
+# 'thirdline' represents regular expressions for extracting information from
+# the logfile. normalline is for lines where the person merely said
+# something, actionline is for lines where the person performed an action,
+# and thirdline matches everything else, including things like kicks, nick
 # changes, and op grants.  See the thirdline subroutine for a list of
 # everything it should match.
-my $normalline = '';
-my $actionline = '';
-my $thirdline  = '';
 
-my ($debug);
-
-
-# The $debug subroutine needs to be passed to the module so output will go
-# to the correct file.
 sub new
 {
-    my $self = shift;
-    $debug = shift;
-    return bless {};
+    my $type = shift;
+    my $self = {
+        debug => $_[0],
+        normalline => '',
+        actionline => '',
+        thirdline  => '',
+    };
+
+    bless($self, $type);
+    return $self;
 }
 
 # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
@@ -35,8 +34,8 @@ sub normalline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$normalline/) {
-	$debug->("[$lines] Normal: $1 $2 $3");
+    if ($line =~ /$self->{normalline}/) {
+	$self->{debug}->("[$lines] Normal: $1 $2 $3");
 
 	# Most log formats are regular enough that you can just match the
 	# appropriate things with parentheses in the regular expression.
@@ -57,8 +56,8 @@ sub actionline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$actionline/) {
-	$debug->("[$lines] Action: $1 $2 $3");
+    if ($line =~ /$self->{actionline}/) {
+	$self->{debug}->("[$lines] Action: $1 $2 $3");
 
 	# Most log formats are regular enough that you can just match the
 	# appropriate things with parentheses in the regular expression.
@@ -93,8 +92,8 @@ sub thirdline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$thirdline/) {
-	$debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
+    if ($line =~ /$self->{thirdline}/) {
+	$self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
 
 	$hash{hour} = $1;
 	$hash{min}  = $2;

+ 16 - 17
modules/Pisg/Parser/Format/bxlog.pm

@@ -3,19 +3,18 @@ package Pisg::Parser::Format::bxlog;
 use strict;
 $^W = 1;
 
-
-my $normalline = '^\[\d+ \S+\/(\d+):\d+\] <([^>]+)> (.*)';
-my $actionline = '^\[\d+ \S+\/(\d+):\d+\] \* (\S+) (.*)';
-my $thirdline  = '^\[\d+ \S+\/(\d+):(\d+)\] ([<>@!]) (.*)';
-
-my ($debug);
-
-
 sub new
 {
-    my $self = shift;
-    $debug = shift;
-    return bless {};
+    my $type = shift;
+    my $self = {
+        debug => $_[0],
+        normalline => '^\[\d+ \S+\/(\d+):\d+\] <([^>]+)> (.*)',
+        actionline => '^\[\d+ \S+\/(\d+):\d+\] \* (\S+) (.*)',
+        thirdline => '^\[\d+ \S+\/(\d+):(\d+)\] ([<>@!]) (.*)'
+    };
+
+    bless($self, $type);
+    return $self;
 }
 
 sub normalline
@@ -24,8 +23,8 @@ sub normalline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$normalline/) {
-	$debug->("[$lines] Normal: $1 $2 $3");
+    if ($line =~ /$self->{normalline}/) {
+	$self->{debug}->("[$lines] Normal: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -43,8 +42,8 @@ sub actionline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$actionline/) {
-	$debug->("[$lines] Action: $1 $2 $3");
+    if ($line =~ /$self->{actionline}/) {
+	$self->{debug}->("[$lines] Action: $1 $2 $3");
 
 	$hash{hour}    = $1;
 	$hash{nick}   = $2;
@@ -73,8 +72,8 @@ sub thirdline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$thirdline/) {
-	$debug->("[$lines] ***: $1 $2 $3 $4");
+    if ($line =~ /$self->{thirdline}/) {
+	$self->{debug}->("[$lines] ***: $1 $2 $3 $4");
 
 	$hash{hour} = $1;
 	$hash{min}  = $2;

+ 17 - 18
modules/Pisg/Parser/Format/eggdrop.pm

@@ -3,19 +3,18 @@ package Pisg::Parser::Format::eggdrop;
 use strict;
 $^W = 1;
  
-
-my $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
-my $actionline = '^\[(\d+):\d+\] Action: (\S+) (.*)';
-my $thirdline  = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+)(.*)';
-
-my ($debug);
-
-
 sub new
 {
-    my $self = shift;
-    $debug = shift;
-    return bless {};
+    my $type = shift;
+    my $self = {
+        debug => $_[0],
+        normalline => '^\[(\d+):\d+\] <([^>]+)> (.*)',
+        actionline => '^\[(\d+):\d+\] Action: (\S+) (.*)',
+        thirdline  => '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+)(.*)',
+    };
+
+    bless($self, $type);
+    return $self;
 }
 
 sub normalline
@@ -24,8 +23,8 @@ sub normalline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$normalline/) {
-	$debug->("[$lines] Normal: $1 $2 $3");
+    if ($line =~ /$self->{normalline}/) {
+	$self->{debug}->("[$lines] Normal: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -43,8 +42,8 @@ sub actionline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$actionline/) {
-	$debug->("[$lines] Action: $1 $2 $3");
+    if ($line =~ /$self->{actionline}/) {
+	$self->{debug}->("[$lines] Action: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -76,11 +75,11 @@ sub thirdline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$thirdline/) {
+    if ($line =~ /$self->{thirdline}/) {
 	if (defined $7) {
-	    $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
+	    $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
 	} else {
-	    $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6");
+	    $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6");
 	}
 
 	$hash{hour} = $1;

+ 17 - 17
modules/Pisg/Parser/Format/grufti.pm

@@ -3,18 +3,18 @@ package Pisg::Parser::Format::grufti;
 use strict;
 $^W = 1;
 
-my $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
-my $actionline = '^\[(\d+):\d+\] \* (\S+) (.*)';
-my $thirdline  = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
-
-my ($debug);
-
-
 sub new
 {
-    my $self = shift;
-    $debug = shift;
-    return bless {};
+    my $type = shift;
+    my $self = {
+        debug => $_[0],
+        normalline => '^\[(\d+):\d+\] <([^>]+)> (.*)',
+        actionline => '^\[(\d+):\d+\] \* (\S+) (.*)',
+        thirdline  => '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)(.*)',
+    };
+
+    bless($self, $type);
+    return $self;
 }
 
 sub normalline
@@ -23,8 +23,8 @@ sub normalline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$normalline/) {
-	$debug->("[$lines] Normal: $1 $2 $3");
+    if ($line =~ /$self->{normalline}/) {
+	$self->{debug}->("[$lines] Normal: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -42,8 +42,8 @@ sub actionline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$actionline/) {
-	$debug->("[$lines] Action: $1 $2 $3");
+    if ($line =~ /$self->{actionline}/) {
+	$self->{debug}->("[$lines] Action: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -72,11 +72,11 @@ sub thirdline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$thirdline/) {
+    if ($line =~ /$self->{thirdline}/) {
 	if (defined $9) {
-	    $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
+	    $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
 	} else {
-	    $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8");
+	    $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8");
 	}
 
 	$hash{hour} = $1;

+ 17 - 17
modules/Pisg/Parser/Format/irssi.pm

@@ -3,18 +3,18 @@ package Pisg::Parser::Format::irssi;
 use strict;
 $^W = 1;
 
-my $normalline = '^(\d+):\d+ <.([^>]+)> (.*)';
-my $actionline = '^(\d+):\d+  \* (\S+) (.*)';
-my $thirdline  = '^(\d+):(\d+) -\!- (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
-
-my ($debug);
-
-
 sub new
 {
-    my $self = shift;
-    $debug = shift;
-    return bless {};
+    my $type = shift;
+    my $self = {
+        debug => $_[0],
+        normalline => '^(\d+):\d+ <.([^>]+)> (.*)',
+        actionline => '^(\d+):\d+  \* (\S+) (.*)',
+        thirdline  => '^(\d+):(\d+) -\!- (\S+) (\S+) (\S+) (\S+) (\S+)(.*)',
+    };
+
+    bless($self, $type);
+    return $self;
 }
 
 sub normalline
@@ -23,8 +23,8 @@ sub normalline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$normalline/) {
-        $debug->("[$lines] Normal: $1 $2 $3");
+    if ($line =~ /$self->{normalline}/) {
+        $self->{debug}->("[$lines] Normal: $1 $2 $3");
 
         $hash{hour}   = $1;
         $hash{nick}   = $2;
@@ -42,8 +42,8 @@ sub actionline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$actionline/) {
-        $debug->("[$lines] Action: $1 $2 $3");
+    if ($line =~ /$self->{actionline}/) {
+        $self->{debug}->("[$lines] Action: $1 $2 $3");
 
         $hash{hour}   = $1;
         $hash{nick}   = $2;
@@ -72,11 +72,11 @@ sub thirdline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$thirdline/) {
+    if ($line =~ /$self->{thirdline}/) {
         if (defined $8) {
-            $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8");
+            $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8");
         } else {
-            $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
+            $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
         }
 
         $hash{hour} = $1;

+ 17 - 17
modules/Pisg/Parser/Format/mIRC.pm

@@ -3,18 +3,18 @@ package Pisg::Parser::Format::mIRC;
 use strict;
 $^W = 1;
 
-my $normalline = '^\[(\d+):\d+[^ ]+ <([^>]+)> (.*)';
-my $actionline = '^\[(\d+):\d+[^ ]+ \* (\S+) (.*)';
-my $thirdline  = '^\[(\d+):(\d+)[^ ]+ \*\*\* (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
-
-my ($debug);
-
-
 sub new
 {
-    my $self = shift;
-    $debug = shift;
-    return bless {};
+    my $type = shift;
+    my $self = {
+        debug => $_[0],
+        normalline => '^\[(\d+):\d+[^ ]+ <([^>]+)> (.*)',
+        actionline => '^\[(\d+):\d+[^ ]+ \* (\S+) (.*)',
+        thirdline  => '^\[(\d+):(\d+)[^ ]+ \*\*\* (\S+) (\S+) (\S+) (\S+) (\S+)(.*)',
+    };
+
+    bless($self, $type);
+    return $self;
 }
 
 sub normalline
@@ -23,8 +23,8 @@ sub normalline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$normalline/) {
-	$debug->("[$lines] Normal: $1 $2 $3");
+    if ($line =~ /$self->{normalline}/) {
+	$self->{debug}->("[$lines] Normal: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -42,8 +42,8 @@ sub actionline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$actionline/) {
-	$debug->("[$lines] Action: $1 $2 $3");
+    if ($line =~ /$self->{actionline}/) {
+	$self->{debug}->("[$lines] Action: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -72,11 +72,11 @@ sub thirdline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$thirdline/) {
+    if ($line =~ /$self->{thirdline}/) {
 	if (defined $8) {
-	    $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8");
+	    $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8");
 	} else {
-	    $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
+	    $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
 	}
 
 	$hash{hour} = $1;

+ 17 - 18
modules/Pisg/Parser/Format/mbot.pm

@@ -1,21 +1,20 @@
 package Pisg::Parser::Format::mbot;
 
 use strict;
-$^T = 1;
-
-
-my $normalline = '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> (?!\001ACTION)(.*)';
-my $actionline = '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> \001ACTION (.*)\001$';
-my $thirdline  = '^\S+ \S+ \d+ (\d+):(\d+):\d+ \d+ (\S+) (\S+) ?(\S*) ?(\S*) ?(.*)';
-
-my ($debug);
-
+$^W = 1;
 
 sub new
 {
-    my $self = shift;
-    $debug = shift;
-    return bless {};
+    my $type = shift;
+    my $self = {
+        debug => $_[0],
+        normalline => '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> (?!\001ACTION)(.*)',
+        actionline => '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> \001ACTION (.*)\001$',
+        thirdline  => '^\S+ \S+ \d+ (\d+):(\d+):\d+ \d+ (\S+) (\S+) ?(\S*) ?(\S*) ?(.*)',
+    };
+
+    bless($self, $type);
+    return $self;
 }
 
 sub normalline
@@ -24,8 +23,8 @@ sub normalline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$normalline/) {
-	$debug->("[$lines] Normal: $1 $2 $3");
+    if ($line =~ /$self->{normalline}/) {
+	$self->{debug}->("[$lines] Normal: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -43,8 +42,8 @@ sub actionline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$actionline/) {
-	$debug->("[$lines] Action: $1 $2 $3");
+    if ($line =~ /$self->{actionline}/) {
+	$self->{debug}->("[$lines] Action: $1 $2 $3");
 
 	$hash{hour}   = $1;
 	$hash{nick}   = $2;
@@ -73,12 +72,12 @@ sub thirdline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$thirdline/) {
+    if ($line =~ /$self->{thirdline}/) {
 	my $debugstring = "[$lines] ***: $1 $2 $3 $4";
 	$debugstring .= " $5" if (defined $5);
 	$debugstring .= " $6" if (defined $6);
 	$debugstring .= " $7" if (defined $7);
-	$debug->($debugstring);
+	$self->{debug}->($debugstring);
 
 	$hash{hour} = $1;
 	$hash{min}  = $2;

+ 16 - 18
modules/Pisg/Parser/Format/xchat.pm

@@ -3,20 +3,18 @@ package Pisg::Parser::Format::xchat;
 use strict;
 $^W = 1;
 
-
-my $normalline = '^(\d+):\d+:\d+ <([^>]+)>\s+(.*)';
-my $actionline = '^(\d+):\d+:\d+ \*\s+(\S+) (.*)';
-my $thirdline  = '^(\d+):(\d+):\d+ .--\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)';
-
-my ($debug);
-
-# Preloaded methods go here.
-
 sub new
 {
-    my $self = shift;
-    $debug = shift;
-    return bless {};
+    my $type = shift;
+    my $self = {
+        debug => $_[0],
+        normalline => '^(\d+):\d+:\d+ <([^>]+)>\s+(.*)',
+        actionline => '^(\d+):\d+:\d+ \*\s+(\S+) (.*)',
+        thirdline  => '^(\d+):(\d+):\d+ .--\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)',
+    };
+
+    bless($self, $type);
+    return $self;
 }
 
 sub normalline
@@ -25,8 +23,8 @@ sub normalline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$normalline/) {
-	$debug->("[$lines] Normal: $1 $2 $3");
+    if ($line =~ /$self->{normalline}/) {
+	$self->{debug}->("[$lines] Normal: $1 $2 $3");
 
 	$hash{hour} = $1;
 	$hash{nick} = $2;
@@ -44,8 +42,8 @@ sub actionline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$actionline/) {
-	$debug->("[$lines] Action: $1 $2 $3");
+    if ($line =~ /$self->{actionline}/) {
+	$self->{debug}->("[$lines] Action: $1 $2 $3");
 
 	$hash{hour} = $1;
 	$hash{nick} = $2;
@@ -74,8 +72,8 @@ sub thirdline
     my ($self, $line, $lines) = @_;
     my %hash;
 
-    if ($line =~ /$thirdline/) {
-	$debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
+    if ($line =~ /$self->{thirdline}/) {
+	$self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
 
 	$hash{hour} = $1;
 	$hash{min} = $2;