From 1bc035c900ac26294b6031bf45c28c15cca44ae3 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Fri, 12 Mar 2010 14:36:53 -0500 Subject: [PATCH] removing the symbol table hackery, working slowly on some other cleanup --- plugins/factoids.pm | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/plugins/factoids.pm b/plugins/factoids.pm index 0ff70ea..6e65ea8 100644 --- a/plugins/factoids.pm +++ b/plugins/factoids.pm @@ -22,6 +22,21 @@ use Data::Dumper; my $COPULA = join '|', qw/is are was isn't were being am/, "to be", "will be", "has been", "have been", "shall be", "can has", "wus liek", "iz liek", "used to be"; my $COPULA_RE = qr/\b(?:$COPULA)\b/i; +#this is a hash that gives all the commands their names and functions, added to avoid some symbol table funkery that happened originally. +my %commandhash = ( + "" => \&get_fact, + "forget" => \&get_fact_forget, + "learn" => \&get_fact_learn, + "relearn" => \&get_fact_learn, + "literal" => \&get_fact_literal, + "protect" => \&get_fact_protect, + "revert" => \&get_fact_revert, + "revisions" => \&get_fact_revisions, + "search" => \&get_fact_search, + "unprotect" => \&get_fact_unprotect, + ); + + sub new { my( $class ) = @_; @@ -103,14 +118,14 @@ sub command { return( 'handled', "Stored @ret" ); } else { - my $commands_re = join '|', qw/search relearn learn forget revisions literal revert protect unprotect/; - $commands_re = qr/$commands_re/; + my $commands_re = join '|', keys %commandhash; + $commands_re = qr/$commands_re/; my $fact_string; if( !$call_only && $subject =~ s/^\s*($commands_re)\s+// ) { - my( $cmd_name ) = "get_fact_$1"; - $fact_string = $self->$cmd_name($subject, $said->{name}, $said); + #i lost the object oriented calling here, but i don't care too much, BECAUSE this avoids using strings for the calling, i might change that. + $fact_string = $commandhash{$1}->($self,$subject, $said->{name}, $said); } else { $fact_string = $self->get_fact( $pm, $said, $subject, $said->{name}, $call_only ); @@ -353,10 +368,6 @@ sub get_fact_learn { return "Stored $subject as $predicate"; } -{no warnings 'once'; #keep perl from complaining about this only being used once -*get_fact_relearn = \&get_fact_learn; #Alias.. -} - sub get_fact_search { my( $self, $body, $name ) = @_;