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