start with routing
[spider.git] / perl / Thingy.pm
index 885e7f0f5f4c0dc1a210a449390b5025978d7c87..87ee391adece15a8da1ac799ee2e0ca0be1867c1 100644 (file)
@@ -10,6 +10,8 @@
 
 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));
@@ -20,6 +22,8 @@ $main::branch += $BRANCH;
 use DXChannel;
 use DXDebug;
 
+use Thingy::Route;
+
 use vars qw(@queue);
 @queue = ();                                   # the thingy queue
 
@@ -29,7 +33,15 @@ sub new
        my $class = shift;
        my $self = {@_};
        
+       my ($type) = $class =~ /::(\w+)$/;
+       
        bless $self, $class;
+       $self->{_tonode} ||= '*';
+       $self->{_fromnode} ||= $main::mycall;
+       $self->{_hoptime} ||= 0;
+       while (my ($k,$v) = each %$self) {
+               delete $self->{$k} unless defined $v;
+       }
        return $self;
 }
 
@@ -44,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 = $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;