7ec71e543a24d0a0866c3481eb5832110387541c
[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 package PC10;
12
13 @ISA = qw(Prot);
14 use DXUtil;
15
16 use strict;
17
18 sub new
19 {
20         my $pkg = shift;
21         my $self = SUPER->new($pkg);
22         $self->{from} = shift;
23         $self->{to} = shift;     # is TO if {to} is blank
24         $self->{text} = shift;
25     $self->{flag} = shift;
26     my $auxto = shift;
27     $self->{origin} = shift;
28
29         # sort out the to/via dillema and do some validation
30         if (is_callsign($auxto)) {
31                 $self->{via} = $self->{to};
32                 $self->{to} = $auxto;
33                 return undef unless is_callsign($self->{via});
34         }
35         return undef unless is_callsign($self->{from}) && is_callsign($self->{to}) && is_callsign($self->{origin}) && is_pctext($self->{text}) && is_pcflag($self->{flag});
36         return $self;
37 }
38
39 sub out {
40         my $self = shift;
41         my $addra = $self->{via} || $self->{to};
42     my $addrb = exists $self->{via} ? $self->{to} : ' ';
43         return "PC10^$self->{from}^$addra^$self->{text}^$self->{flag}^$addrb^$self->{origin}^~";
44 }
45
46 1;
47 __END__