Commits

Shlomi Fish committed 736a369

Magic numbers -> constants in the ->Set return code.

See:

http://stackoverflow.com/questions/47882/

And Martin Fowler's "Refactoring book".

  • Participants
  • Parent commits 2eda85d

Comments (0)

Files changed (2)

lib/Mozbot/Constants.pm

+package Mozbot::Constants;
+
+use strict;
+use warnings;
+
+use base 'Exporter';
+
+# XXX : Maybe these should be Readonly:
+# http://search.cpan.org/dist/Readonly/
+
+our $SET_VAR__WRONG_FORMAT_FOR_ARRAY = 3;
+our $SET_VAR__WRONG_FORMAT_FOR_HASH = 4;
+
+our @EXPORT = (qw(
+    $SET_VAR__WRONG_FORMAT_FOR_ARRAY
+    $SET_VAR__WRONG_FORMAT_FOR_HASH
+));
+
+1;
+
     );
 }
 
+use Mozbot::Constants;
+
 # Set - called to set a variable to a particular value.
 sub Set {
     my $self = shift;
                     # XXX no feedback if nothing is done
                 }
             } else {
-                return 3; # not the right format dude!
+                # not the right format dude!
+                return $SET_VAR__WRONG_FORMAT_FOR_ARRAY;
             }
         } elsif (ref($self->{$variable}) eq 'HASH') {
             if ($value =~ /^\+(.)(.*)\1(.*)$/so) {
                 # XXX no feedback if nothing is done
                 delete($self->{$variable}->{$1});
             } else {
-                return 4; # not the right format dude!
+                # not the right format dude!
+                return $SET_VAR__WRONG_FORMAT_FOR_HASH; 
             }
         } else {
             return 1; # please to not be trying to set coderefs or arrayrefs or hashrefs or ...
 ################################
 
 package BotModules::Admin;
+
 use vars qw(@ISA);
 @ISA = qw(BotModules);
-1;
+
+use Mozbot::Constants;
 
 # Initialise - Called when the module is loaded
 sub Initialise {
         } else { # not known
             $self->_event_say("Module '$modulename' does not have a variable '$variable' as far as I can tell.");
         }
-    } elsif ($result == 3) {
+    } elsif ($result == $SET_VAR__WRONG_FORMAT_FOR_ARRAY) {
         $self->_event_say("Variable '$variable' is a list. To add to a list, please use the '+' symbol before the value (vars <module> <variable> '+<value>'). To remove from a list, use the '-' symbol (vars <module> <variable> '-<value>').");
-    } elsif ($result == 4) {
+    } elsif ($result == $SET_VAR__WRONG_FORMAT_FOR_HASH) {
         $self->_event_say("Variable '$variable' is a hash. To add to a hash, please use the '+' symbol before the '|key|value' pair (vars <module> <variable> '+|<key>|<value>').  The separator symbol ('|' in this example) could be anything. To remove from a list, use the '-' symbol (vars <module> <variable> '-<key>').");
     } elsif ($result == -1) {
         # already reported success