fixed bull problems properly
[spider.git] / perl / DXMsg.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the message handling for a dx cluster
4 #
5 # Copyright (c) 1998 Dirk Koopman G1TLH
6 #
7 # $Id$
8
9
10 package DXMsg;
11
12 @ISA = qw(DXProt DXChannel);
13
14 use DXUtil;
15 use DXChannel;
16 use DXUser;
17 use DXM;
18 use DXCluster;
19 use DXProtVars;
20 use DXProtout;
21 use DXDebug;
22 use DXLog;
23 use FileHandle;
24 use Carp;
25
26 use strict;
27 use vars qw(%work @msg $msgdir %valid %busy $maxage $last_clean);
28
29 %work = ();                                             # outstanding jobs
30 @msg = ();                                              # messages we have
31 %busy = ();                                             # station interlocks
32 $msgdir = "$main::root/msg";    # directory contain the msgs
33 $maxage = 30 * 86400;                   # the maximum age that a message shall live for if not marked 
34 $last_clean = 0;                                # last time we did a clean
35
36 %valid = (
37                   fromnode => '9,From Node',
38                   tonode => '9,To Node',
39                   to => '0,To',
40                   from => '0,From',
41                   t => '0,Msg Time,cldatetime',
42                   private => '9,Private',
43                   subject => '0,Subject',
44                   linesreq => '0,Lines per Gob',
45                   rrreq => '9,Read Confirm',
46                   origin => '0,Origin',
47                   lines => '5,Data',
48                   stream => '9,Stream No',
49                   count => '9,Gob Linecnt',
50                   file => '9,File?,yesno',
51                   gotit => '9,Got it Nodes,parray',
52                   lines => '9,Lines,parray',
53                   read => '9,Times read',
54                   size => '0,Size',
55                   msgno => '0,Msgno',
56                   keep => '0,Keep this?,yesno',
57                  );
58
59 # allocate a new object
60 # called fromnode, tonode, from, to, datetime, private?, subject, nolinesper  
61 sub alloc                  
62 {
63         my $pkg = shift;
64         my $self = bless {}, $pkg;
65         $self->{msgno} = shift;
66         my $to = shift;
67         #  $to =~ s/-\d+$//o;
68         $self->{to} = $to;
69         my $from = shift;
70         $from =~ s/-\d+$//o;
71         $self->{from} = uc $from;
72         $self->{t} = shift;
73         $self->{private} = shift;
74         $self->{subject} = shift;
75         $self->{origin} = shift;
76         $self->{read} = shift;
77         $self->{rrreq} = shift;
78         $self->{gotit} = [];
79     
80         return $self;
81 }
82
83 sub workclean
84 {
85         my $ref = shift;
86         delete $ref->{lines};
87         delete $ref->{linesreq};
88         delete $ref->{tonode};
89         delete $ref->{fromnode};
90         delete $ref->{stream};
91         delete $ref->{lines};
92         delete $ref->{file};
93         delete $ref->{count};
94 }
95
96 sub process
97 {
98         my ($self, $line) = @_;
99         my @f = split /[\^\~]/, $line;
100         my ($pcno) = $f[0] =~ /^PC(\d\d)/; # just get the number
101         
102  SWITCH: {
103                 if ($pcno == 28) {              # incoming message
104                         my $t = cltounix($f[5], $f[6]);
105                         my $stream = next_transno($f[2]);
106                         my $ref = DXMsg->alloc($stream, uc $f[3], $f[4], $t, $f[7], $f[8], $f[13], '0', $f[11]);
107                         
108                         # fill in various forwarding state variables
109                         $ref->{fromnode} = $f[2];
110                         $ref->{tonode} = $f[1];
111                         $ref->{rrreq} = $f[11];
112                         $ref->{linesreq} = $f[10];
113                         $ref->{stream} = $stream;
114                         $ref->{count} = 0;      # no of lines between PC31s
115                         dbg('msg', "new message from $f[4] to $f[3] '$f[8]' stream $stream\n");
116                         $work{"$f[2]$stream"} = $ref; # store in work
117                         $busy{$f[2]} = $ref; # set interlock
118                         $self->send(DXProt::pc30($f[2], $f[1], $stream)); # send ack
119                         last SWITCH;
120                 }
121                 
122                 if ($pcno == 29) {              # incoming text
123                         my $ref = $work{"$f[2]$f[3]"};
124                         if ($ref) {
125                                 push @{$ref->{lines}}, $f[4];
126                                 $ref->{count}++;
127                                 if ($ref->{count} >= $ref->{linesreq}) {
128                                         $self->send(DXProt::pc31($f[2], $f[1], $f[3]));
129                                         dbg('msg', "stream $f[3]: $ref->{count} lines received\n");
130                                         $ref->{count} = 0;
131                                 }
132                         }
133                         last SWITCH;
134                 }
135                 
136                 if ($pcno == 30) {              # this is a incoming subject ack
137                         my $ref = $work{$f[2]}; # note no stream at this stage
138                         delete $work{$f[2]};
139                         $ref->{stream} = $f[3];
140                         $ref->{count} = 0;
141                         $ref->{linesreq} = 5;
142                         $work{"$f[2]$f[3]"} = $ref;     # new ref
143                         dbg('msg', "incoming subject ack stream $f[3]\n");
144                         $busy{$f[2]} = $ref; # interlock
145                         $ref->{lines} = [];
146                         push @{$ref->{lines}}, ($ref->read_msg_body);
147                         $ref->send_tranche($self);
148                         last SWITCH;
149                 }
150                 
151                 if ($pcno == 31) {              # acknowledge a tranche of lines
152                         my $ref = $work{"$f[2]$f[3]"};
153                         if ($ref) {
154                                 dbg('msg', "tranche ack stream $f[3]\n");
155                                 $ref->send_tranche($self);
156                         } else {
157                                 $self->send(DXProt::pc42($f[2], $f[1], $f[3])); # unknown stream
158                         } 
159                         last SWITCH;
160                 }
161                 
162                 if ($pcno == 32) {              # incoming EOM
163                         dbg('msg', "stream $f[3]: EOM received\n");
164                         my $ref = $work{"$f[2]$f[3]"};
165                         if ($ref) {
166                                 $self->send(DXProt::pc33($f[2], $f[1], $f[3])); # acknowledge it
167                                 
168                                 # get the next msg no - note that this has NOTHING to do with the stream number in PC protocol
169                                 # store the file or message
170                                 # remove extraneous rubbish from the hash
171                                 # remove it from the work in progress vector
172                                 # stuff it on the msg queue
173                                 if ($ref->{lines} && @{$ref->{lines}} > 0) { # ignore messages with 0 lines
174                                         if ($ref->{file}) {
175                                                 $ref->store($ref->{lines});
176                                         } else {
177                                                 $ref->{msgno} = next_transno("Msgno");
178                                                 push @{$ref->{gotit}}, $f[2]; # mark this up as being received
179                                                 $ref->store($ref->{lines});
180                                                 add_dir($ref);
181                                                 my $dxchan = DXChannel->get($ref->{to});
182                                                 $dxchan->send("New mail has arrived for you") if $dxchan;
183                                                 Log('msg', "Message $ref->{msgno} from $ref->{from} received from $f[2] for $ref->{to}");
184                                         }
185                                 }
186                                 $ref->stop_msg($self);
187                                 queue_msg();
188                         } else {
189                                 $self->send(DXProt::pc42($f[2], $f[1], $f[3])); # unknown stream
190                         }
191                         queue_msg();
192                         last SWITCH;
193                 }
194                 
195                 if ($pcno == 33) {              # acknowledge the end of message
196                         my $ref = $work{"$f[2]$f[3]"};
197                         if ($ref) {
198                                 if ($ref->{private}) { # remove it if it private and gone off site#
199                                         Log('msg', "Message $ref->{msgno} from $ref->{from} sent to $f[2] and deleted");
200                                         $ref->del_msg;
201                                 } else {
202                                         Log('msg', "Message $ref->{msgno} from $ref->{from} sent to $f[2]");
203                                         push @{$ref->{gotit}}, $f[2]; # mark this up as being received
204                                         $ref->store($ref->{lines});     # re- store the file
205                                 }
206                                 $ref->stop_msg($self);
207                         } else {
208                                 $self->send(DXProt::pc42($f[2], $f[1], $f[3])); # unknown stream
209                         } 
210                         queue_msg();
211                         last SWITCH;
212                 }
213                 
214                 if ($pcno == 40) {              # this is a file request
215                         $f[3] =~ s/\\/\//og; # change the slashes
216                         $f[3] =~ s/\.//og;      # remove dots
217                         $f[3] =~ s/^\///o;   # remove the leading /
218                         $f[3] = lc $f[3];       # to lower case;
219                         dbg('msg', "incoming file $f[3]\n");
220                         last SWITCH if $f[3] =~ /^(perl|cmd|local|src|lib|include|sys|msg|connect)/; # prevent access to executables
221                         
222                         # create any directories
223                         my @part = split /\//, $f[3];
224                         my $part;
225                         my $fn = "$main::root";
226                         pop @part;                      # remove last part
227                         foreach $part (@part) {
228                                 $fn .= "/$part";
229                                 next if -e $fn;
230                                 last SWITCH if !mkdir $fn, 0777;
231                                 dbg('msg', "created directory $fn\n");
232                         }
233                         my $stream = next_transno($f[2]);
234                         my $ref = DXMsg->alloc($stream, "$main::root/$f[3]", $self->call, time, !$f[4], $f[3], ' ', '0', '0');
235                         
236                         # forwarding variables
237                         $ref->{fromnode} = $f[1];
238                         $ref->{tonode} = $f[2];
239                         $ref->{linesreq} = $f[5];
240                         $ref->{stream} = $stream;
241                         $ref->{count} = 0;      # no of lines between PC31s
242                         $ref->{file} = 1;
243                         $work{"$f[2]$stream"} = $ref; # store in work
244                         $self->send(DXProt::pc30($f[2], $f[1], $stream)); # send ack 
245                         
246                         last SWITCH;
247                 }
248                 
249                 if ($pcno == 42) {              # abort transfer
250                         dbg('msg', "stream $f[3]: abort received\n");
251                         my $ref = $work{"$f[2]$f[3]"};
252                         if ($ref) {
253                                 $ref->stop_msg($self);
254                                 $ref = undef;
255                         }
256                         
257                         last SWITCH;
258                 }
259         }
260          
261          clean_old() if $main::systime - $last_clean > 3600 ; # clean the message queue
262 }
263
264
265 # store a message away on disc or whatever
266 #
267 # NOTE the second arg is a REFERENCE not a list
268 sub store
269 {
270         my $ref = shift;
271         my $lines = shift;
272         
273         # we only proceed if there are actually any lines in the file
274         if (!$lines || @{$lines} == 0) {
275                 return;
276         }
277         
278         if ($ref->{file}) {                     # a file
279                 dbg('msg', "To be stored in $ref->{to}\n");
280                 
281                 my $fh = new FileHandle "$ref->{to}", "w";
282                 if (defined $fh) {
283                         my $line;
284                         foreach $line (@{$lines}) {
285                                 print $fh "$line\n";
286                         }
287                         $fh->close;
288                         dbg('msg', "file $ref->{to} stored\n");
289                         Log('msg', "file $ref->{to} from $ref->{from} stored" );
290                 } else {
291                         confess "can't open file $ref->{to} $!";  
292                 }
293         } else {                                        # a normal message
294                 
295                 # attempt to open the message file
296                 my $fn = filename($ref->{msgno});
297                 
298                 dbg('msg', "To be stored in $fn\n");
299                 
300                 # now save the file, overwriting what's there, YES I KNOW OK! (I will change it if it's a problem)
301                 my $fh = new FileHandle "$fn", "w";
302                 if (defined $fh) {
303                         my $rr = $ref->{rrreq} ? '1' : '0';
304                         my $priv = $ref->{private} ? '1': '0';
305                         print $fh "=== $ref->{msgno}^$ref->{to}^$ref->{from}^$ref->{t}^$priv^$ref->{subject}^$ref->{origin}^$ref->{read}^$rr\n";
306                         print $fh "=== ", join('^', @{$ref->{gotit}}), "\n";
307                         my $line;
308                         $ref->{size} = 0;
309                         foreach $line (@{$lines}) {
310                                 $ref->{size} += (length $line) + 1;
311                                 print $fh "$line\n";
312                         }
313                         $fh->close;
314                         dbg('msg', "msg $ref->{msgno} stored\n");
315                         Log('msg', "msg $ref->{msgno} from $ref->{from} to $ref->{to} stored" );
316                 } else {
317                         confess "can't open msg file $fn $!";  
318                 }
319         }
320 }
321
322 # delete a message
323 sub del_msg
324 {
325         my $self = shift;
326         
327         # remove it from the active message list
328         @msg = map { $_ != $self ? $_ : () } @msg;
329         
330         # belt and braces (one day I will ask someone if this is REALLY necessary)
331         delete $self->{gotit};
332         delete $self->{list};
333         
334         # remove the file
335         unlink filename($self->{msgno});
336         dbg('msg', "deleting $self->{msgno}\n");
337 }
338
339 # clean out old messages from the message queue
340 sub clean_old
341 {
342         my $ref;
343         
344         # mark old messages for deletion
345         foreach $ref (@msg) {
346                 if (!$ref->{keep} && $ref->{t} < $main::systime - $maxage) {
347                         $ref->{deleteme} = 1;
348                         delete $ref->{gotit};
349                         delete $ref->{list};
350                         unlink filename($ref->{msgno});
351                         dbg('msg', "deleting old $ref->{msgno}\n");
352                 }
353         }
354         
355         # remove them all from the active message list
356         @msg = map { $_->{deleteme} ? () : $_ } @msg;
357         $last_clean = $main::systime;
358 }
359
360 # read in a message header
361 sub read_msg_header
362
363         my $fn = shift;
364         my $file;
365         my $line;
366         my $ref;
367         my @f;
368         my $size;
369         
370         $file = new FileHandle;
371         if (!open($file, $fn)) {
372                 print "Error reading $fn $!\n";
373                 return undef;
374         }
375         $size = -s $fn;
376         $line = <$file>;                        # first line
377         chomp $line;
378         $size -= length $line;
379         if (! $line =~ /^===/o) {
380                 print "corrupt first line in $fn ($line)\n";
381                 return undef;
382         }
383         $line =~ s/^=== //o;
384         @f = split /\^/, $line;
385         $ref = DXMsg->alloc(@f);
386         
387         $line = <$file>;                        # second line
388         chomp $line;
389         $size -= length $line;
390         if (! $line =~ /^===/o) {
391                 print "corrupt second line in $fn ($line)\n";
392                 return undef;
393         }
394         $line =~ s/^=== //o;
395         $ref->{gotit} = [];
396         @f = split /\^/, $line;
397         push @{$ref->{gotit}}, @f;
398         $ref->{size} = $size;
399         
400         close($file);
401         
402         return $ref;
403 }
404
405 # read in a message header
406 sub read_msg_body
407 {
408         my $self = shift;
409         my $msgno = $self->{msgno};
410         my $file;
411         my $line;
412         my $fn = filename($msgno);
413         my @out;
414         
415         $file = new FileHandle;
416         if (!open($file, $fn)) {
417                 print "Error reading $fn $!\n";
418                 return undef;
419         }
420         chomp (@out = <$file>);
421         close($file);
422         
423         shift @out if $out[0] =~ /^=== /;
424         shift @out if $out[0] =~ /^=== /;
425         return @out;
426 }
427
428 # send a tranche of lines to the other end
429 sub send_tranche
430 {
431         my ($self, $dxchan) = @_;
432         my @out;
433         my $to = $self->{tonode};
434         my $from = $self->{fromnode};
435         my $stream = $self->{stream};
436         my $i;
437         
438         for ($i = 0; $i < $self->{linesreq} && $self->{count} < @{$self->{lines}}; $i++, $self->{count}++) {
439                 push @out, DXProt::pc29($to, $from, $stream, ${$self->{lines}}[$self->{count}]);
440 }
441 push @out, DXProt::pc32($to, $from, $stream) if $i < $self->{linesreq};
442 $dxchan->send(@out);
443 }
444
445         
446         # find a message to send out and start the ball rolling
447         sub queue_msg
448 {
449         my $sort = shift;
450         my @nodelist = DXProt::get_all_ak1a();
451         my $ref;
452         my $clref;
453         my $dxchan;
454         
455         # bat down the message list looking for one that needs to go off site and whose
456         # nearest node is not busy.
457         
458         dbg('msg', "queue msg ($sort)\n");
459         foreach $ref (@msg) {
460                 # firstly, is it private and unread? if so can I find the recipient
461                 # in my cluster node list offsite?
462                 if ($ref->{private}) {
463                         if ($ref->{read} == 0) {
464                                 $clref = DXCluster->get($ref->{to});
465                                 if ($clref && !grep { $clref->{dxchan} == $_ } DXCommandmode::get_all) {
466                                         $dxchan = $clref->{dxchan};
467                                         $ref->start_msg($dxchan) if $clref && !get_busy($dxchan->call);
468                                 }
469                         }
470                 } elsif ($sort == undef) {
471                         # otherwise we are dealing with a bulletin, compare the gotit list with
472                         # the nodelist up above, if there are sites that haven't got it yet
473                         # then start sending it - what happens when we get loops is anyone's
474                         # guess, use (to, from, time, subject) tuple?
475                         my $noderef;
476                         foreach $noderef (@nodelist) {
477                                 next if $noderef->call eq $main::mycall;
478                                 next if grep { $_ eq $noderef->call } @{$ref->{gotit}};
479                                 
480                                 # if we are here we have a node that doesn't have this message
481                                 $ref->start_msg($noderef) if !get_busy($noderef->call);
482                                 last;
483                         } 
484                 }
485                 
486                 # if all the available nodes are busy then stop
487                 last if @nodelist == scalar grep { get_busy($_->call) } @nodelist;
488         }
489 }
490
491 # start the message off on its travels with a PC28
492 sub start_msg
493 {
494         my ($self, $dxchan) = @_;
495         
496         dbg('msg', "start msg $self->{msgno}\n");
497         $self->{linesreq} = 5;
498         $self->{count} = 0;
499         $self->{tonode} = $dxchan->call;
500         $self->{fromnode} = $main::mycall;
501         $busy{$dxchan->call} = $self;
502         $work{"$self->{tonode}"} = $self;
503         $dxchan->send(DXProt::pc28($self->{tonode}, $self->{fromnode}, $self->{to}, $self->{from}, $self->{t}, $self->{private}, $self->{subject}, $self->{origin}, $self->{rrreq}));
504 }
505
506 # get the ref of a busy node
507 sub get_busy
508 {
509         my $call = shift;
510         return $busy{$call};
511 }
512
513 # get the busy queue
514 sub get_all_busy
515 {
516         return values %busy;
517 }
518
519 # get the forwarding queue
520 sub get_fwq
521 {
522         return values %work;
523 }
524
525 # stop a message from continuing, clean it out, unlock interlocks etc
526 sub stop_msg
527 {
528         my ($self, $dxchan) = @_;
529         my $node = $dxchan->call;
530         
531         dbg('msg', "stop msg $self->{msgno} stream $self->{stream}\n");
532         delete $work{$node};
533         delete $work{"$node$self->{stream}"};
534         $self->workclean;
535         delete $busy{$node};
536 }
537
538 # get a new transaction number from the file specified
539 sub next_transno
540 {
541         my $name = shift;
542         $name =~ s/\W//og;                      # remove non-word characters
543         my $fn = "$msgdir/$name";
544         my $msgno;
545         
546         my $fh = new FileHandle;
547         if (sysopen($fh, $fn, O_RDWR|O_CREAT, 0666)) {
548                 $fh->autoflush(1);
549                 $msgno = $fh->getline;
550                 chomp $msgno;
551                 $msgno++;
552                 seek $fh, 0, 0;
553                 $fh->print("$msgno\n");
554                 dbg('msg', "msgno $msgno allocated for $name\n");
555                 $fh->close;
556         } else {
557                 confess "can't open $fn $!";
558         }
559         return $msgno;
560 }
561
562 # initialise the message 'system', read in all the message headers
563 sub init
564 {
565         my $dir = new FileHandle;
566         my @dir;
567         my $ref;
568         
569         # read in the directory
570         opendir($dir, $msgdir) or confess "can't open $msgdir $!";
571         @dir = readdir($dir);
572         closedir($dir);
573         
574         for (sort @dir) {
575                 next if /^\./o;
576                 next if ! /^m\d+/o;
577                 
578                 $ref = read_msg_header("$msgdir/$_");
579                 next if !$ref;
580                 
581                 # add the message to the available queue
582                 add_dir($ref); 
583                 
584         }
585 }
586
587 # add the message to the directory listing
588 sub add_dir
589 {
590         my $ref = shift;
591         confess "tried to add a non-ref to the msg directory" if !ref $ref;
592         push @msg, $ref;
593 }
594
595 # return all the current messages
596 sub get_all
597 {
598         return @msg;
599 }
600
601 # get a particular message
602 sub get
603 {
604         my $msgno = shift;
605         for (@msg) {
606                 return $_ if $_->{msgno} == $msgno;
607                 last if $_->{msgno} > $msgno;
608         }
609         return undef;
610 }
611
612 # return the official filename for a message no
613 sub filename
614 {
615         return sprintf "$msgdir/m%06d", shift;
616 }
617
618 #
619 # return a list of valid elements 
620
621
622 sub fields
623 {
624         return keys(%valid);
625 }
626
627 #
628 # return a prompt for a field
629 #
630
631 sub field_prompt
632
633         my ($self, $ele) = @_;
634         return $valid{$ele};
635 }
636
637 #
638 # send a message state machine
639 sub do_send_stuff
640 {
641         my $self = shift;
642         my $line = shift;
643         my @out;
644         
645         if ($self->state eq 'send1') {
646                 #  $DB::single = 1;
647                 confess "local var gone missing" if !ref $self->{loc};
648                 my $loc = $self->{loc};
649                 $loc->{subject} = $line;
650                 $loc->{lines} = [];
651                 $self->state('sendbody');
652                 #push @out, $self->msg('sendbody');
653                 push @out, "Enter Message /EX (^Z) to send or /ABORT (^Y) to exit";
654         } elsif ($self->state eq 'sendbody') {
655                 confess "local var gone missing" if !ref $self->{loc};
656                 my $loc = $self->{loc};
657                 if ($line eq "\032" || uc $line eq "/EX") {
658                         my $to;
659                         
660                         if (@{$loc->{lines}} > 0) {
661                                 foreach $to (@{$loc->{to}}) {
662                                         my $ref;
663                                         my $systime = $main::systime;
664                                         my $mycall = $main::mycall;
665                                         $ref = DXMsg->alloc(DXMsg::next_transno('Msgno'),
666                                                                                 uc $to,
667                                                                                 $self->call, 
668                                                                                 $systime,
669                                                                                 $loc->{private}, 
670                                                                                 $loc->{subject}, 
671                                                                                 $mycall,
672                                                                                 '0',
673                                                                                 $loc->{rrreq});
674                                         $ref->store($loc->{lines});
675                                         $ref->add_dir();
676                                         #push @out, $self->msg('sendsent', $to);
677                                         push @out, "msgno $ref->{msgno} sent to $to";
678                                         my $dxchan = DXChannel->get(uc $to);
679                                         if ($dxchan) {
680                                                 if ($dxchan->is_user()) {
681                                                         $dxchan->send("New mail has arrived for you");
682                                                 }
683                                         }
684                                 }
685                         }
686                         delete $loc->{lines};
687                         delete $loc->{to};
688                         delete $self->{loc};
689                         $self->state('prompt');
690                         $self->func(undef);
691                         DXMsg::queue_msg();
692                 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
693                         #push @out, $self->msg('sendabort');
694                         push @out, "aborted";
695                         delete $loc->{lines};
696                         delete $loc->{to};
697                         delete $self->{loc};
698                         $self->func(undef);
699                         $self->state('prompt');
700                 } else {
701                         
702                         # i.e. it ain't and end or abort, therefore store the line
703                         push @{$loc->{lines}}, $line;
704                 }
705         }
706         return (1, @out);
707 }
708
709 # return the standard directory line for this ref 
710 sub dir
711 {
712         my $ref = shift;
713         return sprintf "%6d%s%s%5d %8.8s %8.8s %-6.6s %5.5s %-30.30s", 
714                 $ref->msgno, $ref->read ? '-' : ' ', $ref->private ? 'p' : ' ', $ref->size,
715                         $ref->to, $ref->from, cldate($ref->t), ztime($ref->t), $ref->subject;
716 }
717
718 no strict;
719 sub AUTOLOAD
720 {
721         my $self = shift;
722         my $name = $AUTOLOAD;
723         return if $name =~ /::DESTROY$/;
724         $name =~ s/.*:://o;
725         
726         confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
727         @_ ? $self->{$name} = shift : $self->{$name} ;
728 }
729
730 1;
731
732 __END__