1. Added an efficiency thing for AUTOLOADed accessors from OO Perl by Conway.
[spider.git] / perl / DXCluster.pm
index aee8fe4d94a0c6a0e1c192fb1d94d836b705edd1..2160846547e9e542b5c80413c3bc8c1201e46ccf 100644 (file)
 
 package DXCluster;
 
-use Exporter;
-@ISA = qw(Exporter);
 use DXDebug;
-use Carp;
+use DXUtil;
 
 use strict;
 use vars qw(%cluster %valid);
@@ -25,13 +23,13 @@ use vars qw(%cluster %valid);
 %cluster = ();                                 # this is where we store the dxcluster database
 
 %valid = (
-                 mynode => '0,Parent Node,showcall',
+                 mynode => '0,Parent Node,DXCluster::showcall',
                  call => '0,Callsign',
                  confmode => '0,Conference Mode,yesno',
                  here => '0,Here?,yesno',
-                 dxchan => '5,Channel ref',
+                 dxchan => '5,Channel ref,DXCluster::showcall',
                  pcversion => '5,Node Version',
-                 list => '5,User List,dolist',
+                 list => '5,User List,DXCluster::dolist',
                  users => '0,No of Users',
                 );
 
@@ -102,6 +100,14 @@ sub field_prompt
        my ($self, $ele) = @_;
        return $valid{$ele};
 }
+#
+# return a list of valid elements 
+# 
+
+sub fields
+{
+       return keys(%valid);
+}
 
 # this expects a reference to a list in a node NOT a ref to a node 
 sub dolist
@@ -110,7 +116,8 @@ sub dolist
        my $out;
        my $ref;
   
-       foreach $ref (@{$self}) {
+       foreach my $call (keys %{$self}) {
+               $ref = $$self{$call};
                my $s = $ref->{call};
                $s = "($s)" if !$ref->{here};
                $out .= "$s ";
@@ -146,6 +153,9 @@ sub AUTOLOAD
        $name =~ s/.*:://o;
   
        confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
+       # this clever line of code creates a subroutine which takes over from autoload
+       # from OO Perl - Conway
+       *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
        @_ ? $self->{$name} = shift : $self->{$name} ;
 }