Farly/Object.pm

filter: Statementstmt 97.6% 124 / 127 Branchbran 75.0% 33 / 44 Conditioncond 47.6% 10 / 21 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 32 / 32 Podpod 100% 14 / 14 totaltotal 86.6% 215 / 248 CC 36 SCAR 17.7
CC
36
Cov
87%
set
19.8
intersects
5.2
matches
5.0
CRAP 5.9
« Farly/Object/Set.pm ↑ Summary Farly/Remove/Address.pm »
1 package Farly::Object;
2
3 16 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 #Farly containers
9 16 ▶use Farly::Object::List;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Farly::Object::Set;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Farly::Object::Aggregate;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 #Farly reference object
13 16 require Farly::Object::Ref;
14 #Farly value objects
15 16 ▶use Farly::Value::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 16 ▶use Farly::Value::Integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 16 ▶use Farly::IPv4::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 16 ▶use Farly::IPv4::Network;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 16 ▶use Farly::IPv4::Range;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 16 ▶use Farly::IPv4::ICMPType;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 16 ▶use Farly::Transport::Port;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 16 ▶use Farly::Transport::PortGT;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 16 ▶use Farly::Transport::PortLT;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 16 ▶use Farly::Transport::PortRange;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 16 ▶use Farly::Transport::Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
26
27 16 our $VERSION = '0.26';
28
29 1256 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
30 1256 my ($class) = @_;
31
32 1256 ▶ carp "constructor arguments not supported; use 'set'"
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 1 0 1256 1256
33 if ( scalar(@_) > 1 );
34
35 1256 return bless {}, $class;
36 }
37
38 3842 ▶sub set {
Subroutine set: called CC=12 SCAR=29.9
Pod documented
39 3842 my ( $self, $key, $value ) = @_;
40
41 3842 ▶ confess "invalid key"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and length $key 0 3842 3842
Condition33%1/3
defined $key and length $key
!ll&&!rl&&r
003842
MC/DC0%0/2
defined $key and length $key
defined $key length $key
Truth table33%1/3
A and B
A= defined $keyB= length $key
ABresult
0X0
100
111
42 unless ( defined($key) && length($key) );
43
44 3842 ▶ confess "a value object must be defined"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 3842 3842
45 unless ( defined($value) );
46
47 # reference object, or list (i.e. $self is tree node), or set
48 3842 ▶ if ( $value->isa('Farly::Object') || $value->isa('Farly::Object::List')
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa("Farly::Object") or $value->isa("Farly::Object::List") or $value->isa("Farly::Object::Set")) 383 3459 3842
Condition83%5/6
$value->isa("Farly::Object") or $value->isa("Farly::Object::List") or $value->isa("Farly::Object::Set")
l!l&&r!l&&!r
38303459
$value->isa("Farly::Object") or $value->isa("Farly::Object::List")
l!l&&r!l&&!r
1861973459
MC/DC66%2/3
$value->isa("Farly::Object") or $value->isa("Farly::Object::List") or $value->isa("Farly::Object::Set")
$value->isa("Farly::Object") $value->isa("Farly::Object::List") $value->isa("Farly::Object::Set")
Truth table75%3/4
A or B or C
A= $value->isa("Farly::Object")B= $value->isa("Farly::Object::List")C= $value->isa("Farly::Object::Set")
ABCresult
1XX1
01X1
0011
0000
49 || $value->isa('Farly::Object::Set') )
50 {
51 383 $self->{$key} = $value;
52 383 return;
53 }
54
55 # or value object
56 3459 ▶ confess "$value is not a valid value object type"
Branch: 1 branch
BranchTrueFalseTotal
unless $value->can("equals") and $value->can("contains") and $value->can("intersects") and $value->can("compare") and $value->can("as_string") 0 3459 3459
Condition33%4/12
$value->can("equals") and $value->can("contains") and $value->can("intersects") and $value->can("compare") and $value->can("as_string")
!ll&&!rl&&r
003459
$value->can("equals") and $value->can("contains") and $value->can("intersects") and $value->can("compare")
!ll&&!rl&&r
003459
$value->can("equals") and $value->can("contains") and $value->can("intersects")
!ll&&!rl&&r
003459
$value->can("equals") and $value->can("contains")
!ll&&!rl&&r
003459
MC/DC0%0/5
$value->can("equals") and $value->can("contains") and $value->can("intersects") and $value->can("compare") and $value->can("as_string")
$value->can("equals") $value->can("contains") $value->can("intersects") $value->can("compare") $value->can("as_string")
Truth table16%1/6
A and B and C and D and E
A= $value->can("equals")B= $value->can("contains")C= $value->can("intersects")D= $value->can("compare")E= $value->can("as_string")
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
57 unless ( $value->can('equals')
58 && $value->can('contains')
59 && $value->can('intersects')
60 && $value->can('compare')
61 && $value->can('as_string') );
62
63 3459 $self->{$key} = $value;
64 }
65
66 9029 ▶sub get {
Subroutine get: called CC=2 SCAR=7.6
Pod documented
67 9029 my ( $self, $key ) = @_;
68 9029 ▶ if ( defined( $self->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$key}) { } 9029 0 9029
69 9029 return $self->{$key};
70 }
71 else {
72 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 1617 ▶sub has_defined {
Subroutine has_defined: called CC=2 SCAR=6.9
Pod documented
78 1617 my ( $self, $key ) = @_;
79 1617 ▶ return 1 if defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$key} 997 620 1617
80 }
81
82 9 ▶sub delete_key {
Subroutine delete_key: called CC=2 SCAR=7.2
Pod documented
83 9 my ( $self, $key ) = @_;
84 9 ▶ delete $self->{$key}
Branch: 1 branch
BranchTrueFalseTotal
delete $self->{$key} or carp("key $key delete error") 9 0 9
85 or carp "key $key delete error";
86 }
87
88 532 ▶sub get_keys {
Subroutine get_keys: called CC=1 SCAR=0.0
Pod documented
89 532 return keys %{ $_[0] };
90 }
91
92 110 ▶sub equals {
Subroutine equals: called CC=3 SCAR=11.3
Pod documented
93 110 my ( $self, $other ) = @_;
94
95 110 ▶ if ( $other->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa(__PACKAGE__)) 57 53 110
96
97 57 ▶ if ( scalar( keys %$self ) != scalar( keys %$other ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$self != scalar keys %$other) 0 57 57
98 0 return undef;
99 }
100
101 57 return $self->matches($other);
102 }
103 }
104
105 2395 ▶sub matches {
Subroutine matches: called CC=5 SCAR=16.1
Pod documented
106 2395 my ( $self, $other ) = @_;
107
108 2395 ▶ if ( $other->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa(__PACKAGE__)) 2395 0 2395
109
110 2395 foreach my $key ( keys %$other ) {
111 3278 ▶ if ( !defined( $self->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$key}) 34 3244 3278
112 34 return undef;
113 }
114 3244 ▶ if ( !$self->{$key}->equals( $other->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$key}->equals($other->{$key})) 1566 1678 3244
115 1566 return undef;
116 }
117 }
118 795 return 1;
119 }
120 }
121
122 7 ▶sub intersects {
Subroutine intersects: called CC=5 SCAR=16.6
Pod documented
123 7 my ( $self, $other ) = @_;
124
125 7 ▶ if ( $other->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa(__PACKAGE__)) 7 0 7
126
127 7 foreach my $key ( keys %$other ) {
128 9 ▶ if ( !defined( $self->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$key}) 0 9 9
129 0 return undef;
130 }
131 9 ▶ if ( !$self->{$key}->intersects( $other->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$key}->intersects($other->{$key})) 3 6 9
132 3 return undef;
133 }
134 }
135
136 4 return 1;
137 }
138 }
139
140 14 ▶sub contains {
Subroutine contains: called CC=5 SCAR=16.1
Pod documented
141 14 my ( $self, $other ) = @_;
142
143 14 ▶ if ( $other->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa(__PACKAGE__)) 12 2 14
144
145 12 foreach my $key ( keys %$other ) {
146 13 ▶ if ( !defined( $self->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$key}) 2 11 13
147 2 return undef;
148 }
149 11 ▶ if ( !$self->{$key}->contains( $other->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$key}->contains($other->{$key})) 5 6 11
150 5 return undef;
151 }
152 }
153
154 5 return 1;
155 }
156 }
157
158 440 ▶sub contained_by {
Subroutine contained_by: called CC=5 SCAR=16.1
Pod documented
159 440 my ( $self, $other ) = @_;
160
161 440 ▶ if ( $other->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa(__PACKAGE__)) 440 0 440
162
163 440 foreach my $key ( keys %$other ) {
164 481 ▶ if ( !defined( $self->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$key}) 242 239 481
165 242 return undef;
166 }
167 239 ▶ if ( !$other->{$key}->contains( $self->{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($other->{$key}->contains($self->{$key})) 187 52 239
168 187 return undef;
169 }
170 }
171
172 11 return 1;
173 }
174 }
175
176 206 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
177 206 my ($self) = @_;
178 206 my %clone = %$self;
179 206 return bless( \%clone, ref $self );
180 }
181
182 106 ▶sub as_string {
Subroutine as_string: called CC=2 SCAR=6.9
Pod documented
183 106 my ($self) = @_;
184 106 my $string;
185 106 foreach my $key ( sort keys %$self ) {
186 212 $string .= $key . " => " . $self->get($key) . " ";
187 }
188 106 return $string;
189 }
190
191 4 ▶sub dump {
Subroutine dump: called CC=2 SCAR=6.9
Pod documented
192 4 my ($self) = @_;
193 4 my $string;
194 4 foreach my $key ( sort keys %$self ) {
195 20 $string .=
196 $key . " => "
197 . ref( $self->get($key) ) . " "
198 . $self->get($key)->as_string() . "\n";
199 }
200 4 return $string;
201
202 }
203
204 16 1;
205 __END__
« Farly/Object/Set.pm ↑ Summary Farly/Remove/Address.pm »