| 1 | # FTN/Address.pm | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Copyright (c) 2005-2006 Serguei Trouchelle. All rights reserved. | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 6 | # under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # History: | ||||||||||||||||||||||||||||
| 9 | # 1.03 2007/02/04 Quality update (Test::Pod, Test::Pod::Coverage), Data::Define used | ||||||||||||||||||||||||||||
| 10 | # 1.02 2006/09/07 Added empty value processing | ||||||||||||||||||||||||||||
| 11 | # 1.01 2005/02/16 Initial revision | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | FTN::Address - Process FTN addresses | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my $addr = new FTN::Address('2:464/4077'); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | my $address4D = $addr->get(); # 2:464/4077.0 | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | my $address5D = $addr->getfull(); # 2:464/4077.0@fidonet | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | my $fqdn = $addr->fqdn(); # f4077.n464.z2.fidonet.net | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $addr = empty FTN::Address(); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | $addr->assign('2:464/4077'); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | my $address4D = $addr->get(); # 2:464/4077.0 | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | FTN::Address | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head1 METHODS | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head2 new | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | This method creates FTN::Address object. | ||||||||||||||||||||||||||||
| 43 | Takes FTN address as argument. Address can be feed in three addressing variants: | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 3D, ex.: new FTN::Address '2:464/0' | ||||||||||||||||||||||||||||
| 46 | 4D, ex.: new FTN::Address '2:464/4077.1' | ||||||||||||||||||||||||||||
| 47 | 5D, ex.: new FTN::Address '2:464/357.0@fidonet' | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Default domain for 3D and 4D address is 'fidonet' | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head2 empty | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | This method creates empty FTN::Address object. | ||||||||||||||||||||||||||||
| 54 | You cannot use it before assigning a new value. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Takes no parameters. | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head2 assign( $address ) | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | This method assign new address to FTN::Address object. | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Takes FTN address as argument (like 'new' method). | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head2 get() | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | This method returns qualified 4D address. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Takes no parameters. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head2 getfull() | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | This method returns qualified 5D address. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Takes no parameters. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head2 fqdn( [ $root_domain [, $level ] ] ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | This method returns fully qualified domain name, as described in FSP-1026 | ||||||||||||||||||||||||||||
| 79 | Fidonet Technical Standards Comittee document. See this document for details. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Valid values for level are "0, 1, 2, 3, 4, DOM, DO1, DO2, DO3, DO4" | ||||||||||||||||||||||||||||
| 82 | Parameters can be omitted, default values will be used. | ||||||||||||||||||||||||||||
| 83 | Default root domain is 'net', default level is '0'. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Examples: | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | my $addr = new FTN::Address('2:464/4077'); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | print $addr->fqdn(); # f4077.n464.z2.fidonet.net | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | print $addr->fqdn('org'); # f4077.n464.z2.fidonet.org | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | print $addr->fqdn('railways.dp.ua', 2); # f4077.n464.railways.dp.ua | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Serguei Trouchelle E<lt>F<stro@railways.dp.ua>E<gt> | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Copyright (c) 2005-2006 Serguei Trouchelle. All rights reserved. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 104 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | package FTN::Address; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 8 | require Exporter; | |||||||||||||||||||||||||||
| 111 | 8 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 8 | ▶ | use Data::Define qw/brockets/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 8 | our @EXPORT_OK = qw//; | |||||||||||||||||||||||||||
| 119 | 8 | our %EXPORT_TAGS = (); | |||||||||||||||||||||||||||
| 120 | 8 | our @ISA = qw/Exporter/; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 8 | $FTN::Address::VERSION = "1.03"; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 8 | our $DEFAULT_DOMAIN = 'fidonet'; | |||||||||||||||||||||||||||
| 125 | 8 | our $DEFAULT_ROOT = 'net'; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # | ||||||||||||||||||||||||||||
| 128 | # Constructor | ||||||||||||||||||||||||||||
| 129 | # | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sub new { | ||||||||||||||||||||||||||||
| 132 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 14 | my $addr = shift; | |||||||||||||||||||||||||||
| 134 | 14 | ▶ | if ($addr and $addr =~ m!^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$addr and $addr =~ m[^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$]
MC/DC50%1/2
$addr and $addr =~ m[^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$]
$addr
$addr =~ m[^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$]
Truth table66%2/3
A and B
A= $addrB= $addr =~ m[^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$]
| |||||||||||||||||||||||||||||
| 135 | 13 | ▶ | $self = | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 136 | {'z' => $1, | ||||||||||||||||||||||||||||
| 137 | 'n' => $2, | ||||||||||||||||||||||||||||
| 138 | 'f' => $3, | ||||||||||||||||||||||||||||
| 139 | 'p' => $5 ? $5 : 0, | ||||||||||||||||||||||||||||
| 140 | 'd' => $7 ? $7 : $DEFAULT_DOMAIN, | ||||||||||||||||||||||||||||
| 141 | }; | ||||||||||||||||||||||||||||
| 142 | $self->{'__addr'} = $self->{'z'} . ':' . $self->{'n'} . '/' . | ||||||||||||||||||||||||||||
| 143 | 13 | $self->{'f'} . '.' . $self->{'p'}; | |||||||||||||||||||||||||||
| 144 | 13 | $self->{'__addrd'} = $self->{'__addr'} . '@' . $self->{'d'}; | |||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||
| 146 | 1 | $@ = join('', 'Invalid address: ', define($addr)); | |||||||||||||||||||||||||||
| 147 | 1 | return undef; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 13 | bless $self; | |||||||||||||||||||||||||||
| 151 | 13 | return $self; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # | ||||||||||||||||||||||||||||
| 155 | # Empty constructor | ||||||||||||||||||||||||||||
| 156 | # | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub empty { | ||||||||||||||||||||||||||||
| 159 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | 6 | $self = {'__empty' => 1}; | |||||||||||||||||||||||||||
| 161 | 6 | bless $self; | |||||||||||||||||||||||||||
| 162 | 6 | return $self; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # | ||||||||||||||||||||||||||||
| 166 | # Assign new value | ||||||||||||||||||||||||||||
| 167 | # | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | sub assign { | ||||||||||||||||||||||||||||
| 170 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
assign: called CC=5 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||
| 171 | 5 | my $addr = shift; | |||||||||||||||||||||||||||
| 172 | 5 | ▶ | if ($addr and $addr =~ m!^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$addr and $addr =~ m[^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$]
MC/DC0%0/2
$addr and $addr =~ m[^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$]
$addr
$addr =~ m[^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$]
Truth table33%1/3
A and B
A= $addrB= $addr =~ m[^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$]
| |||||||||||||||||||||||||||||
| 173 | 5 | $self->{'z'} = $1; | |||||||||||||||||||||||||||
| 174 | 5 | $self->{'n'} = $2; | |||||||||||||||||||||||||||
| 175 | 5 | $self->{'f'} = $3; | |||||||||||||||||||||||||||
| 176 | 5 | ▶ | $self->{'p'} = $5 ? $5 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 5 | ▶ | $self->{'d'} = $7 ? $7 : $DEFAULT_DOMAIN; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | $self->{'__addr'} = $self->{'z'} . ':' . $self->{'n'} . '/' . | ||||||||||||||||||||||||||||
| 179 | 5 | $self->{'f'} . '.' . $self->{'p'}; | |||||||||||||||||||||||||||
| 180 | 5 | $self->{'__addrd'} = $self->{'__addr'} . '@' . $self->{'d'}; | |||||||||||||||||||||||||||
| 181 | 5 | delete $self->{'__empty'}; | |||||||||||||||||||||||||||
| 182 | } else { | ||||||||||||||||||||||||||||
| 183 | 0 | $@ = join('', 'Invalid address: ', $addr); | |||||||||||||||||||||||||||
| 184 | 0 | $self->{'__empty'} = 1; | |||||||||||||||||||||||||||
| 185 | 0 | return undef; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | # | ||||||||||||||||||||||||||||
| 190 | # get 4D address | ||||||||||||||||||||||||||||
| 191 | # | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | sub get { | ||||||||||||||||||||||||||||
| 194 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | 4 | ▶ | if ($self->{'__empty'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | $@ = 'Cannot use empty FTN::Address object'; | |||||||||||||||||||||||||||
| 197 | 0 | return undef; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 4 | return $self->{'__addr'}; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | # | ||||||||||||||||||||||||||||
| 203 | # get 5D address | ||||||||||||||||||||||||||||
| 204 | # | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | sub getfull { | ||||||||||||||||||||||||||||
| 207 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
getfull: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||||||||||||||||||||
| 208 | 4 | ▶ | if ($self->{'__empty'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | $@ = 'Cannot use empty FTN::Address object'; | |||||||||||||||||||||||||||
| 210 | 0 | return undef; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | 4 | return $self->{'__addrd'}; | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # | ||||||||||||||||||||||||||||
| 216 | # get FQDN | ||||||||||||||||||||||||||||
| 217 | # | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | sub fqdn { | ||||||||||||||||||||||||||||
| 220 | 16 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
fqdn: called CC=13 SCAR=26.9
Pod
documented
| |||||||||||||||||||||||||||||
| 221 | 16 | ▶ | if ($self->{'__empty'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 1 | $@ = 'Cannot use empty FTN::Address object'; | |||||||||||||||||||||||||||
| 223 | 1 | return undef; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | 15 | ▶ | my $root = shift || $DEFAULT_ROOT; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $FTN::Address::DEFAULT_ROOT
MC/DC0%0/2
shift() || $FTN::Address::DEFAULT_ROOT
shift()
$FTN::Address::DEFAULT_ROOT
Truth table33%1/3
A || B
A= shift()B= $FTN::Address::DEFAULT_ROOT
| |||||||||||||||||||||||||||||
| 226 | 15 | ▶ | my $level = shift || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 0
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 15 | ▶ | $level = $1 if $level =~ /^DO([M1234])$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 15 | ▶ | $level = 0 if $level eq 'M'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 15 | ▶ | if ($level eq '0') { # DOM - 5D ([pPP.]fFF.nNN.zZZ.fidonet.RD) | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 232 | return ($self->{'p'} ? 'p' . $self->{'p'} . '.' : '') . | ||||||||||||||||||||||||||||
| 233 | 'f' . $self->{'f'} . '.' . | ||||||||||||||||||||||||||||
| 234 | 'n' . $self->{'n'} . '.' . | ||||||||||||||||||||||||||||
| 235 | 'z' . $self->{'z'} . '.' . | ||||||||||||||||||||||||||||
| 236 | 3 | ▶ | $self->{'d'} . '.' . $root; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | } elsif ($level eq '1') { # DO1 - 1D (fFF.RD) | ||||||||||||||||||||||||||||
| 238 | 3 | return 'f' . $self->{'f'} . '.' . | |||||||||||||||||||||||||||
| 239 | $root; | ||||||||||||||||||||||||||||
| 240 | } elsif ($level eq '2') { # DO2 - 2D (fFF.nNN.RD) | ||||||||||||||||||||||||||||
| 241 | return 'f' . $self->{'f'} . '.' . | ||||||||||||||||||||||||||||
| 242 | 3 | 'n' . $self->{'n'} . '.' . | |||||||||||||||||||||||||||
| 243 | $root; | ||||||||||||||||||||||||||||
| 244 | } elsif ($level eq '3') { # DO3 - 3D (fFF.nNN.zZZ.RD) | ||||||||||||||||||||||||||||
| 245 | return 'f' . $self->{'f'} . '.' . | ||||||||||||||||||||||||||||
| 246 | 'n' . $self->{'n'} . '.' . | ||||||||||||||||||||||||||||
| 247 | 3 | 'z' . $self->{'z'} . '.' . | |||||||||||||||||||||||||||
| 248 | $root; | ||||||||||||||||||||||||||||
| 249 | } elsif ($level eq '4') { # DO4 - 4D ([pPP.]fFF.nNN.zZZ.RD) | ||||||||||||||||||||||||||||
| 250 | return ($self->{'p'} ? 'p' . $self->{'p'} . '.' : '') . | ||||||||||||||||||||||||||||
| 251 | 'f' . $self->{'f'} . '.' . | ||||||||||||||||||||||||||||
| 252 | 'n' . $self->{'n'} . '.' . | ||||||||||||||||||||||||||||
| 253 | 3 | ▶ | 'z' . $self->{'z'} . '.' . | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | $root; | ||||||||||||||||||||||||||||
| 255 | } else { | ||||||||||||||||||||||||||||
| 256 | 0 | $@ = 'Invalid level: ' . $level; | |||||||||||||||||||||||||||
| 257 | 0 | return undef; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 8 | 1; | |||||||||||||||||||||||||||