add more code gradually
[spider.git] / perl / Thingy.pm
index cf057957c8e7e415149b3d1aaef036f672b796a4..785428cf42c6d7365a9d125405716c7de8e85ba9 100644 (file)
 
 package Thingy;
 
+use strict;
+
 use vars qw($VERSION $BRANCH);
 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
-$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/,(0,0));
 $main::build += $VERSION;
 $main::branch += $BRANCH;
 
@@ -20,7 +22,11 @@ $main::branch += $BRANCH;
 use DXChannel;
 use DXDebug;
 
-our @queue;
+use Thingy::Hi;
+use Thingy::Route;
+
+use vars qw(@queue);
+@queue = ();                                   # the thingy queue
 
 # we expect all thingies to be subclassed
 sub new
@@ -28,12 +34,19 @@ sub new
        my $class = shift;
        my $self = {@_};
        
+       my ($type) = $class =~ /::(\w+)$/;
+       
        bless $self, $class;
+       $self->{_tonode} ||= '*';
+       $self->{_fromnode} ||= $main::mycall;
+       while (my ($k,$v) = each %$self) {
+               delete $self->{$k} unless defined $v;
+       }
        return $self;
 }
 
 # add the Thingy to the queue
-sub add
+sub queue
 {
        push @queue, shift;
 }
@@ -43,7 +56,22 @@ sub process
 {
        my $t = pop @queue if @queue;
 
-       $t->process if $t;
+       if ($t) {
+
+               # go directly to this class's t= handler if there is one
+               my $type = lc $t->{t};
+               if ($type) {
+                       # remove extraneous characters put there by the ungodly
+                       $type =~ s/[^\w]//g;
+                       $type = 'handle_' . $type;
+                       if ($t->can($type)) {
+                               no strict 'refs';
+                               $t->$type;
+                               return;
+                       }
+               }
+               $t->normal;
+       }
 }
 
 1;