X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FThingy.pm;h=f10467986dcb0d4215f591bfa4b881b61ef3567b;hb=b9dffeff7239952814342dad19db3a51def6fab7;hp=885e7f0f5f4c0dc1a210a449390b5025978d7c87;hpb=584945a122922aebe94f733c8f9a734f412aa5cb;p=spider.git diff --git a/perl/Thingy.pm b/perl/Thingy.pm index 885e7f0f..f1046798 100644 --- a/perl/Thingy.pm +++ b/perl/Thingy.pm @@ -8,44 +8,47 @@ # Copyright (c) 2004 Dirk Koopman G1TLH # -package Thingy; - -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)); -$main::build += $VERSION; -$main::branch += $BRANCH; +use strict; +package Thingy; use DXChannel; use DXDebug; -use vars qw(@queue); -@queue = (); # the thingy 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;