Farly/Object/Set.pm

filter: Statementstmt 88.5% 93 / 105 Branchbran 68.7% 33 / 48 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.2% 15 / 17 Podpod 92.3% 12 / 13 totaltotal 83.6% 153 / 183 CC 40 SCAR 18.8
CC
40
Cov
82%
contains
12.0
includes
9.1
equals
7.0
CRAP 6.6
« Farly/ASA/Filter.pm ↑ Summary Farly/Object.pm »
1 package Farly::Object::Set;
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 16 our $VERSION = '0.26';
9
10 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 7 my ($class) = @_;
12 7 return bless [], $class;
13 }
14
15 11 ▶sub add {
Subroutine add: called CC=3 SCAR=11.3
Pod documented
16 11 my ( $self, $object ) = @_;
17
18 11 ▶ croak "Farly::Object object required"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object 0 11 11
19 unless ( defined $object );
20
21 11 ▶ croak "Farly::Object object required"
Branch: 1 branch
BranchTrueFalseTotal
unless $object->isa("Farly::Object") 0 11 11
22 unless ( $object->isa('Farly::Object') );
23
24 11 push @{$self}, $object;
25 }
26
27 10 ▶sub size {
Subroutine size: called CC=1 SCAR=0.0
Pod documented
28 10 return scalar( @{ $_[0] } );
29 }
30
31 27 ▶sub iter {
Subroutine iter: called CC=1 SCAR=0.0
Pod documented
32 27 return @{ $_[0] };
33 }
34
35 4 ▶sub equals {
Subroutine equals: called CC=7 SCAR=19.5
Pod documented
36 4 my ( $self, $other ) = @_;
37
38 4 ▶ if ( $other->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa(__PACKAGE__)) 3 1 4
39
40 3 ▶ if ( $self->size() != $other->size() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->size != $other->size) 1 2 3
41 1 return undef;
42 }
43
44 2 foreach my $s ( $self->iter() ) {
45 3 my $match;
46 3 foreach my $o ( $other->iter() ) {
47 5 ▶ if ( $s->equals($o) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->equals($o)) 3 2 5
48 3 $match = 1;
49 }
50 }
51 3 ▶ if ( !$match ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($match) 0 3 3
52 0 return undef;
53 }
54 }
55
56 2 return 1;
57 }
58 }
59
60 2 ▶sub contains {
Subroutine contains: called CC=9 SCAR=24.8
Pod documented
61 2 my ( $self, $other ) = @_;
62
63 2 ▶ if ( $other->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa(__PACKAGE__)) 2 0 2
64
65 2 foreach my $o ( $other->iter() ) {
66 3 my $contained;
67 3 foreach my $s ( $self->iter() ) {
68 3 ▶ if ( $s->contains($o) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->contains($o)) 2 1 3
69 2 $contained = 1;
70 2 last;
71 }
72 }
73 3 ▶ if ( !$contained ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($contained) 1 2 3
74 1 return undef;
75 }
76 }
77 1 return 1;
78 }
79
80 0 ▶ if ( $other->isa('Farly::Object') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa("Farly::Object")) 0 0 0
81 0 foreach my $s ( $self->iter() ) {
82 0 ▶ return 1 if ( $s->contains($other) );
Branch: 1 branch
BranchTrueFalseTotal
if $s->contains($other) 0 0 0
83 }
84 }
85 }
86
87 6 ▶sub includes {
Subroutine includes: called CC=9 SCAR=22.1
Pod documented
88 6 my ( $self, $other ) = @_;
89
90 6 ▶ if ( $other->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa(__PACKAGE__)) 1 5 6
91
92 1 foreach my $o ( $other->iter() ) {
93 2 my $included;
94 2 foreach my $s ( $self->iter() ) {
95 7 ▶ if ( $s->matches($o) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->matches($o)) 2 5 7
96 2 $included = 1;
97 2 last;
98 }
99 }
100 2 ▶ if ( !$included ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($included) 0 2 2
101 0 return undef;
102 }
103 }
104 1 return 1;
105 }
106
107 5 ▶ if ( $other->isa('Farly::Object') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->isa("Farly::Object")) 5 0 5
108 5 foreach my $s ( $self->iter() ) {
109 7 ▶ if ( $s->matches($other) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->matches($other)) 4 3 7
110 4 return 1;
111 }
112 }
113 }
114 }
115
116 0 ▶sub intersects {
Subroutine intersects: not called CC=2 SCAR=17.9
Pod documented
117 0 my ( $self, $other ) = @_;
118 0 ▶ return 1 if ( $self->intersection($other)->size() >= 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->intersection($other)->size >= 1 0 0 0
119 }
120
121 2 ▶sub intersection {
Subroutine intersection: called CC=5 SCAR=16.1
Pod documented
122 2 my ( $self, $other ) = @_;
123
124 2 ▶ confess "Set required"
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa(__PACKAGE__) 0 2 2
125 unless $other->isa(__PACKAGE__);
126
127 2 my $isect = __PACKAGE__->new();
128
129 2 foreach my $s ( $self->iter() ) {
130 2 foreach my $o ( $other->iter() ) {
131 3 ▶ if ( $s->matches($o) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->matches($o)) 1 2 3
132 1 $isect->add($s);
133 1 last;
134 }
135 }
136 }
137
138 2 return $isect;
139 }
140
141 1 ▶sub union {
Subroutine union: called CC=5 SCAR=16.1
Pod documented
142 1 my ( $self, $other ) = @_;
143
144 1 ▶ confess "Set required"
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa(__PACKAGE__) 0 1 1
145 unless $other->isa(__PACKAGE__);
146
147 1 my $union = __PACKAGE__->new();
148
149 1 foreach my $s ( $self->iter() ) {
150 1 $union->add($s);
151 }
152
153 1 foreach my $o ( $other->iter() ) {
154 2 ▶ if ( !$union->includes($o) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($union->includes($o)) 1 1 2
155 1 $union->add($o);
156 }
157 }
158
159 1 return $union;
160 }
161
162 1 ▶sub disjoint {
Subroutine disjoint: called CC=1 SCAR=0.0
Pod documented
163 1 my ( $self, $other ) = @_;
164 1 my $isect = $self->intersection($other);
165 1 return $isect->size() == 0;
166 }
167
168 1 ▶sub difference {
Subroutine difference: called CC=6 SCAR=17.9
Pod documented
169 1 my ( $self, $other ) = @_;
170
171 1 ▶ confess "Set required"
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa(__PACKAGE__) 0 1 1
172 unless $other->isa(__PACKAGE__);
173
174 1 my $diff = __PACKAGE__->new();
175
176 1 foreach my $s ( $self->iter() ) {
177 2 my $in_other;
178 2 foreach my $o ( $other->iter() ) {
179 2 ▶ if ( $s->matches($o) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->matches($o)) 1 1 2
180 1 $in_other = 1;
181 1 last;
182 }
183 }
184 2 ▶ if ( !$in_other ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($in_other) 1 1 2
185 1 $diff->add($s);
186 }
187 }
188
189 1 return $diff;
190 }
191
192 0 ▶sub as_string {
Subroutine as_string: not called CC=2 SCAR=17.9
Pod undocumented
193 0 my ($self) = @_;
194
195 #carp "called as_string on Set";
196 0 my $string;
197 0 foreach my $s ( $self->iter() ) {
198 0 $string .= $s->as_string() . " ";
199 }
200 0 return $string;
201 }
202
203 16 1;
204 __END__
« Farly/ASA/Filter.pm ↑ Summary Farly/Object.pm »