improve help for grepdbg and watchdbg
[spider.git] / perl / DXChannel.pm
1 #
2 # module to manage channel lists & data
3 #
4 # This is the base class for all channel operations, which is everything to do 
5 # with input and output really.
6 #
7 # The instance variable in the outside world will be generally be called $dxchan
8 #
9 # This class is 'inherited' (if that is the goobledegook for what I am doing)
10 # by various other modules. The point to understand is that the 'instance variable'
11 # is in fact what normal people would call the state vector and all useful info
12 # about a connection goes in there.
13 #
14 # Another point to note is that a vector may contain a list of other vectors. 
15 # I have simply added another variable to the vector for 'simplicity' (or laziness
16 # as it is more commonly called)
17 #
18 # PLEASE NOTE - I am a C programmer using this as a method of learning perl
19 # firstly and OO about ninthly (if you don't like the design and you can't 
20 # improve it with better OO and thus make it smaller and more efficient, then tough). 
21 #
22 # Copyright (c) 1998-2016 - Dirk Koopman G1TLH
23 #
24 #
25 #
26 package DXChannel;
27
28 use Msg;
29 use DXM;
30 use DXUtil;
31 use DXVars;
32 use DXDebug;
33 use Filter;
34 use Prefix;
35 use Route;
36
37 use strict;
38 use vars qw(%channels %valid @ISA $count $maxerrors);
39
40 %channels = ();
41 $count = 0;
42
43 %valid = (
44                   'sort' => '5,Type of Channel',
45                   ann => '0,Want Announce,yesno',
46                   ann_talk => '0,Suppress Talk Anns,yesno',
47                   annfilter => '5,Ann Filt-out',
48                   badcount => '1,Bad Word Count',
49                   badip => '9,BAD IP address',
50                   beep => '0,Want Beeps,yesno',
51                   build => '1,Node Build',
52                   call => '0,Callsign',
53                   cluster => '5,Cluster data',
54                   conf => '0,In Conference?,yesno',
55                   conn => '9,Msg Conn ref',
56                   consort => '5,Connection Type',
57                   cq => '0,CQ Zone',
58                   delayed => '5,Delayed messages,parray',
59                   disconnecting => '9,Disconnecting,yesno',
60                   do_pc9x => '9,Handles PC9x,yesno',
61                   dx => '0,DX Spots,yesno',
62                   dxcc => '0,Country Code',
63                   edit => '7,Edit Function',
64                   enhanced => '5,Enhanced Client,yesno',
65                   errors => '9,Errors',
66                   func => '5,Function',
67                   group => '0,Access Group,parray',     # used to create a group of users/nodes for some purpose or other.
68                   gtk => '5,Using GTK,yesno',
69                   handle_xml => '9,Handles XML,yesno',
70                   here => '0,Here?,yesno',
71                   hostname => '0,Hostname',
72                   inannfilter => '5,Ann Filt-inp',
73                   inpc92filter => '5,PC92 Route Filt-inp',
74                   inqueue => '9,Input Queue,parray',
75                   inrbnfilter => '5,RBN Filt-inp',
76                   inroutefilter => '5,Route Filt-inp',
77                   inscript => '9,In a script,yesno',
78                   inspotsfilter => '5,Spot Filt-inp',
79                   inwcyfilter => '5,WCY Filt-inp',
80                   inwwvfilter => '5,WWV Filt-inp',
81                   isbasic => '9,Internal Connection', 
82                   isolate => '5,Isolate network,yesno',
83                   isslugged => '9,Still Slugged,yesno',
84                   itu => '0,ITU Zone',
85                   K => '9,Seen on PC92 K,yesno',
86                   lang => '0,Language',
87                   lastmsgpoll => '0,Last Msg Poll,atime',
88                   lastping => '5,Ping last sent,atime',
89                   lastread => '5,Last Msg Read',
90                   list => '9,Dep Chan List',
91                   loc => '9,Local Vars', # used by func to store local variables in
92                   logininfo => '9,Login info req,yesno',
93                   metric => '1,Route metric',
94                   name => '0,User Name',
95                   newroute => '1,New Style Routing,yesno',
96                   next_pc92_keepalive => '9,Next PC92 KeepAlive,atime',
97                   next_pc92_update => '9,Next PC92 Update,atime',
98                   nopings => '5,Ping Obs Count',
99                   oldstate => '5,Last State',
100                   outbound => '5,outbound?,yesno',
101                   pagedata => '9,Page Data Store',
102                   pagelth => '0,Page Length',
103                   passwd => '9,Passwd List,yesno',
104                   pc50_t => '5,Last PC50 Time,atime',
105                   pc92filter => '5,PC92 Route Filt-out',
106                   pingave => '0,Ping ave time',
107                   pingint => '5,Ping Interval ',
108                   pingtime => '5,Ping totaltime,parray',
109                   priv => '9,Privilege',
110                   prompt => '0,Required Prompt',
111                   rbnfilter => '5,RBN Filt-out',
112                   rbnseeme => '0,RBN See Me,yesno',
113                   redirect => '0,Redirect messages to',
114                   registered => '9,Registered?,yesno',
115                   remotecmd => '9,doing rcmd,yesno',
116                   route => '9,Route Data',
117                   routefilter => '5,Route Filt-out',
118                   senddbg => '8,Sending Debug,yesno',
119                   sluggedpcs => '9,Slugged PCxx Queue,parray',
120                   spotsfilter => '5,Spot Filt-out',
121                   startt => '0,Start Time,atime',
122                   state => '0,Current State',
123                   t => '9,Time,atime',
124                   talk => '0,Want Talk,yesno',
125                   talklist => '0,Talk List,parray',
126                   user => '9,DXUser ref',
127                   ve7cc => '0,VE7CC program special,yesno',
128                   verified => '9,Verified?,yesno',
129                   version => '1,Node Version',
130                   wcy => '0,Want WCY,yesno',
131                   wcyfilter => '5,WCY Filt-out',
132                   width => '0,Column Width',
133                   wwv => '0,Want WWV,yesno',
134                   wwvfilter => '5,WWV Filt-out',
135                   wx => '0,Want WX,yesno',                
136                  );
137
138 $maxerrors = 20;                                # the maximum number of concurrent errors allowed before disconnection
139
140 # object destruction
141 sub DESTROY
142 {
143         my $self = shift;
144         for (keys %$self) {
145                 if (ref($self->{$_})) {
146                         delete $self->{$_};
147                 }
148         }
149         dbg("DXChannel $self->{call} destroyed ($count)") if isdbg('chan');
150         $count--;
151 }
152
153 # create a new channel object [$obj = DXChannel->new($call, $msg_conn_obj, $user_obj)]
154 sub alloc
155 {
156         my ($pkg, $call, $conn, $user) = @_;
157         my $self = {};
158   
159         die "trying to create a duplicate channel for $call" if $channels{$call};
160         $self->{call} = $call;
161         $self->{priv} = 0;
162         $self->{conn} = $conn if defined $conn; # if this isn't defined then it must be a list
163         if (defined $user) {
164                 $self->{user} = $user;
165                 $self->{lang} = $user->lang;
166                 $user->new_group unless $user->group;
167                 $user->new_buddies unless $user->buddies;
168                 $self->{group} = $user->group;
169                 $self->{sort} = $user->sort;
170                 $self->{width} = $user->width;
171         }
172         $self->{startt} = $self->{t} = $main::systime;
173         $self->{state} = 0;
174         $self->{oldstate} = 0;
175         $self->{lang} = $main::lang if !$self->{lang};
176         $self->{func} = "";
177         $self->{width} ||=  80;
178
179         # add in all the dxcc, itu, zone info
180         my @dxcc = Prefix::extract($call);
181         if (@dxcc > 0) {
182                 $self->{dxcc} = $dxcc[1]->dxcc;
183                 $self->{itu} = $dxcc[1]->itu;
184                 $self->{cq} = $dxcc[1]->cq;
185         }
186         $self->{inqueue} = [];
187
188         $count++;
189         dbg("DXChannel $self->{call} created ($count)") if isdbg('chan');
190         bless $self, $pkg; 
191         return $channels{$call} = $self;
192 }
193
194 # count errors and disconnect if too many
195 # this has to be here because it can come from rcmd (DXProt) as
196 # well as DXCommandmode.
197 sub _error_out
198 {
199         my $self = shift;
200         my $e = shift;
201         if (++$self->{errors} > $maxerrors) {
202                 $self->send($self->msg('e26'));
203                 $self->disconnect;
204                 return ();
205         } else {
206                 return ($self->msg($e));
207         }
208 }
209
210 # rebless this channel as something else
211 sub rebless
212 {
213         my $self = shift;
214         my $class = shift;
215         return $channels{$self->{call}} = bless $self, $class;
216 }
217
218 sub rec 
219 {
220         my ($self, $msg) = @_;
221         
222         # queue the message and the channel object for later processing
223         if (defined $msg) {
224                 push @{$self->{inqueue}}, $msg;
225         }
226         $self->process_one;
227 }
228
229 # obtain a channel object by callsign [$obj = DXChannel::get($call)]
230 sub get
231 {
232         my $call = shift;
233         return $channels{$call};
234 }
235
236 # obtain all the channel objects
237 sub get_all
238 {
239         return values(%channels);
240 }
241
242 #
243 # gimme all the ak1a nodes
244 #
245 sub get_all_nodes
246 {
247         my $ref;
248         my @out;
249         foreach $ref (values %channels) {
250                 push @out, $ref if $ref->is_node;
251         }
252         return @out;
253 }
254
255 # return a list of node calls
256 sub get_all_node_calls
257 {
258         my $ref;
259         my @out;
260         foreach $ref (values %channels) {
261                 push @out, $ref->{call} if $ref->is_node;
262         }
263         return @out;
264 }
265
266 # return a list of all users
267 sub get_all_users
268 {
269         my $ref;
270         my @out;
271         foreach $ref (values %channels) {
272                 push @out, $ref if $ref->is_user;
273         }
274         return @out;
275 }
276
277 # return a list of all user callsigns
278 sub get_all_user_calls
279 {
280         my $ref;
281         my @out;
282         foreach $ref (values %channels) {
283                 push @out, $ref->{call} if $ref->is_user;
284         }
285         return @out;
286 }
287
288 # obtain a channel object by searching for its connection reference
289 sub get_by_cnum
290 {
291         my ($pkg, $conn) = @_;
292         my $self;
293   
294         foreach $self (values(%channels)) {
295                 return $self if ($self->{conn} == $conn);
296         }
297         return undef;
298 }
299
300 # get rid of a channel object [$obj->del()]
301 sub del
302 {
303         my $self = shift;
304
305         $self->{group} = undef;         # belt and braces
306         delete $channels{$self->{call}};
307 }
308
309 # is it a bbs
310 sub is_bbs
311 {
312         return $_[0]->{sort} eq 'B';
313 }
314
315 sub is_node
316 {
317         return $_[0]->{sort} =~ /^[ACRSX]$/;
318 }
319 # is it an ak1a node ?
320 sub is_ak1a
321 {
322         return $_[0]->{sort} eq 'A';
323 }
324
325 # is it a user?
326 sub is_user
327 {
328         return $_[0]->{sort} =~ /^[UW]$/;
329 }
330
331 # is it a clx node
332 sub is_clx
333 {
334         return $_[0]->{sort} eq 'C';
335 }
336
337 # it is a Web connected user
338 sub is_web
339 {
340         return $_[0]->{sort} eq 'W';
341 }
342
343 # is it a spider node
344 sub is_spider
345 {
346         return $_[0]->{sort} eq 'S';
347 }
348
349 # is it a DXNet node
350 sub is_dxnet
351 {
352         return $_[0]->{sort} eq 'X';
353 }
354
355 # is it a ar-cluster node
356 sub is_arcluster
357 {
358         return $_[0]->{sort} eq 'R';
359 }
360
361 sub is_rbn
362 {
363         return $_[0]->{sort} eq 'N';
364 }
365
366 sub is_dslink
367 {
368         return $_[0]->{sort} eq 'L';
369 }
370
371 # for perl 5.004's benefit
372 sub sort
373 {
374         my $self = shift;
375         return @_ ? $self->{sort} = shift : $self->{sort} ;
376 }
377
378 # find out whether we are prepared to believe this callsign on this interface
379 sub is_believed
380 {
381         my $self = shift;
382         my $call = shift;
383         
384         return grep $call eq $_, $self->user->believe;
385 }
386
387 # handle out going messages, immediately without waiting for the select to drop
388 # this could, in theory, block
389 sub send_now
390 {
391         my $self = shift;
392         my $conn = $self->{conn};
393         return unless $conn;
394         my $sort = shift;
395         my $call = $self->{call};
396         
397         for (@_) {
398 #               chomp;
399         my @lines = split /\n/;
400                 for (@lines) {
401                         $conn->send_now("$sort$call|$_");
402                         # debug log it, but not if it is a log message
403                         dbg("-> $sort $call $_") if $sort ne 'L' && isdbg('chan');
404                 }
405         }
406         $self->{t} = time;
407 }
408
409 #
410 # send later with letter (more control)
411 #
412
413 sub send_later
414 {
415         my $self = shift;
416         my $conn = $self->{conn};
417         return unless $conn;
418         my $sort = shift;
419         my $call = $self->{call};
420         
421         for (@_) {
422 #               chomp;
423         my @lines = split /\n/;
424                 for (@lines) {
425                         $conn->send_later("$sort$call|$_");
426                         # debug log it, but not if it is a log message
427                         dbg("-> $sort $call $_") if $sort ne 'L' && isdbg('chan');
428                 }
429         }
430         $self->{t} = time;
431 }
432
433 #
434 # the normal output routine
435 #
436 sub send                                                # this is always later and always data
437 {
438         my $self = shift;
439         my $conn = $self->{conn};
440         return unless $conn;
441         my $call = $self->{call};
442
443         foreach my $l (@_) {
444                 for (ref $l ? @$l : $l) {
445                         my @lines = split /\n/;
446                         for (@lines) {
447                                 $conn->send_later("D$call|$_");
448                                 dbg("-> D $call $_") if isdbg('chan');
449                         }
450                 }
451         }
452         $self->{t} = $main::systime;
453 }
454
455 # send a file (always later)
456 sub send_file
457 {
458         my ($self, $fn) = @_;
459         my $call = $self->{call};
460         my $conn = $self->{conn};
461         my @buf;
462   
463         open(F, $fn) or die "can't open $fn for sending file ($!)";
464         @buf = <F>;
465         close(F);
466         $self->send(@buf);
467 }
468
469 # this will implement language independence (in time)
470 sub msg
471 {
472         my $self = shift;
473         return DXM::msg($self->{lang}, @_);
474 }
475
476 # stick a broadcast on the delayed queue (but only up to 20 items)
477 sub delay
478 {
479         my $self = shift;
480         my $s = shift;
481         
482         $self->{delayed} = [] unless $self->{delayed};
483         push @{$self->{delayed}}, $s;
484         if (@{$self->{delayed}} >= 20) {
485                 shift @{$self->{delayed}};   # lose oldest one
486         }
487 }
488
489 # change the state of the channel - lots of scope for debugging here :-)
490 sub state
491 {
492         my $self = shift;
493         if (@_) {
494                 $self->{oldstate} = $self->{state};
495                 $self->{state} = shift;
496                 $self->{func} = '' unless defined $self->{func};
497                 dbg("$self->{call} channel func $self->{func} state $self->{oldstate} -> $self->{state}\n") if isdbg('state');
498
499                 # if there is any queued up broadcasts then splurge them out here
500                 if ($self->{delayed} && ($self->{state} eq 'prompt' || $self->{state} eq 'talk')) {
501                         $self->send (@{$self->{delayed}});
502                         delete $self->{delayed};
503                 }
504         }
505         return $self->{state};
506 }
507
508 # disconnect this channel
509 sub disconnect
510 {
511         my $self = shift;
512         my $user = $self->{user};
513         
514         $user->close($self->{startt}, $self->{hostname}) if defined $user;
515         $self->{conn}->disconnect if $self->{conn};
516         $self->del();
517 }
518
519 #
520 # just close all the socket connections down without any fiddling about, cleaning, being
521 # nice to other processes and otherwise telling them what is going on.
522 #
523 # This is for the benefit of forked processes to prepare for starting new programs, they
524 # don't want or need all this baggage.
525 #
526
527 sub closeall
528 {
529         my $ref;
530         foreach $ref (values %channels) {
531                 $ref->{conn}->disconnect() if $ref->{conn};
532         }
533 }
534
535 #
536 # Tell all the users that we have come in or out (if they want to know)
537 #
538 sub tell_login
539 {
540         my ($self, $m, $call) = @_;
541         
542         $call ||= $self->{call};
543         
544         # send info to all logged in thingies
545         my @dxchan = get_all_users();
546         my $dxchan;
547         foreach $dxchan (@dxchan) {
548                 next if $dxchan == $self;
549                 next if $dxchan->{call} eq $main::mycall;
550                 $dxchan->send($dxchan->msg($m, $call)) if $dxchan->{logininfo};
551         }
552 }
553
554 #
555 # Tell all the users if a buddy is logged or out
556 #
557 sub tell_buddies
558 {
559         my ($self, $m, $call, $node) = @_;
560         
561         $call ||= $self->{call};
562         $call =~ s/-\d+$//;
563         $m .= 'n' if $node;
564         
565         # send info to all logged in thingies
566         my @dxchan = get_all_users();
567         my $dxchan;
568         foreach $dxchan (@dxchan) {
569                 next if $dxchan == $self;
570                 next if $dxchan->{call} eq $main::mycall;
571                 $dxchan->send($dxchan->msg($m, $call, $node)) if grep $_ eq $call, @{$dxchan->{user}->{buddies}} ;
572         }
573 }
574
575 # various access routines
576
577 #
578 # return a list of valid elements 
579
580
581 sub fields
582 {
583         return keys(%valid);
584 }
585
586 #
587 # return a prompt for a field
588 #
589
590 sub field_prompt
591
592         my ($self, $ele) = @_;
593         return $valid{$ele};
594 }
595
596 # take a standard input message and decode it into its standard parts
597 sub decode_input
598 {
599         my $dxchan = shift;
600         my $data = shift;
601         my ($sort, $call, $line) = $data =~ /^([A-Z])(#?[A-Z0-9\/\-]{3,25})\|(.*)$/;
602
603         my $chcall = (ref $dxchan) ? $dxchan->call : "UN.KNOWN";
604         
605         # the above regexp must work
606         unless (defined $sort && defined $call && defined $line) {
607 #               $data =~ s/([\x00-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
608                 dbg("DUFF Line on $chcall: $data");
609                 return ();
610         }
611
612         if(ref($dxchan) && $call ne $chcall) {
613                 dbg("DUFF Line come in for $call on wrong channel $chcall");
614                 return();
615         }
616         
617         return ($sort, $call, $line);
618 }
619
620 # broadcast a message to all clusters taking into account isolation
621 # [except those mentioned after buffer]
622 sub broadcast_nodes
623 {
624         my $s = shift;                          # the line to be rebroadcast
625         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
626         my @dxchan = get_all_nodes();
627         my $dxchan;
628         
629         # send it if it isn't the except list and isn't isolated and still has a hop count
630         foreach $dxchan (@dxchan) {
631                 next if grep $dxchan == $_, @except;
632                 next if $dxchan == $main::me;
633                 
634                 my $routeit = $dxchan->can('adjust_hops') ? $dxchan->adjust_hops($s) : $s;      # adjust its hop count by node name
635
636                 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
637         }
638 }
639
640 # broadcast a message to all clusters ignoring isolation
641 # [except those mentioned after buffer]
642 sub broadcast_all_nodes
643 {
644         my $s = shift;                          # the line to be rebroadcast
645         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
646         my @dxchan = get_all_nodes();
647         my $dxchan;
648         
649         # send it if it isn't the except list and isn't isolated and still has a hop count
650         foreach $dxchan (@dxchan) {
651                 next if grep $dxchan == $_, @except;
652                 next if $dxchan == $main::me;
653
654                 my $routeit = $dxchan->can('adjust_hops') ? $dxchan->adjust_hops($s) : $s;      # adjust its hop count by node name
655                 $dxchan->send($routeit);
656         }
657 }
658
659 # broadcast to all users
660 # storing the spot or whatever until it is in a state to receive it
661 sub broadcast_users
662 {
663         my $s = shift;                          # the line to be rebroadcast
664         my $sort = shift;           # the type of transmission
665         my $fref = shift;           # a reference to an object to filter on
666         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
667         my @dxchan = get_all_users();
668         my $dxchan;
669         my @out;
670         
671         foreach $dxchan (@dxchan) {
672                 next if grep $dxchan == $_, @except;
673                 push @out, $dxchan;
674         }
675         broadcast_list($s, $sort, $fref, @out);
676 }
677
678
679 # broadcast to a list of users
680 sub broadcast_list
681 {
682         my $s = shift;
683         my $sort = shift;
684         my $fref = shift;
685         my $dxchan;
686         
687         foreach $dxchan (@_) {
688                 my $filter = 1;
689                 next if $dxchan == $main::me;
690                 
691                 if ($sort eq 'dx') {
692                     next unless $dxchan->{dx};
693                         ($filter) = $dxchan->{spotsfilter}->it($fref) if $dxchan->{spotsfilter} && ref $fref;
694                         next unless $filter;
695                 }
696                 next if $sort eq 'ann' && !$dxchan->{ann} && $s !~ /^To\s+LOCAL\s+de\s+(?:$main::myalias|$main::mycall)/i;
697                 next if $sort eq 'wwv' && !$dxchan->{wwv};
698                 next if $sort eq 'wcy' && !$dxchan->{wcy};
699                 next if $sort eq 'wx' && !$dxchan->{wx};
700
701                 $s =~ s/\a//og unless $dxchan->{beep};
702
703                 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
704                         $dxchan->send($s);      
705                 } else {
706                         $dxchan->delay($s);
707                 }
708         }
709 }
710
711 sub process_one
712 {
713         my $self = shift;
714
715         while (my $data = shift @{$self->{inqueue}}) {
716                 my ($sort, $call, $line) = $self->decode_input($data);
717                 next unless defined $sort;
718
719                 if ($sort ne 'D') {
720                         if (isdbg('chan')) {
721                                 if (($self->is_rbn && isdbg('rbnchan')) || !$self->is_rbn) {
722                                         dbg("<- $sort $call $line") if isdbg('chan'); # you may think this is tautology, but it's needed get the correct label on the debug line
723                                 }
724                         }
725                 }
726                 
727                 # handle A records
728                 my $user = $self->user;
729                 if ($sort eq 'I') {
730                         die "\$user not defined for $call" unless defined $user;
731                         
732                         # normal input
733                         $self->normal($line);
734                 } elsif ($sort eq 'G') {
735                         $self->enhanced($line);
736                 } elsif ($sort eq 'A' || $sort eq 'O' || $sort eq 'W') {
737                         $self->start($line, $sort);
738                 } elsif ($sort eq 'C') {
739                         $self->width($line); # change number of columns
740                 } elsif ($sort eq 'Z') {
741                         $self->disconnect;
742                 } elsif ($sort eq 'D') {
743                         ;                               # ignored (an echo)
744                 } else {
745                         dbg atime . " DXChannel::process_one: Unknown command letter ($sort) received from $call\n";
746                 }
747         }
748 }
749
750 sub process
751 {
752         foreach my $dxchan (values %channels) {
753                 next if $dxchan->{disconnecting};
754                 $dxchan->process_one;
755         }
756 }
757
758 sub handle_xml
759 {
760         my $self = shift;
761         my $r = 0;
762         
763         if (DXXml::available()) {
764                 $r = $self->{handle_xml} || 0;
765         } else {
766                 delete $self->{handle_xml} if exists $self->{handle_xml};
767         }
768         return $r;
769 }
770
771 sub error_handler
772 {
773         my $self = shift;
774         my $error = shift || '';
775         dbg("$self->{call} ERROR '$error', closing") if isdbg('chan');
776         $self->{conn}->set_error(undef) if exists $self->{conn};
777         $self->disconnect(1);
778 }
779
780 sub refresh_user
781 {
782         my $call = shift;
783         my $user = shift;
784         return unless $call && $user && ref $user;
785         my $self = DXChannel::get($call);
786         $self->{user} = $user;
787         return $user;
788 }
789
790 sub isregistered
791 {
792         my $self = shift;
793
794         # the sysop is registered!
795         return 1 if $self->{call} eq $main::myalias || $self->{call} eq $main::mycall;
796         
797         if ($main::reqreg) {
798                 return $self->{registered};
799         } else {
800                 return 1;
801         }
802 }
803
804 #no strict;
805 sub AUTOLOAD
806 {
807         no strict;
808         my $name = $AUTOLOAD;
809         return if $name =~ /::DESTROY$/;
810         $name =~ s/^.*:://o;
811   
812         confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
813
814         # this clever line of code creates a subroutine which takes over from autoload
815         # from OO Perl - Conway
816         *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
817         goto &$AUTOLOAD;
818 }
819
820
821 1;
822 __END__;