Prepare for git repository
[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 DXChannel;
16 use DXDebug;
17
18 # we expect all thingies to be subclassed
19 sub new
20 {
21         my $class = shift;
22         my $thing = {@_};
23         
24         bless $thing, $class;
25         return $thing;
26 }
27
28 # send it out in the format asked for, if available
29 sub send
30 {
31         my $thing = shift;
32         my $chan = shift;
33         my $class;
34         if (@_) {
35                 $class = shift;
36         } elsif ($chan->isa('DXChannel')) {
37                 $class = ref $chan;
38         }
39
40         # generate the line which may (or not) be cached
41         my @out;
42         if (my $ref = $thing->{class}) {
43                 push @out, ref $ref ? @$ref : $ref;
44         } else {
45                 no strict 'refs';
46                 my $sub = "gen_$class";
47                 push @out, $thing->$sub() if $thing->can($sub);
48         }
49         $chan->send(@out) if @out;
50 }
51
52
53 1;
54