line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Farly::Object;
|
2
|
|
|
|
|
|
|
|
3
|
16
|
|
|
16
|
|
80104
|
use 5.008008;
|
|
16
|
|
|
|
|
53
|
|
|
16
|
|
|
|
|
658
|
|
4
|
16
|
|
|
16
|
|
85
|
use strict;
|
|
16
|
|
|
|
|
28
|
|
|
16
|
|
|
|
|
467
|
|
5
|
16
|
|
|
16
|
|
87
|
use warnings;
|
|
16
|
|
|
|
|
28
|
|
|
16
|
|
|
|
|
428
|
|
6
|
16
|
|
|
16
|
|
73
|
use Carp;
|
|
16
|
|
|
|
|
32
|
|
|
16
|
|
|
|
|
1078
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#Farly containers
|
9
|
16
|
|
|
16
|
|
9055
|
use Farly::Object::List;
|
|
16
|
|
|
|
|
67
|
|
|
16
|
|
|
|
|
644
|
|
10
|
16
|
|
|
16
|
|
10293
|
use Farly::Object::Set;
|
|
16
|
|
|
|
|
43
|
|
|
16
|
|
|
|
|
553
|
|
11
|
16
|
|
|
16
|
|
10892
|
use Farly::Object::Aggregate;
|
|
16
|
|
|
|
|
40
|
|
|
16
|
|
|
|
|
1364
|
|
12
|
|
|
|
|
|
|
#Farly reference object
|
13
|
|
|
|
|
|
|
require Farly::Object::Ref;
|
14
|
|
|
|
|
|
|
#Farly value objects
|
15
|
16
|
|
|
16
|
|
10583
|
use Farly::Value::String;
|
|
16
|
|
|
|
|
36
|
|
|
16
|
|
|
|
|
459
|
|
16
|
16
|
|
|
16
|
|
9290
|
use Farly::Value::Integer;
|
|
16
|
|
|
|
|
37
|
|
|
16
|
|
|
|
|
445
|
|
17
|
16
|
|
|
16
|
|
9047
|
use Farly::IPv4::Address;
|
|
16
|
|
|
|
|
48
|
|
|
16
|
|
|
|
|
457
|
|
18
|
16
|
|
|
16
|
|
9161
|
use Farly::IPv4::Network;
|
|
16
|
|
|
|
|
49
|
|
|
16
|
|
|
|
|
453
|
|
19
|
16
|
|
|
16
|
|
79
|
use Farly::IPv4::Range;
|
|
16
|
|
|
|
|
27
|
|
|
16
|
|
|
|
|
385
|
|
20
|
16
|
|
|
16
|
|
9776
|
use Farly::IPv4::ICMPType;
|
|
16
|
|
|
|
|
39
|
|
|
16
|
|
|
|
|
480
|
|
21
|
16
|
|
|
16
|
|
8460
|
use Farly::Transport::Port;
|
|
16
|
|
|
|
|
38
|
|
|
16
|
|
|
|
|
426
|
|
22
|
16
|
|
|
16
|
|
9009
|
use Farly::Transport::PortGT;
|
|
16
|
|
|
|
|
47
|
|
|
16
|
|
|
|
|
436
|
|
23
|
16
|
|
|
16
|
|
8504
|
use Farly::Transport::PortLT;
|
|
16
|
|
|
|
|
39
|
|
|
16
|
|
|
|
|
488
|
|
24
|
16
|
|
|
16
|
|
9027
|
use Farly::Transport::PortRange;
|
|
16
|
|
|
|
|
48
|
|
|
16
|
|
|
|
|
461
|
|
25
|
16
|
|
|
16
|
|
9488
|
use Farly::Transport::Protocol;
|
|
16
|
|
|
|
|
42
|
|
|
16
|
|
|
|
|
17125
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '0.26';
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new {
|
30
|
1256
|
|
|
1256
|
1
|
3340
|
my ($class) = @_;
|
31
|
|
|
|
|
|
|
|
32
|
1256
|
50
|
|
|
|
2965
|
carp "constructor arguments not supported; use 'set'"
|
33
|
|
|
|
|
|
|
if ( scalar(@_) > 1 );
|
34
|
|
|
|
|
|
|
|
35
|
1256
|
|
|
|
|
4603
|
return bless {}, $class;
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub set {
|
39
|
3827
|
|
|
3827
|
1
|
5705
|
my ( $self, $key, $value ) = @_;
|
40
|
|
|
|
|
|
|
|
41
|
3827
|
50
|
33
|
|
|
15947
|
confess "invalid key"
|
42
|
|
|
|
|
|
|
unless ( defined($key) && length($key) );
|
43
|
|
|
|
|
|
|
|
44
|
3827
|
50
|
|
|
|
6930
|
confess "a value object must be defined"
|
45
|
|
|
|
|
|
|
unless ( defined($value) );
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# reference object, or list (i.e. $self is tree node), or set
|
48
|
3827
|
100
|
100
|
|
|
60105
|
if ( $value->isa('Farly::Object') || $value->isa('Farly::Object::List')
|
|
|
|
66
|
|
|
|
|
49
|
|
|
|
|
|
|
|| $value->isa('Farly::Object::Set') )
|
50
|
|
|
|
|
|
|
{
|
51
|
375
|
|
|
|
|
724
|
$self->{$key} = $value;
|
52
|
375
|
|
|
|
|
908
|
return;
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# or value object
|
56
|
3452
|
50
|
33
|
|
|
53091
|
confess "$value is not a valid value object type"
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
57
|
|
|
|
|
|
|
unless ( $value->can('equals')
|
58
|
|
|
|
|
|
|
&& $value->can('contains')
|
59
|
|
|
|
|
|
|
&& $value->can('intersects')
|
60
|
|
|
|
|
|
|
&& $value->can('compare')
|
61
|
|
|
|
|
|
|
&& $value->can('as_string') );
|
62
|
|
|
|
|
|
|
|
63
|
3452
|
|
|
|
|
13054
|
$self->{$key} = $value;
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get {
|
67
|
8925
|
|
|
8925
|
1
|
11964
|
my ( $self, $key ) = @_;
|
68
|
8925
|
50
|
|
|
|
19265
|
if ( defined( $self->{$key} ) ) {
|
69
|
8925
|
|
|
|
|
31788
|
return $self->{$key};
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
else {
|
72
|
0
|
|
|
|
|
0
|
confess $self->dump(), "\n undefined key $key. use 'has_defined' to
|
73
|
|
|
|
|
|
|
check for the existance of a key/value pair";
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub has_defined {
|
78
|
1606
|
|
|
1606
|
1
|
2099
|
my ( $self, $key ) = @_;
|
79
|
1606
|
100
|
|
|
|
7440
|
return 1 if defined $self->{$key};
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub delete_key {
|
83
|
9
|
|
|
9
|
1
|
18
|
my ( $self, $key ) = @_;
|
84
|
9
|
50
|
|
|
|
1355
|
delete $self->{$key}
|
85
|
|
|
|
|
|
|
or carp "key $key delete error";
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get_keys {
|
89
|
519
|
|
|
519
|
1
|
559
|
return keys %{ $_[0] };
|
|
519
|
|
|
|
|
2631
|
|
90
|
|
|
|
|
|
|
}
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub equals {
|
93
|
110
|
|
|
110
|
1
|
199
|
my ( $self, $other ) = @_;
|
94
|
|
|
|
|
|
|
|
95
|
110
|
100
|
|
|
|
608
|
if ( $other->isa(__PACKAGE__) ) {
|
96
|
|
|
|
|
|
|
|
97
|
57
|
50
|
|
|
|
165
|
if ( scalar( keys %$self ) != scalar( keys %$other ) ) {
|
98
|
0
|
|
|
|
|
0
|
return undef;
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
|
101
|
57
|
|
|
|
|
159
|
return $self->matches($other);
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
}
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub matches {
|
106
|
2339
|
|
|
2339
|
1
|
3282
|
my ( $self, $other ) = @_;
|
107
|
|
|
|
|
|
|
|
108
|
2339
|
50
|
|
|
|
7710
|
if ( $other->isa(__PACKAGE__) ) {
|
109
|
|
|
|
|
|
|
|
110
|
2339
|
|
|
|
|
4957
|
foreach my $key ( keys %$other ) {
|
111
|
3189
|
100
|
|
|
|
7398
|
if ( !defined( $self->{$key} ) ) {
|
112
|
38
|
|
|
|
|
162
|
return undef;
|
113
|
|
|
|
|
|
|
}
|
114
|
3151
|
100
|
|
|
|
9366
|
if ( !$self->{$key}->equals( $other->{$key} ) ) {
|
115
|
1512
|
|
|
|
|
6348
|
return undef;
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
}
|
118
|
789
|
|
|
|
|
2905
|
return 1;
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub intersects {
|
123
|
7
|
|
|
7
|
1
|
11
|
my ( $self, $other ) = @_;
|
124
|
|
|
|
|
|
|
|
125
|
7
|
50
|
|
|
|
32
|
if ( $other->isa(__PACKAGE__) ) {
|
126
|
|
|
|
|
|
|
|
127
|
7
|
|
|
|
|
18
|
foreach my $key ( keys %$other ) {
|
128
|
9
|
50
|
|
|
|
22
|
if ( !defined( $self->{$key} ) ) {
|
129
|
0
|
|
|
|
|
0
|
return undef;
|
130
|
|
|
|
|
|
|
}
|
131
|
9
|
100
|
|
|
|
28
|
if ( !$self->{$key}->intersects( $other->{$key} ) ) {
|
132
|
3
|
|
|
|
|
16
|
return undef;
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
}
|
135
|
|
|
|
|
|
|
|
136
|
4
|
|
|
|
|
19
|
return 1;
|
137
|
|
|
|
|
|
|
}
|
138
|
|
|
|
|
|
|
}
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub contains {
|
141
|
14
|
|
|
14
|
1
|
673
|
my ( $self, $other ) = @_;
|
142
|
|
|
|
|
|
|
|
143
|
14
|
100
|
|
|
|
80
|
if ( $other->isa(__PACKAGE__) ) {
|
144
|
|
|
|
|
|
|
|
145
|
12
|
|
|
|
|
25
|
foreach my $key ( keys %$other ) {
|
146
|
13
|
100
|
|
|
|
35
|
if ( !defined( $self->{$key} ) ) {
|
147
|
2
|
|
|
|
|
10
|
return undef;
|
148
|
|
|
|
|
|
|
}
|
149
|
11
|
100
|
|
|
|
49
|
if ( !$self->{$key}->contains( $other->{$key} ) ) {
|
150
|
5
|
|
|
|
|
25
|
return undef;
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
}
|
153
|
|
|
|
|
|
|
|
154
|
5
|
|
|
|
|
20
|
return 1;
|
155
|
|
|
|
|
|
|
}
|
156
|
|
|
|
|
|
|
}
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub contained_by {
|
159
|
440
|
|
|
440
|
1
|
483
|
my ( $self, $other ) = @_;
|
160
|
|
|
|
|
|
|
|
161
|
440
|
50
|
|
|
|
1444
|
if ( $other->isa(__PACKAGE__) ) {
|
162
|
|
|
|
|
|
|
|
163
|
440
|
|
|
|
|
671
|
foreach my $key ( keys %$other ) {
|
164
|
512
|
100
|
|
|
|
1026
|
if ( !defined( $self->{$key} ) ) {
|
165
|
242
|
|
|
|
|
741
|
return undef;
|
166
|
|
|
|
|
|
|
}
|
167
|
270
|
100
|
|
|
|
790
|
if ( !$other->{$key}->contains( $self->{$key} ) ) {
|
168
|
187
|
|
|
|
|
781
|
return undef;
|
169
|
|
|
|
|
|
|
}
|
170
|
|
|
|
|
|
|
}
|
171
|
|
|
|
|
|
|
|
172
|
11
|
|
|
|
|
50
|
return 1;
|
173
|
|
|
|
|
|
|
}
|
174
|
|
|
|
|
|
|
}
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub clone {
|
177
|
197
|
|
|
197
|
1
|
259
|
my ($self) = @_;
|
178
|
197
|
|
|
|
|
1569
|
my %clone = %$self;
|
179
|
197
|
|
|
|
|
891
|
return bless( \%clone, ref $self );
|
180
|
|
|
|
|
|
|
}
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub as_string {
|
183
|
106
|
|
|
106
|
1
|
174
|
my ($self) = @_;
|
184
|
106
|
|
|
|
|
145
|
my $string;
|
185
|
106
|
|
|
|
|
595
|
foreach my $key ( sort keys %$self ) {
|
186
|
212
|
|
|
|
|
593
|
$string .= $key . " => " . $self->get($key) . " ";
|
187
|
|
|
|
|
|
|
}
|
188
|
106
|
|
|
|
|
519
|
return $string;
|
189
|
|
|
|
|
|
|
}
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub dump {
|
192
|
4
|
|
|
4
|
1
|
9
|
my ($self) = @_;
|
193
|
4
|
|
|
|
|
8
|
my $string;
|
194
|
4
|
|
|
|
|
33
|
foreach my $key ( sort keys %$self ) {
|
195
|
20
|
|
|
|
|
48
|
$string .=
|
196
|
|
|
|
|
|
|
$key . " => "
|
197
|
|
|
|
|
|
|
. ref( $self->get($key) ) . " "
|
198
|
|
|
|
|
|
|
. $self->get($key)->as_string() . "\n";
|
199
|
|
|
|
|
|
|
}
|
200
|
4
|
|
|
|
|
91
|
return $string;
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
}
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1;
|
205
|
|
|
|
|
|
|
__END__
|