X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FThingy.pm;h=785428cf42c6d7365a9d125405716c7de8e85ba9;hb=refs%2Fremotes%2Fserver%2Fspider2;hp=cf057957c8e7e415149b3d1aaef036f672b796a4;hpb=1284d2e7cc4c25bb02c7f4fa7c59246de9c0027c;p=spider.git diff --git a/perl/Thingy.pm b/perl/Thingy.pm index cf057957..785428cf 100644 --- a/perl/Thingy.pm +++ b/perl/Thingy.pm @@ -10,9 +10,11 @@ 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;