5bce28b1f5bea78e7dda2209ce29228ece0c578e
[spider.git] / perl / PC.pm
1 #
2 # OO version of all the PC protocol stuff
3 #
4 # Here is done all reception, validation and generation of PC
5 # protocol frames
6 #
7 # This uses the Prot class as a basis for all 
8 # protocol entities
9 #
10
11
12 use vars qw($VERSION $BRANCH);
13 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
14 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
15 $main::build += $VERSION;
16 $main::branch += $BRANCH;
17
18 package PC10;
19
20 @ISA = qw(Prot);
21 use DXUtil;
22
23 use strict;
24
25 sub new
26 {
27         my $pkg = shift;
28         my $self = SUPER->new($pkg);
29         $self->{from} = shift;
30         $self->{to} = shift;     # is TO if {to} is blank
31         $self->{text} = shift;
32     $self->{flag} = shift;
33     my $auxto = shift;
34     $self->{origin} = shift;
35
36         # sort out the to/via dillema and do some validation
37         if (is_callsign($auxto)) {
38                 $self->{via} = $self->{to};
39                 $self->{to} = $auxto;
40                 return undef unless is_callsign($self->{via});
41         }
42         return undef unless is_callsign($self->{from}) && is_callsign($self->{to}) && is_callsign($self->{origin}) && is_pctext($self->{text}) && is_pcflag($self->{flag});
43         return $self;
44 }
45
46 sub out {
47         my $self = shift;
48         my $addra = $self->{via} || $self->{to};
49     my $addrb = exists $self->{via} ? $self->{to} : ' ';
50         return "PC10^$self->{from}^$addra^$self->{text}^$self->{flag}^$addrb^$self->{origin}^~";
51 }
52
53 1;
54 __END__