X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FThingy.pm;h=61068e06b2f7e5df80cd4275b33627eca633edd6;hb=510a9f0644b3a0e02f5951702ada39616bfcfc2f;hp=cf057957c8e7e415149b3d1aaef036f672b796a4;hpb=1284d2e7cc4c25bb02c7f4fa7c59246de9c0027c;p=spider.git diff --git a/perl/Thingy.pm b/perl/Thingy.pm index cf057957..61068e06 100644 --- a/perl/Thingy.pm +++ b/perl/Thingy.pm @@ -8,6 +8,8 @@ # Copyright (c) 2004 Dirk Koopman G1TLH # +use strict; + package Thingy; use vars qw($VERSION $BRANCH); @@ -16,35 +18,43 @@ $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)) $main::build += $VERSION; $main::branch += $BRANCH; - use DXChannel; use DXDebug; -our @queue; - # we expect all thingies to be subclassed sub new { my $class = shift; - my $self = {@_}; + my $thing = {@_}; - bless $self, $class; - return $self; + bless $thing, $class; + return $thing; } -# add the Thingy to the queue -sub add +# send it out in the format asked for, if available +sub send { - push @queue, shift; + my $thing = shift; + my $chan = shift; + my $class; + if (@_) { + $class = shift; + } elsif ($chan->isa('DXChannel')) { + $class = ref $chan; + } + + # generate the line which may (or not) be cached + my @out; + if (my $ref = $thing->{class}) { + push @out, ref $ref ? @$ref : $ref; + } else { + no strict 'refs'; + my $sub = "gen_$class"; + push @out, $thing->$sub() if $thing->can($sub); + } + $chan->send(@out) if @out; } -# dispatch Thingies to action it. -sub process -{ - my $t = pop @queue if @queue; - - $t->process if $t; -} 1;