61068e06b2f7e5df80cd4275b33627eca633edd6
[spider.git] / perl / Thingy.pm
1 #
2 # Thingy handling
3 #
4 # This is the new fundamental protocol engine handler
5 #
6 # $Id$
7 #
8 # Copyright (c) 2004 Dirk Koopman G1TLH
9 #
10
11 use strict;
12
13 package Thingy;
14
15 use vars qw($VERSION $BRANCH);
16 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
17 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
18 $main::build += $VERSION;
19 $main::branch += $BRANCH;
20
21 use DXChannel;
22 use DXDebug;
23
24 # we expect all thingies to be subclassed
25 sub new
26 {
27         my $class = shift;
28         my $thing = {@_};
29         
30         bless $thing, $class;
31         return $thing;
32 }
33
34 # send it out in the format asked for, if available
35 sub send
36 {
37         my $thing = shift;
38         my $chan = shift;
39         my $class;
40         if (@_) {
41                 $class = shift;
42         } elsif ($chan->isa('DXChannel')) {
43                 $class = ref $chan;
44         }
45
46         # generate the line which may (or not) be cached
47         my @out;
48         if (my $ref = $thing->{class}) {
49                 push @out, ref $ref ? @$ref : $ref;
50         } else {
51                 no strict 'refs';
52                 my $sub = "gen_$class";
53                 push @out, $thing->$sub() if $thing->can($sub);
54         }
55         $chan->send(@out) if @out;
56 }
57
58
59 1;
60