| 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
| |||||||||||
| 19 | unless ( defined $object ); | ||||||||||
| 20 | |||||||||||
| 21 | 11 | ▶ | croak "Farly::Object object required" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 39 | |||||||||||
| 40 | 3 | ▶ | if ( $self->size() != $other->size() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 48 | 3 | $match = 1; | |||||||||
| 49 | } | ||||||||||
| 50 | } | ||||||||||
| 51 | 3 | ▶ | if ( !$match ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 69 | 2 | $contained = 1; | |||||||||
| 70 | 2 | last; | |||||||||
| 71 | } | ||||||||||
| 72 | } | ||||||||||
| 73 | 3 | ▶ | if ( !$contained ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 1 | return undef; | |||||||||
| 75 | } | ||||||||||
| 76 | } | ||||||||||
| 77 | 1 | return 1; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | if ( $other->isa('Farly::Object') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | foreach my $s ( $self->iter() ) { | |||||||||
| 82 | 0 | ▶ | return 1 if ( $s->contains($other) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 96 | 2 | $included = 1; | |||||||||
| 97 | 2 | last; | |||||||||
| 98 | } | ||||||||||
| 99 | } | ||||||||||
| 100 | 2 | ▶ | if ( !$included ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 0 | return undef; | |||||||||
| 102 | } | ||||||||||
| 103 | } | ||||||||||
| 104 | 1 | return 1; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 5 | ▶ | if ( $other->isa('Farly::Object') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 5 | foreach my $s ( $self->iter() ) { | |||||||||
| 109 | 7 | ▶ | if ( $s->matches($other) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 180 | 1 | $in_other = 1; | |||||||||
| 181 | 1 | last; | |||||||||
| 182 | } | ||||||||||
| 183 | } | ||||||||||
| 184 | 2 | ▶ | if ( !$in_other ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||