Address.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 179 CC 14 SCAR 31.9
CC
14
Cov
0%
string
72.0
_init
12.0
zone
6.0
CRAP 24.2
1 #!/usr/bin/perl
2  
3 # EvilBoss-api - API for creating FTN-tools
4 #
5 # EBAddress.pm - work with FTN-style addresses
6 #
7 # Copyright (c) 2004-2005 Alex Soukhotine, 2:5030/1157
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # $Id$
15  
16 package EvilBoss::Address;
17  
18 require Exporter;
19  
20 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
21  
22 $VERSION = 1.00;
23  
24 @ISA=qw(Exporter);
25 #@EXPORT = qw(&f1 &f3 &name);
26 %EXPORT_TAGS=();
27  
28 #@EXPORT_OK = qw(&name);
29  
30 use overload '==' => \&equal,
31 'eq' => \&equal,
32 '!=' => \&notequal,
33 'ne' => \&notequal,
34 '""' => \&stringify;
35  
36 sub equal
37 {
38 my ($a1,$a2)=@_;
39 return $a1->string eq $a2->string;
40 }
41  
42 sub noequal
43 {
44 my ($a1,$a2)=@_;
45 return $a1->string ne $a2->string;
46 }
47  
48  
49 sub new
50 {
51 my $classname = shift;
52 my $self = {};
53 bless($self,$classname);
54 $self->_init(@_);
55 return $self;
56 }
57  
58 sub DESTROY
59 {
60 my $self = shift;
61 }
62  
63 sub _init
64 {
65 my $self = shift;
66 $self->{string} = "0:0/0";
67 $self->{zone} = 0;
68 $self->{net} = 0;
69 $self->{node} = 0;
70 $self->{point} = 0;
71 if (@_)
72 {
73 my %extra = @_;
74 @$self{keys %extra} = values %extra;
75
76 $self->{string} = $self->string($extra{string}) if ($extra{string});
77
78 }
79 }
80  
81 sub zone
82 {
83 my $self = shift;
84 if (@_)
85 {
86 $self->{zone} = shift;
87 }
88 return $self->{zone};
89 }
90  
91  
92 sub net
93 {
94 my $self = shift;
95 if (@_)
96 {
97 $self->{net} = shift;
98 }
99 return $self->{net};
100 }
101  
102 sub node
103 {
104 my $self = shift;
105 if (@_)
106 {
107 $self->{node} = shift;
108 }
109 return $self->{node};
110 }
111  
112  
113 sub point
114 {
115 my $self = shift;
116 if (@_)
117 {
118 $self->{point} = shift;
119 }
120 return $self->{point};
121 }
122  
123 sub string
124 {
125 my $self = shift;
126 if (@_)
127 {
128 my @tmp = @_;
129
130 if ($tmp[0]=~/(\d+):(\d+)\/(\d+)\.?(\d+)?/)
131 {
132 $self->{zone} = $1;
133 $self->{net} = $2;
134 $self->{node} = $3;
135 $self->{point} = $4;
136 }
137 else
138 {
139 if ($tmp[0]=~/^\d+$/ && $tmp[1]=~/^\d+$/ && $tmp[2]=~/^\d+$/ && $tmp[3]=~/^\d+$/)
140 {
141 $self->{zone} = $tmp[0];
142 $self->{net} = $tmp[1];
143 $self->{node} = $tmp[2];
144 $self->{point} = $tmp[3];
145 }
146 elsif ($tmp[0]=~/^\d+$/ && $tmp[1]=~/^\d+$/ && $tmp[2]=~/^\d+$/ && $tmp[3]!~/^\d+$/)
147 {
148 $self->{zone} = $tmp[0];
149 $self->{net} = $tmp[1];
150 $self->{node} = $tmp[2];
151 }
152 elsif ($tmp[0]=~/^\d+$/ && $tmp[1]=~/^\d+$/ && $tmp[2]!~/^\d+$/ && $tmp[3]!~/^\d+$/)
153 {
154 $self->{zone} = $tmp[0];
155 $self->{net} = $tmp[1];
156 }
157 elsif ($tmp[0]=~/^\d+$/ && $tmp[1]!~/^\d+$/ && $tmp[2]!~/^\d+$/ && $tmp[3]!~/^\d+$/)
158 {
159 $self->{zone} = $tmp[0];
160 }
161 }
162 }
163 $self->{string}=sprintf("%d",$self->zone).":".sprintf("%d",$self->net)."/".sprintf("%d",$self->node);
164 $self->{string}.=".".sprintf("%d",$self->point) if ($self->point);
165 return $self->{string};
166 }
167  
168 sub string3d
169 {
170 my $self=shift;
171 return sprintf("%d:%d/%d",$self->zone,$self->net,$self->node);
172 }
173  
174 sub stringify
175 {
176 my $self = shift;
177 return $self->{string};
178 }
179  
180 1;