add missing K field definition
[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                   redirect => '0,Redirect messages to',
113                   registered => '9,Registered?,yesno',
114                   remotecmd => '9,doing rcmd,yesno',
115                   route => '9,Route Data',
116                   routefilter => '5,Route Filt-out',
117                   senddbg => '8,Sending Debug,yesno',
118                   sluggedpcs => '9,Slugged PCxx Queue,parray',
119                   spotsfilter => '5,Spot Filt-out',
120                   startt => '0,Start Time,atime',
121                   state => '0,Current State',
122                   t => '9,Time,atime',
123                   talk => '0,Want Talk,yesno',
124                   talklist => '0,Talk List,parray',
125                   user => '9,DXUser ref',
126                   ve7cc => '0,VE7CC program special,yesno',
127                   verified => '9,Verified?,yesno',
128                   version => '1,Node Version',
129                   wcy => '0,Want WCY,yesno',
130                   wcyfilter => '5,WCY Filt-out',
131                   width => '0,Column Width',
132                   wwv => '0,Want WWV,yesno',
133                   wwvfilter => '5,WWV Filt-out',
134                   wx => '0,Want WX,yesno',
135                  );
136
137 $maxerrors = 20;                                # the maximum number of concurrent errors allowed before disconnection
138
139 # object destruction
140 sub DESTROY
141 {
142         my $self = shift;
143         for (keys %$self) {
144                 if (ref($self->{$_})) {
145                         delete $self->{$_};
146                 }
147         }
148         dbg("DXChannel $self->{call} destroyed ($count)") if isdbg('chan');
149         $count--;
150 }
151
152 # create a new channel object [$obj = DXChannel->new($call, $msg_conn_obj, $user_obj)]
153 sub alloc
154 {
155         my ($pkg, $call, $conn, $user) = @_;
156         my $self = {};
157   
158         die "trying to create a duplicate channel for $call" if $channels{$call};
159         $self->{call} = $call;
160         $self->{priv} = 0;
161         $self->{conn} = $conn if defined $conn; # if this isn't defined then it must be a list
162         if (defined $user) {
163                 $self->{user} = $user;
164                 $self->{lang} = $user->lang;
165                 $user->new_group unless $user->group;
166                 $user->new_buddies unless $user->buddies;
167                 $self->{group} = $user->group;
168                 $self->{sort} = $user->sort;
169                 $self->{width} = $user->width;
170         }
171         $self->{startt} = $self->{t} = $main::systime;
172         $self->{state} = 0;
173         $self->{oldstate} = 0;
174         $self->{lang} = $main::lang if !$self->{lang};
175         $self->{func} = "";
176         $self->{width} ||=  80;
177
178         # add in all the dxcc, itu, zone info
179         my @dxcc = Prefix::extract($call);
180         if (@dxcc > 0) {
181                 $self->{dxcc} = $dxcc[1]->dxcc;
182                 $self->{itu} = $dxcc[1]->itu;
183                 $self->{cq} = $dxcc[1]->cq;
184         }
185         $self->{inqueue} = [];
186
187         $count++;
188         dbg("DXChannel $self->{call} created ($count)") if isdbg('chan');
189         bless $self, $pkg; 
190         return $channels{$call} = $self;
191 }
192
193 # count errors and disconnect if too many
194 # this has to be here because it can come from rcmd (DXProt) as
195 # well as DXCommandmode.
196 sub _error_out
197 {
198         my $self = shift;
199         my $e = shift;
200         if (++$self->{errors} > $maxerrors) {
201                 $self->send($self->msg('e26'));
202                 $self->disconnect;
203                 return ();
204         } else {
205                 return ($self->msg($e));
206         }
207 }
208
209 # rebless this channel as something else
210 sub rebless
211 {
212         my $self = shift;
213         my $class = shift;
214         return $channels{$self->{call}} = bless $self, $class;
215 }
216
217 sub rec 
218 {
219         my ($self, $msg) = @_;
220         
221         # queue the message and the channel object for later processing
222         if (defined $msg) {
223                 push @{$self->{inqueue}}, $msg;
224         }
225         $self->process_one;
226 }
227
228 # obtain a channel object by callsign [$obj = DXChannel::get($call)]
229 sub get
230 {
231         my $call = shift;
232         return $channels{$call};
233 }
234
235 # obtain all the channel objects
236 sub get_all
237 {
238         return values(%channels);
239 }
240
241 #
242 # gimme all the ak1a nodes
243 #
244 sub get_all_nodes
245 {
246         my $ref;
247         my @out;
248         foreach $ref (values %channels) {
249                 push @out, $ref if $ref->is_node;
250         }
251         return @out;
252 }
253
254 # return a list of node calls
255 sub get_all_node_calls
256 {
257         my $ref;
258         my @out;
259         foreach $ref (values %channels) {
260                 push @out, $ref->{call} if $ref->is_node;
261         }
262         return @out;
263 }
264
265 # return a list of all users
266 sub get_all_users
267 {
268         my $ref;
269         my @out;
270         foreach $ref (values %channels) {
271                 push @out, $ref if $ref->is_user;
272         }
273         return @out;
274 }
275
276 # return a list of all user callsigns
277 sub get_all_user_calls
278 {
279         my $ref;
280         my @out;
281         foreach $ref (values %channels) {
282                 push @out, $ref->{call} if $ref->is_user;
283         }
284         return @out;
285 }
286
287 # obtain a channel object by searching for its connection reference
288 sub get_by_cnum
289 {
290         my ($pkg, $conn) = @_;
291         my $self;
292   
293         foreach $self (values(%channels)) {
294                 return $self if ($self->{conn} == $conn);
295         }
296         return undef;
297 }
298
299 # get rid of a channel object [$obj->del()]
300 sub del
301 {
302         my $self = shift;
303
304         $self->{group} = undef;         # belt and braces
305         delete $channels{$self->{call}};
306 }
307
308 # is it a bbs
309 sub is_bbs
310 {
311         return $_[0]->{sort} eq 'B';
312 }
313
314 sub is_node
315 {
316         return $_[0]->{sort} =~ /^[ACRSX]$/;
317 }
318 # is it an ak1a node ?
319 sub is_ak1a
320 {
321         return $_[0]->{sort} eq 'A';
322 }
323
324 # is it a user?
325 sub is_user
326 {
327         return $_[0]->{sort} =~ /^[UW]$/;
328 }
329
330 # is it a clx node
331 sub is_clx
332 {
333         return $_[0]->{sort} eq 'C';
334 }
335
336 # it is a Web connected user
337 sub is_web
338 {
339         return $_[0]->{sort} eq 'W';
340 }
341
342 # is it a spider node
343 sub is_spider
344 {
345         return $_[0]->{sort} eq 'S';
346 }
347
348 # is it a DXNet node
349 sub is_dxnet
350 {
351         return $_[0]->{sort} eq 'X';
352 }
353
354 # is it a ar-cluster node
355 sub is_arcluster
356 {
357         return $_[0]->{sort} eq 'R';
358 }
359
360 sub is_rbn
361 {
362         return $_[0]->{sort} eq 'N';
363 }
364
365 sub is_dslink
366 {
367         return $_[0]->{sort} eq 'L';
368 }
369
370 # for perl 5.004's benefit
371 sub sort
372 {
373         my $self = shift;
374         return @_ ? $self->{sort} = shift : $self->{sort} ;
375 }
376
377 # find out whether we are prepared to believe this callsign on this interface
378 sub is_believed
379 {
380         my $self = shift;
381         my $call = shift;
382         
383         return grep $call eq $_, $self->user->believe;
384 }
385
386 # handle out going messages, immediately without waiting for the select to drop
387 # this could, in theory, block
388 sub send_now
389 {
390         my $self = shift;
391         my $conn = $self->{conn};
392         return unless $conn;
393         my $sort = shift;
394         my $call = $self->{call};
395         
396         for (@_) {
397 #               chomp;
398         my @lines = split /\n/;
399                 for (@lines) {
400                         $conn->send_now("$sort$call|$_");
401                         # debug log it, but not if it is a log message
402                         dbg("-> $sort $call $_") if $sort ne 'L' && isdbg('chan');
403                 }
404         }
405         $self->{t} = time;
406 }
407
408 #
409 # send later with letter (more control)
410 #
411
412 sub send_later
413 {
414         my $self = shift;
415         my $conn = $self->{conn};
416         return unless $conn;
417         my $sort = shift;
418         my $call = $self->{call};
419         
420         for (@_) {
421 #               chomp;
422         my @lines = split /\n/;
423                 for (@lines) {
424                         $conn->send_later("$sort$call|$_");
425                         # debug log it, but not if it is a log message
426                         dbg("-> $sort $call $_") if $sort ne 'L' && isdbg('chan');
427                 }
428         }
429         $self->{t} = time;
430 }
431
432 #
433 # the normal output routine
434 #
435 sub send                                                # this is always later and always data
436 {
437         my $self = shift;
438         my $conn = $self->{conn};
439         return unless $conn;
440         my $call = $self->{call};
441
442         foreach my $l (@_) {
443                 for (ref $l ? @$l : $l) {
444                         my @lines = split /\n/;
445                         for (@lines) {
446                                 $conn->send_later("D$call|$_");
447                                 dbg("-> D $call $_") if isdbg('chan');
448                         }
449                 }
450         }
451         $self->{t} = $main::systime;
452 }
453
454 # send a file (always later)
455 sub send_file
456 {
457         my ($self, $fn) = @_;
458         my $call = $self->{call};
459         my $conn = $self->{conn};
460         my @buf;
461   
462         open(F, $fn) or die "can't open $fn for sending file ($!)";
463         @buf = <F>;
464         close(F);
465         $self->send(@buf);
466 }
467
468 # this will implement language independence (in time)
469 sub msg
470 {
471         my $self = shift;
472         return DXM::msg($self->{lang}, @_);
473 }
474
475 # stick a broadcast on the delayed queue (but only up to 20 items)
476 sub delay
477 {
478         my $self = shift;
479         my $s = shift;
480         
481         $self->{delayed} = [] unless $self->{delayed};
482         push @{$self->{delayed}}, $s;
483         if (@{$self->{delayed}} >= 20) {
484                 shift @{$self->{delayed}};   # lose oldest one
485         }
486 }
487
488 # change the state of the channel - lots of scope for debugging here :-)
489 sub state
490 {
491         my $self = shift;
492         if (@_) {
493                 $self->{oldstate} = $self->{state};
494                 $self->{state} = shift;
495                 $self->{func} = '' unless defined $self->{func};
496                 dbg("$self->{call} channel func $self->{func} state $self->{oldstate} -> $self->{state}\n") if isdbg('state');
497
498                 # if there is any queued up broadcasts then splurge them out here
499                 if ($self->{delayed} && ($self->{state} eq 'prompt' || $self->{state} eq 'talk')) {
500                         $self->send (@{$self->{delayed}});
501                         delete $self->{delayed};
502                 }
503         }
504         return $self->{state};
505 }
506
507 # disconnect this channel
508 sub disconnect
509 {
510         my $self = shift;
511         my $user = $self->{user};
512         
513         $user->close($self->{startt}, $self->{hostname}) if defined $user;
514         $self->{conn}->disconnect if $self->{conn};
515         $self->del();
516 }
517
518 #
519 # just close all the socket connections down without any fiddling about, cleaning, being
520 # nice to other processes and otherwise telling them what is going on.
521 #
522 # This is for the benefit of forked processes to prepare for starting new programs, they
523 # don't want or need all this baggage.
524 #
525
526 sub closeall
527 {
528         my $ref;
529         foreach $ref (values %channels) {
530                 $ref->{conn}->disconnect() if $ref->{conn};
531         }
532 }
533
534 #
535 # Tell all the users that we have come in or out (if they want to know)
536 #
537 sub tell_login
538 {
539         my ($self, $m, $call) = @_;
540         
541         $call ||= $self->{call};
542         
543         # send info to all logged in thingies
544         my @dxchan = get_all_users();
545         my $dxchan;
546         foreach $dxchan (@dxchan) {
547                 next if $dxchan == $self;
548                 next if $dxchan->{call} eq $main::mycall;
549                 $dxchan->send($dxchan->msg($m, $call)) if $dxchan->{logininfo};
550         }
551 }
552
553 #
554 # Tell all the users if a buddy is logged or out
555 #
556 sub tell_buddies
557 {
558         my ($self, $m, $call, $node) = @_;
559         
560         $call ||= $self->{call};
561         $call =~ s/-\d+$//;
562         $m .= 'n' if $node;
563         
564         # send info to all logged in thingies
565         my @dxchan = get_all_users();
566         my $dxchan;
567         foreach $dxchan (@dxchan) {
568                 next if $dxchan == $self;
569                 next if $dxchan->{call} eq $main::mycall;
570                 $dxchan->send($dxchan->msg($m, $call, $node)) if grep $_ eq $call, @{$dxchan->{user}->{buddies}} ;
571         }
572 }
573
574 # various access routines
575
576 #
577 # return a list of valid elements 
578
579
580 sub fields
581 {
582         return keys(%valid);
583 }
584
585 #
586 # return a prompt for a field
587 #
588
589 sub field_prompt
590
591         my ($self, $ele) = @_;
592         return $valid{$ele};
593 }
594
595 # take a standard input message and decode it into its standard parts
596 sub decode_input
597 {
598         my $dxchan = shift;
599         my $data = shift;
600         my ($sort, $call, $line) = $data =~ /^([A-Z])(#?[A-Z0-9\/\-]{3,25})\|(.*)$/;
601
602         my $chcall = (ref $dxchan) ? $dxchan->call : "UN.KNOWN";
603         
604         # the above regexp must work
605         unless (defined $sort && defined $call && defined $line) {
606 #               $data =~ s/([\x00-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
607                 dbg("DUFF Line on $chcall: $data");
608                 return ();
609         }
610
611         if(ref($dxchan) && $call ne $chcall) {
612                 dbg("DUFF Line come in for $call on wrong channel $chcall");
613                 return();
614         }
615         
616         return ($sort, $call, $line);
617 }
618
619 # broadcast a message to all clusters taking into account isolation
620 # [except those mentioned after buffer]
621 sub broadcast_nodes
622 {
623         my $s = shift;                          # the line to be rebroadcast
624         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
625         my @dxchan = get_all_nodes();
626         my $dxchan;
627         
628         # send it if it isn't the except list and isn't isolated and still has a hop count
629         foreach $dxchan (@dxchan) {
630                 next if grep $dxchan == $_, @except;
631                 next if $dxchan == $main::me;
632                 
633                 my $routeit = $dxchan->can('adjust_hops') ? $dxchan->adjust_hops($s) : $s;      # adjust its hop count by node name
634
635                 $dxchan->send($routeit) unless $dxchan->{isolate} || !$routeit;
636         }
637 }
638
639 # broadcast a message to all clusters ignoring isolation
640 # [except those mentioned after buffer]
641 sub broadcast_all_nodes
642 {
643         my $s = shift;                          # the line to be rebroadcast
644         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
645         my @dxchan = get_all_nodes();
646         my $dxchan;
647         
648         # send it if it isn't the except list and isn't isolated and still has a hop count
649         foreach $dxchan (@dxchan) {
650                 next if grep $dxchan == $_, @except;
651                 next if $dxchan == $main::me;
652
653                 my $routeit = $dxchan->can('adjust_hops') ? $dxchan->adjust_hops($s) : $s;      # adjust its hop count by node name
654                 $dxchan->send($routeit);
655         }
656 }
657
658 # broadcast to all users
659 # storing the spot or whatever until it is in a state to receive it
660 sub broadcast_users
661 {
662         my $s = shift;                          # the line to be rebroadcast
663         my $sort = shift;           # the type of transmission
664         my $fref = shift;           # a reference to an object to filter on
665         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
666         my @dxchan = get_all_users();
667         my $dxchan;
668         my @out;
669         
670         foreach $dxchan (@dxchan) {
671                 next if grep $dxchan == $_, @except;
672                 push @out, $dxchan;
673         }
674         broadcast_list($s, $sort, $fref, @out);
675 }
676
677
678 # broadcast to a list of users
679 sub broadcast_list
680 {
681         my $s = shift;
682         my $sort = shift;
683         my $fref = shift;
684         my $dxchan;
685         
686         foreach $dxchan (@_) {
687                 my $filter = 1;
688                 next if $dxchan == $main::me;
689                 
690                 if ($sort eq 'dx') {
691                     next unless $dxchan->{dx};
692                         ($filter) = $dxchan->{spotsfilter}->it($fref) if $dxchan->{spotsfilter} && ref $fref;
693                         next unless $filter;
694                 }
695                 next if $sort eq 'ann' && !$dxchan->{ann} && $s !~ /^To\s+LOCAL\s+de\s+(?:$main::myalias|$main::mycall)/i;
696                 next if $sort eq 'wwv' && !$dxchan->{wwv};
697                 next if $sort eq 'wcy' && !$dxchan->{wcy};
698                 next if $sort eq 'wx' && !$dxchan->{wx};
699
700                 $s =~ s/\a//og unless $dxchan->{beep};
701
702                 if ($dxchan->{state} eq 'prompt' || $dxchan->{state} eq 'talk') {
703                         $dxchan->send($s);      
704                 } else {
705                         $dxchan->delay($s);
706                 }
707         }
708 }
709
710 sub process_one
711 {
712         my $self = shift;
713
714         while (my $data = shift @{$self->{inqueue}}) {
715                 my ($sort, $call, $line) = $self->decode_input($data);
716                 next unless defined $sort;
717                 
718                 # do the really sexy console interface bit! (Who is going to do the TK interface then?)
719                 dbg("<- $sort $call $line") if $sort ne 'D' && isdbg('chan');
720                 
721                 # handle A records
722                 my $user = $self->user;
723                 if ($sort eq 'I') {
724                         die "\$user not defined for $call" unless defined $user;
725                         
726                         # normal input
727                         $self->normal($line);
728                 } elsif ($sort eq 'G') {
729                         $self->enhanced($line);
730                 } elsif ($sort eq 'A' || $sort eq 'O' || $sort eq 'W') {
731                         $self->start($line, $sort);
732                 } elsif ($sort eq 'C') {
733                         $self->width($line); # change number of columns
734                 } elsif ($sort eq 'Z') {
735                         $self->disconnect;
736                 } elsif ($sort eq 'D') {
737                         ;                               # ignored (an echo)
738                 } else {
739                         dbg atime . " DXChannel::process_one: Unknown command letter ($sort) received from $call\n";
740                 }
741         }
742 }
743
744 sub process
745 {
746         foreach my $dxchan (values %channels) {
747                 next if $dxchan->{disconnecting};
748                 $dxchan->process_one;
749         }
750 }
751
752 sub handle_xml
753 {
754         my $self = shift;
755         my $r = 0;
756         
757         if (DXXml::available()) {
758                 $r = $self->{handle_xml} || 0;
759         } else {
760                 delete $self->{handle_xml} if exists $self->{handle_xml};
761         }
762         return $r;
763 }
764
765 sub error_handler
766 {
767         my $self = shift;
768         my $error = shift || '';
769         dbg("$self->{call} ERROR '$error', closing") if isdbg('chan');
770         $self->{conn}->set_error(undef) if exists $self->{conn};
771         $self->disconnect(1);
772 }
773
774
775 sub isregistered
776 {
777         my $self = shift;
778
779         # the sysop is registered!
780         return 1 if $self->{call} eq $main::myalias || $self->{call} eq $main::mycall;
781         
782         if ($main::reqreg) {
783                 return $self->{registered};
784         } else {
785                 return 1;
786         }
787 }
788
789 #no strict;
790 sub AUTOLOAD
791 {
792         no strict;
793         my $name = $AUTOLOAD;
794         return if $name =~ /::DESTROY$/;
795         $name =~ s/^.*:://o;
796   
797         confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
798
799         # this clever line of code creates a subroutine which takes over from autoload
800         # from OO Perl - Conway
801         *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
802         goto &$AUTOLOAD;
803 }
804
805
806 1;
807 __END__;