Relation/V2.pm

filter: Statementstmt 33.4% 612 / 1832 Branchbran 25.8% 150 / 580 Conditioncond 18.8% 54 / 286 MC/DCmcdc 3.1% 5 / 159 Subroutinesub 40.9% 70 / 171 Podpod 0.0% 0 / 78 totaltotal 28.6% 891 / 3106 CC 446 SCAR 38.0
CC
446
Cov
30%
BUILD
219.2
unwrap
182.0
ungroup
182.0
CRAP 44.9
↑ Summary Relation/V1.pm »
1 3 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 ###########################################################################
7 ###########################################################################
8  
9 { package Set::Relation::V2; # class
10 3 our $VERSION = '0.013004';
11 3 $VERSION = eval $VERSION;
12  
13 3 ▶ use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶ use Scalar::Util 'blessed', 'refaddr';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶ use List::Util 'any', 'all', 'notall', 'uniqstr';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # with Set::Relation
18 32 ▶ sub does {
Subroutine does: called CC=5 SCAR=18.1
Pod undocumented
19 32 my ($self, $role_name) = @_;
20 32 ▶ confess q{This does() may only be invoked on an object.}
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) 0 32 32
21 if not blessed $self;
22 32 ▶ confess q{does(): Bad $role_name arg; it must be a defined string.}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $role_name 0 32 32
23 if !defined $role_name;
24 32 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isa(__PACKAGE__) 0 32 32
25 if !$self->isa( __PACKAGE__ );
26 32 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $role_name eq "Set::Relation" 32 0 32
27 if $role_name eq 'Set::Relation';
28 0 return 0;
29 }
30  
31 # has _heading
32 # isa HashRef
33 # One elem per attribute:
34 # hkey is Str attr name
35 # hval is undef+unused
36 # default {}
37 391 ▶ sub _heading {
Subroutine _heading: called CC=2 SCAR=6.9
38 391 my $self = shift;
39 391 ▶ $self->{_heading} = $_[0] if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 121 270 391
40 391 return $self->{_heading};
41 }
42  
43 # has _body
44 # isa HashRef
45 # One elem per tuple:
46 # hkey is refaddr of hval
47 # hval is HashRef that is the coll of separate tuple attrs:
48 # hkey is Str attr name
49 # hval is the actual tuple attr value
50 # default {}
51 393 ▶ sub _body {
Subroutine _body: called CC=2 SCAR=6.9
52 393 my $self = shift;
53 393 ▶ $self->{_body} = $_[0] if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 99 294 393
54 393 return $self->{_body};
55 }
56  
57 # Note, this flag expressly only applies to the object it is a
58 # member of, and it doesn't say anything about this object's RVAs.
59 # Note, this flag is always true when an index exists over all attrs,
60 # because said index is always made in such a way to ensure this,
61 # but this flag may also be true when said index doesn't exist,
62 # depending on how the V2 object was created.
63 # has _is_known_dup_free
64 # isa Bool
65 # default 0
66 309 ▶ sub _is_known_dup_free {
Subroutine _is_known_dup_free: called CC=2 SCAR=6.9
67 309 my $self = shift;
68 309 ▶ $self->{_is_known_dup_free} = $_[0] if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 115 194 309
69 309 return $self->{_is_known_dup_free};
70 }
71  
72 # has _which
73 # isa Maybe[Str]
74 # default undef
75 61 ▶ sub _which {
Subroutine _which: called CC=2 SCAR=7.1
76 61 my $self = shift;
77 61 ▶ $self->{_which} = $_[0] if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 61 0 61
78 61 return $self->{_which};
79 }
80  
81 # has _indexes
82 # isa HashRef
83 # One elem per index:
84 # hkey is index name;
85 # - is Str ident gen f head subset tha index ranges ovr
86 # hval is 2-elem ArrayRef that is the index itself + meta
87 # [0] is HashRef of atnms that index ranges over
88 # - structure same as '_heading'
89 # [1] is index itself;
90 # - HashRef; one elem per tup of projection of body
91 # on attrs that index ranges over
92 # hkey is Str ident gen fr distinct projection tupl
93 # hval is set of body tup having projection tuples
94 # in comn; is HashRef; one elem per body tuple
95 # - structure same as '_body', is slice o _body
96 # default {}
97 121 ▶ sub _indexes {
Subroutine _indexes: called CC=2 SCAR=6.9
98 121 my $self = shift;
99 121 ▶ $self->{_indexes} = $_[0] if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 61 60 121
100 121 return $self->{_indexes};
101 }
102  
103 # has _keys
104 # isa HashRef
105 # One elem per key:
106 # hkey is key name;
107 # - is Str ident gen f head subset tha index ranges ovr
108 # hval is HashRef of atnms that index ranges over
109 # - structure same as '_heading'
110 # default {}
111 61 ▶ sub _keys {
Subroutine _keys: called CC=2 SCAR=7.1
112 61 my $self = shift;
113 61 ▶ $self->{_keys} = $_[0] if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 61 0 61
114 61 return $self->{_keys};
115 }
116  
117 ###########################################################################
118  
119 61 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
120 61 my ($class, @args) = @_;
121 61 ▶ $class = (blessed $class) || $class;
Condition33%1/3
builtin::blessed($class) || $class
l!l&&r!l&&!r
0610
MC/DC0%0/2
builtin::blessed($class) || $class
builtin::blessed($class) $class
Truth table33%1/3
A || B
A= builtin::blessed($class)B= $class
ABresult
1X1
011
000
122  
123 61 my $params = $class->BUILDARGS( @args );
124  
125 61 my $self = bless {}, $class;
126  
127 # Set attribute default values.
128 61 $self->_heading( {} );
129 61 $self->_body( {} );
130 61 $self->_is_known_dup_free( 0 );
131 61 $self->_which( undef );
132 61 $self->_indexes( {} );
133 61 $self->_keys( {} );
134  
135 61 $self->BUILD( $params );
136  
137 61 return $self;
138 }
139  
140 ###########################################################################
141  
142 61 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=4 SCAR=15.5
Pod undocumented
143 61 my ($class, @args) = @_;
144 61 ▶ if (@args == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@args == 1) { } 22 39 61
elsif (scalar @args % 2 == 0) { } 39 0 39
145 22 ▶ if (ref $args[0] ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] ne 'HASH') { } 22 0 22
146 # Constructor was called with a single positional argument.
147 22 return { members => $args[0] };
148 }
149 else {
150 # Constructor was called with (possibly zero) named arguments.
151 0 return { %{$args[0]} };
152 }
153 }
154 elsif ((scalar @args % 2) == 0) {
155 # Constructor was called with (possibly zero) named arguments.
156 39 return { @args };
157 }
158 else {
159 # Constructor was called with odd number positional arguments >= 3.
160 0 confess q{new(): Bad arguments list; it must either have an even}
161 . q{ number of elements or exactly 1 element.};
162 }
163 }
164  
165 ###########################################################################
166  
167 61 ▶sub BUILD {
Subroutine BUILD: called CC=42 SCAR=53.9
Pod undocumented
168 61 my ($self, $args) = @_;
169 61 my ($members, $keys) = @{$args}{'members', 'keys'};
170  
171 # Note, $members may be in all of the same formats as a HDMD_Perl_STD
172 # Relation value literal payload, but with a few extra trivial options.
173  
174 61 ▶ if (!defined $members) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $members) { } 39 22 61
elsif (not ref $members) { } 0 22 22
elsif (builtin::blessed($members) and $members->can('does') and $members->does('Set::Relation') and not $members->isa(__PACKAGE__)) { } 0 44 44
175 # Extra option 1.
176 39 $members = [];
177 }
178 elsif (!ref $members) {
179 # Extra option 2.
180 0 $members = [$members];
181 }
182 ▶ elsif (blessed $members and $members->can( 'does' )
Condition33%3/9
builtin::blessed($members) and $members->can("does") and $members->does("Set::Relation") and not $members->isa(__PACKAGE__)
!ll&&!rl&&r
2200
builtin::blessed($members) and $members->can("does") and $members->does("Set::Relation")
!ll&&!rl&&r
2200
builtin::blessed($members) and $members->can("does")
!ll&&!rl&&r
2200
MC/DC0%0/4
builtin::blessed($members) and $members->can("does") and $members->does("Set::Relation") and not $members->isa(__PACKAGE__)
builtin::blessed($members) $members->can("does") $members->does("Set::Relation") not $members->isa(__PACKAGE__)
Truth table20%1/5
A and B and C and not(D)
A= builtin::blessed($members)B= $members->can("does")C= $members->does("Set::Relation")D= not $members->isa(__PACKAGE__)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
183 and $members->does( 'Set::Relation' )
184 and !$members->isa( __PACKAGE__ )) {
185 # We got a $members that is a Set::Relation-doing class where that
186 # class isn't us; so clone it from a dump using public interface.
187 0 $members = $self->_new( $members->export_for_new() );
188 }
189 61 ▶ confess q{new(): Bad :$members arg; it must be either undefined}
Branch: 1 branch
BranchTrueFalseTotal
if ref $members ne "ARRAY" and not builtin::blessed($members) && $members->isa(__PACKAGE__) 0 61 61
Condition16%1/6
ref $members ne "ARRAY" and not builtin::blessed($members) && $members->isa(__PACKAGE__)
!ll&&!rl&&r
6100
builtin::blessed($members) && $members->isa(__PACKAGE__)
!ll&&!rl&&r
000
MC/DC0%0/3
ref $members ne "ARRAY" and not builtin::blessed($members) && $members->isa(__PACKAGE__)
ref $members ne "ARRAY" builtin::blessed($members) $members->isa(__PACKAGE__)
Truth table25%1/4
A and not(B && C)
A= ref $members ne "ARRAY"B= builtin::blessed($members)C= $members->isa(__PACKAGE__)
ABCresult
0XX0
1110
10X1
1101
190 . q{ or an array-ref or a non-ref or a Set::Relation object.}
191 if ref $members ne 'ARRAY'
192 and not (blessed $members and $members->isa( __PACKAGE__ ));
193  
194 # If we get here, $members is either a Set::Relation::V2 or an ary-ref.
195  
196 61 ▶ if (!defined $keys) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $keys) { } 61 0 61
elsif (ref $keys ne 'ARRAY') { } 0 0 0
197 61 $keys = [];
198 }
199 elsif (ref $keys ne 'ARRAY') {
200 0 $keys = [$keys];
201 }
202 0 ▶ if (any { ref $_ ne 'ARRAY' } @{$keys}) {
Subroutine __ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { ref $_ ne "ARRAY"; } , @{$keys;})) 0 61 61
203 0 $keys = [$keys];
204 }
205 61 for my $key (@{$keys}) {
206 confess q{new(): Bad $keys arg; it is not correctly formatted.}
207 if ref $key ne 'ARRAY'
208 0 ▶ or notall { defined $_ and !ref $_ } @{$key};
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if ref $key ne "ARRAY" or &notall(sub { defined $_ and not ref $_; } , @{$key;}) 0 0 0
defined $_ and not ref $_ 0 0 0
Condition0%0/3
ref $key ne "ARRAY" or &notall(sub { defined $_ and not ref $_; } , @{$key;})
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $key ne "ARRAY" or &notall(sub { defined $_ and not ref $_; } , @{$key;})
ref $key ne "ARRAY" &notall(sub { defined $_ and not ref $_; } , @{$key;})
Truth table0%0/3
A or B
A= ref $key ne "ARRAY"B= &notall(sub { defined $_ and not ref $_; } , @{$key;})
ABresult
1X1
011
000
209 }
210  
211 # If we get here, $keys is an Array of Array of Str.
212  
213 # Note, we expressly do not set _is_known_dup_free to true when
214 # we are not cloning an S::R object and we know we have an empty body
215 # because often our other methods will be directly adding tuples to
216 # result objects after simply asking new() to make an empty starter
217 # object, and so we are trying to avoid bugs due to those other methods
218 # forgetting to expressly set _is_known_dup_free to false.
219 # But if we know we have exactly 1 input tuple, we set the flag to
220 # true, since its unlikely the meths add tuples both on new and after.
221  
222 61 ▶ if (blessed $members and $members->isa( __PACKAGE__ )) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($members) and $members->isa(__PACKAGE__)) { } 0 61 61
elsif (@{$members;} == 0) { } 40 21 61
Condition33%1/3
builtin::blessed($members) and $members->isa(__PACKAGE__)
!ll&&!rl&&r
6100
MC/DC0%0/2
builtin::blessed($members) and $members->isa(__PACKAGE__)
builtin::blessed($members) $members->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($members)B= $members->isa(__PACKAGE__)
ABresult
0X0
100
111
223 # We'll just shallow-clone anoth Set::Relation::V2 obj's memb-set.
224 0 $self->_heading( $members->_heading() );
225 0 $self->_body( $members->_body() );
226 0 $self->_is_known_dup_free( $members->_is_known_dup_free() );
227 0 $self->_which( $members->_which() );
228 0 $self->_indexes( $members->_indexes() );
229 0 $self->_keys( $members->_keys() );
230 }
231 61 elsif (@{$members} == 0) {
232 # Input specifies zero attrs + zero tuples.
233 # No-op; attr defaults are fine.
234 }
235 else {
236 # Input specifies at least one attr or at least one tuple.
237 21 my $member0 = $members->[0];
238 21 ▶ if (!defined $member0) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $member0) { } 0 21 21
elsif (not ref $member0) { } 0 21 21
elsif (ref $member0 eq 'HASH') { } 12 9 21
elsif (ref $member0 eq 'ARRAY') { } 9 0 9
239 0 confess q{new(): Bad :$members arg; it is an array ref}
240 . q{ but it directly has an undefined element.};
241 }
242 elsif (!ref $member0) {
243 # Input spec at least 1 attr + zero tuples.
244 # Each $members elem is expected to be an atnm.
245 confess q{new(): Bad :$members arg; it has a non-ref elem,}
246 . q{ indicating it should just be a list of attr}
247 . q{ names, but at least one other elem is}
248 . q{ undefined or is a ref.}
249 0 ▶ if notall { defined $_ and !ref $_ } @{$members};
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if &notall(sub { defined $_ and not ref $_; } , @{$members;}) 0 0 0
defined $_ and not ref $_ 0 0 0
250 confess q{new(): Bad :$members arg; it specifies a list of}
251 . q{ attr names with at least one duplicated name.}
252 0 ▶ if (uniqstr @{$members}) != @{$members};
Branch: 1 branch
BranchTrueFalseTotal
if &uniqstr(@{$members;}) != @{$members;} 0 0 0
253 0 $self->_heading( {CORE::map { ($_ => undef) } @{$members}} );
254 }
255 elsif (ref $member0 eq 'HASH') {
256 # Input spec at least 1 tuple, in named attr format.
257 my $heading
258 12 = {CORE::map { ($_ => undef) } CORE::keys %{$member0}};
259 12 my $body = {};
260 12 for my $tuple (@{$members}) {
261 44 ▶ confess q{new(): Bad :$members arg; it has a hash-ref}
Branch: 1 branch
BranchTrueFalseTotal
if ref $tuple ne "HASH" or not $self->_is_identical_hkeys($heading, $tuple) 0 44 44
Condition33%1/3
ref $tuple ne "HASH" or not $self->_is_identical_hkeys($heading, $tuple)
l!l&&r!l&&!r
0044
MC/DC0%0/2
ref $tuple ne "HASH" or not $self->_is_identical_hkeys($heading, $tuple)
ref $tuple ne "HASH" not $self->_is_identical_hkeys($heading, $tuple)
Truth table33%1/3
A or not(B)
A= ref $tuple ne "HASH"B= not $self->_is_identical_hkeys($heading, $tuple)
ABresult
1X1
011
000
262 . q{ elem, indicating it should just be a list of}
263 . q{ tuples in named-attr format, but at least one}
264 . q{ other elem is not a hash-ref, or the 2 elems}
265 . q{ don't have exactly the same set of hkeys.}
266 if ref $tuple ne 'HASH'
267 or !$self->_is_identical_hkeys( $heading, $tuple );
268 44 ▶ confess q{new(): Bad :$members arg;}
Branch: 1 branch
BranchTrueFalseTotal
if $self->_tuple_arg_has_circular_refs($tuple) 0 44 44
269 . q{ at least one of its hash-ref elems is such}
270 . q{ that there exists circular refs between}
271 . q{ itself or its tuple-valued components.}
272 if $self->_tuple_arg_has_circular_refs( $tuple );
273 44 $tuple = $self->_import_nfmt_tuple( $tuple );
274 44 $body->{refaddr $tuple} = $tuple;
275 }
276 12 $self->_heading( $heading );
277 12 $self->_body( $body );
278 12 ▶ if (@{$members} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$members;} == 1) 3 9 12
279 3 $self->_is_known_dup_free( 1 );
280 }
281 }
282 elsif (ref $member0 eq 'ARRAY') {
283 # Input is in ordered attr format.
284 9 my $member1 = $members->[1];
285 confess q{new(): Bad :$members arg; it has an array-ref first}
286 . q{ elem, indicating it should just be a list of}
287 . q{ tuples in ordered-attr format, but either}
288 . q{ :$members doesn't have exactly 2 elements or its}
289 . q{ second element isn't also an array-ref.}
290 9 ▶ if @{$members} != 2 or ref $member1 ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if @{$members;} != 2 or ref $member1 ne "ARRAY" 0 9 9
Condition33%1/3
@{$members;} != 2 or ref $member1 ne "ARRAY"
l!l&&r!l&&!r
009
MC/DC0%0/2
@{$members;} != 2 or ref $member1 ne "ARRAY"
@{$members;} != 2 ref $member1 ne "ARRAY"
Truth table33%1/3
A or B
A= @{$members;} != 2B= ref $member1 ne "ARRAY"
ABresult
1X1
011
000
291 # Each $member0 elem is expected to be an atnm.
292 confess q{new(): Bad :$members array-ref arg array-ref}
293 . q{ first elem; it should be just be a list of}
294 . q{ attr names, but at least one name}
295 . q{ is undefined or is a ref.}
296 9 ▶ if notall { defined $_ and !ref $_ } @{$member0};
Subroutine __ANON__: called CC=2 SCAR=7.4
Branch: 2 branches
BranchTrueFalseTotal
if &notall(sub { defined $_ and not ref $_; } , @{$member0;}) 0 9 9
defined $_ and not ref $_ 33 0 33
297 confess q{new(): Bad :$members arg; it specifies a list of}
298 . q{ attr names with at least one duplicated name.}
299 9 ▶ if (uniqstr @{$member0}) != @{$member0};
Branch: 1 branch
BranchTrueFalseTotal
if &uniqstr(@{$member0;}) != @{$member0;} 0 9 9
300 9 my $heading = {CORE::map { ($_ => undef) } @{$member0}};
301 9 my $body = {};
302 9 for my $tuple (@{$member1}) {
303 confess q{new(): Bad :$members array-ref arg array-ref}
304 . q{ second elem; at least one elem isn't an}
305 . q{ array-ref, or that doesn't have the same}
306 . q{ count of elems as the :$members first elem.}
307 35 ▶ if ref $tuple ne 'ARRAY' or @{$tuple} != @{$member0};
Branch: 1 branch
BranchTrueFalseTotal
if ref $tuple ne "ARRAY" or @{$tuple;} != @{$member0;} 0 35 35
Condition33%1/3
ref $tuple ne "ARRAY" or @{$tuple;} != @{$member0;}
l!l&&r!l&&!r
0035
MC/DC0%0/2
ref $tuple ne "ARRAY" or @{$tuple;} != @{$member0;}
ref $tuple ne "ARRAY" @{$tuple;} != @{$member0;}
Truth table33%1/3
A or B
A= ref $tuple ne "ARRAY"B= @{$tuple;} != @{$member0;}
ABresult
1X1
011
000
308 # Each $tuple elem is expected to be an atvl.
309 confess q{new(): Bad :$members arg;}
310 . q{ at least one of its array-ref elems}
311 . q{ is such that there exists circular refs}
312 . q{ between its tuple-valued components.}
313 125 ▶ if any { ref $_ eq 'HASH'
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "HASH" and $self->_tuple_arg_has_circular_refs($_) 0 125 125
314 and $self->_tuple_arg_has_circular_refs( $_ )
315 35 ▶ } (@{$tuple});
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { ref $_ eq "HASH" and $self->_tuple_arg_has_circular_refs($_); } , @{$tuple;}) 0 35 35
316 35 $tuple = $self->_import_ofmt_tuple( $member0, $tuple );
317 35 $body->{refaddr $tuple} = $tuple;
318 }
319 9 $self->_heading( $heading );
320 9 $self->_body( $body );
321 9 ▶ if (@{$member1} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$member1;} == 1) 1 8 9
322 1 $self->_is_known_dup_free( 1 );
323 }
324 }
325 else {
326 0 confess q{new(): Bad :$members arg; it is an array-ref but it}
327 . q{ has an elem that is neither a defined scalar nor}
328 . q{ an array-ref nor a hash-ref.};
329 }
330 }
331  
332 61 my $self_h = $self->_heading();
333  
334 61 for my $key (@{$keys}) {
335 confess q{new(): At least one of the relation keys defined by the}
336 . q{ $keys arg isn't a subset of the heading of the}
337 . q{ relation defined by the $members arg.}
338 0 ▶ if notall { exists $self_h->{$_} } @{$key};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { exists $self_h->{$_}; } , @{$key;}) 0 0 0
339 0 ▶ confess q{new(): The relation defined by the $members arg violates}
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_key($key) 0 0 0
340 . q{ at least one of the candidate unique key constraints}
341 0 . qq{ defined by the $members arg: [@{$key}].}
342 if !$self->_has_key( $key );
343 }
344  
345 61 return;
346 }
347  
348 ###########################################################################
349  
350 39 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
351 39 my ($self, @args) = @_;
352 39 return (blessed $self)->new( @args );
353 }
354  
355 ###########################################################################
356  
357 0 ▶sub export_for_new {
Subroutine export_for_new: not called CC=1 SCAR=6.9
Pod undocumented
358 0 my ($self, $want_ord_attrs, $allow_dup_tuples) = @_;
359 return {
360 0 'members' => $self->_members( 'export_for_new',
361 '$want_ord_attrs', $want_ord_attrs, $allow_dup_tuples ),
362 'keys' => $self->keys(),
363 };
364 }
365  
366 ###########################################################################
367  
368 0 ▶sub which {
Subroutine which: not called CC=2 SCAR=17.9
Pod undocumented
369 0 my ($self) = @_;
370 0 my $ident_str = $self->_which();
371 0 ▶ if (!defined $ident_str) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ident_str) 0 0 0
372 0 my $index = $self->_dup_free_want_index_over_all_attrs();
373 0 my $hs = $self->_heading_ident_str( $self->_heading() );
374 0 my $bs = CORE::join qq{,\n}, sort (CORE::keys %{$index});
375 0 my $vstr = "H=$hs;\nB={$bs}";
376 0 $ident_str = 'Relation:' . (length $vstr) . ':{' . $vstr . '}';
377 0 $self->_which( $ident_str );
378 }
379 0 return $ident_str;
380 }
381  
382 ###########################################################################
383  
384 33 ▶sub members {
Subroutine members: called CC=1 SCAR=0.0
Pod undocumented
385 33 my ($self, $want_ord_attrs, $allow_dup_tuples) = @_;
386 33 return $self->_members( 'members',
387 '$want_ord_attrs', $want_ord_attrs, $allow_dup_tuples );
388 }
389  
390 33 ▶sub _members {
Subroutine _members: called CC=5 SCAR=16.4
391 33 my ($self, $rtn_nm, $arg_nm, $want_ord_attrs, $allow_dup_tuples) = @_;
392 33 ▶ if (!$allow_dup_tuples and !$self->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $self->_is_known_dup_free) 5 28 33
Condition66%2/3
$allow_dup_tuples or $self->_is_known_dup_free
l!l&&r!l&&!r
0285
MC/DC50%1/2
$allow_dup_tuples or $self->_is_known_dup_free
$allow_dup_tuples $self->_is_known_dup_free
Truth table66%2/3
A or B
A= $allow_dup_tuplesB= $self->_is_known_dup_free
ABresult
1X1
011
000
393 5 $self->_dup_free_want_index_over_all_attrs();
394 }
395 33 ▶ if ($want_ord_attrs) {
Branch: 2 branches
BranchTrueFalseTotal
if ($want_ord_attrs) { } 2 31 33
elsif (CORE::keys %{$self->_body;} == 0) { } 0 31 31
396 2 my $ord_attr_names = $self->_normalize_true_want_ord_attrs_arg(
397 $rtn_nm, $arg_nm, $want_ord_attrs );
398 return [$ord_attr_names, [CORE::map {
399 5 $self->_export_ofmt_tuple( $ord_attr_names, $_ )
400 2 } values %{$self->_body()}]];
401 }
402 31 elsif ((CORE::keys %{$self->_body()}) == 0) {
403 # We have zero tuples, just export attr names.
404 0 return [sort (CORE::keys %{$self->_heading()})];
405 }
406 else {
407 # We have at least one tuple, export in named-attr format.
408 107 return [CORE::map { $self->_export_nfmt_tuple( $_ ) }
409 31 values %{$self->_body()}];
410 }
411 }
412  
413 ###########################################################################
414  
415 1 ▶sub heading {
Subroutine heading: called CC=1 SCAR=0.0
Pod undocumented
416 1 my ($self) = @_;
417 1 return [sort (CORE::keys %{$self->_heading()})];
418 }
419  
420 ###########################################################################
421  
422 0 ▶sub body {
Subroutine body: not called CC=4 SCAR=30.0
Pod undocumented
423 0 my ($self, $want_ord_attrs, $allow_dup_tuples) = @_;
424 0 ▶ if (!$allow_dup_tuples and !$self->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $self->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $self->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $self->_is_known_dup_free
$allow_dup_tuples $self->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $self->_is_known_dup_free
ABresult
1X1
011
000
425 0 $self->_dup_free_want_index_over_all_attrs();
426 }
427 0 ▶ if ($want_ord_attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_ord_attrs) { } 0 0 0
428 0 my $ord_attr_names = $self->_normalize_true_want_ord_attrs_arg(
429 'body', '$want_ord_attrs', $want_ord_attrs );
430 0 return [CORE::map { $self->_export_ofmt_tuple(
431 0 $ord_attr_names, $_ ) } values %{$self->_body()}];
432 }
433 else {
434 0 return [CORE::map { $self->_export_nfmt_tuple( $_ ) }
435 0 values %{$self->_body()}];
436 }
437 }
438  
439 ###########################################################################
440  
441 2 ▶sub _normalize_true_want_ord_attrs_arg {
Subroutine _normalize_true_want_ord_attrs_arg: called CC=7 SCAR=28.4
442 2 my ($self, $rtn_nm, $arg_nm, $want_ord_attrs) = @_;
443  
444 2 my $heading = $self->_heading();
445  
446 2 my $attr_names = [CORE::keys %{$heading}];
447 confess qq{$rtn_nm(): Bad $arg_nm arg;}
448 . q{ it must be either undefined|false or the scalar value '1'}
449 . q{ or an array-ref of attr names whose degree and}
450 . q{ elements match the heading of the invocant.}
451 if not (!ref $want_ord_attrs and $want_ord_attrs eq '1'
452 or ref $want_ord_attrs eq 'ARRAY'
453 0 and @{$want_ord_attrs} == @{$attr_names}
454 0 ▶ and all { exists $heading->{$_} } @{$want_ord_attrs});
Subroutine __ANON__: not called CC=1 SCAR=3.7
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $want_ord_attrs and $want_ord_attrs eq 1 or ref $want_ord_attrs eq "ARRAY" and @{$want_ord_attrs;} == @{$attr_names;} and &all(sub { exists $heading->{$_}; } , @{$want_ord_attrs;}) 0 2 2
Condition16%2/12
not ref $want_ord_attrs and $want_ord_attrs eq 1 or ref $want_ord_attrs eq "ARRAY" and @{$want_ord_attrs;} == @{$attr_names;} and &all(sub { exists $heading->{$_}; } , @{$want_ord_attrs;})
l!l&&r!l&&!r
200
not ref $want_ord_attrs and $want_ord_attrs eq 1
!ll&&!rl&&r
002
ref $want_ord_attrs eq "ARRAY" and @{$want_ord_attrs;} == @{$attr_names;} and &all(sub { exists $heading->{$_}; } , @{$want_ord_attrs;})
!ll&&!rl&&r
000
ref $want_ord_attrs eq "ARRAY" and @{$want_ord_attrs;} == @{$attr_names;}
!ll&&!rl&&r
000
MC/DC0%0/5
not ref $want_ord_attrs and $want_ord_attrs eq 1 or ref $want_ord_attrs eq "ARRAY" and @{$want_ord_attrs;} == @{$attr_names;} and &all(sub { exists $heading->{$_}; } , @{$want_ord_attrs;})
not ref $want_ord_attrs $want_ord_attrs eq 1 ref $want_ord_attrs eq "ARRAY" @{$want_ord_attrs;} == @{$attr_names;} &all(sub { exists $heading->{$_}; } , @{$want_ord_attrs;})
Truth table11%1/9
not(A) and B or C and D and E
A= not ref $want_ord_attrsB= $want_ord_attrs eq 1C= ref $want_ord_attrs eq "ARRAY"D= @{$want_ord_attrs;} == @{$attr_names;}E= &all(sub { exists $heading->{$_}; } , @{$want_ord_attrs;})
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
455  
456 return
457 2 ▶ $want_ord_attrs eq '1' ? [sort @{$attr_names}] : $want_ord_attrs;
Branch: 1 branch
BranchTrueFalseTotal
$want_ord_attrs eq '1' ? : 2 0 2
458 }
459  
460 ###########################################################################
461  
462 0 ▶sub slice {
Subroutine slice: not called CC=6 SCAR=37.4
Pod undocumented
463 0 my ($self, $attr_names, $want_ord_attrs, $allow_dup_tuples) = @_;
464  
465 0 (my $proj_h, $attr_names)
466 = $self->_atnms_hr_from_assert_valid_atnms_arg(
467 'slice', '$attr_names', $attr_names );
468 0 my (undef, undef, $proj_only)
469 = $self->_ptn_conj_and_disj( $self->_heading(), $proj_h );
470 confess q{slice(): Bad $attr_names arg; that attr list}
471 . q{ isn't a subset of the invocant's heading.}
472 0 ▶ if @{$proj_only} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$proj_only;} > 0 0 0 0
473  
474 0 ▶ if (!$allow_dup_tuples and !$self->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $self->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $self->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $self->_is_known_dup_free
$allow_dup_tuples $self->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $self->_is_known_dup_free
ABresult
1X1
011
000
475 0 $self->_dup_free_want_index_over_all_attrs();
476 }
477  
478 0 ▶ if ($want_ord_attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_ord_attrs) { } 0 0 0
479 0 ▶ confess q{slice(): Bad $want_ord_attrs arg; it must be}
Branch: 1 branch
BranchTrueFalseTotal
if $want_ord_attrs ne 1 0 0 0
480 . q{ either undefined|false or the scalar value '1'.}
481 if $want_ord_attrs ne '1';
482 0 return [CORE::map { $self->_export_ofmt_tuple(
483 0 $attr_names, $_ ) } values %{$self->_body()}];
484 }
485 else {
486 return [CORE::map {
487 0 my $t = $_;
488 0 $t = {CORE::map { ($_ => $t->{$_}) } @{$attr_names}};
489 0 $self->_export_nfmt_tuple( $t );
490 0 } values %{$self->_body()}];
491 }
492 }
493  
494 ###########################################################################
495  
496 4 ▶sub attr {
Subroutine attr: called CC=5 SCAR=18.0
Pod undocumented
497 4 my ($self, $name, $allow_dup_tuples) = @_;
498  
499 4 $self->_assert_valid_atnm_arg( 'attr', '$name', $name );
500 confess q{attr(): Bad $name arg; that attr name}
501 . q{ doesn't match an attr of the invocant's heading.}
502 4 ▶ if !exists $self->_heading()->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->_heading->{$name} 0 4 4
503  
504 4 ▶ if (!$allow_dup_tuples and !$self->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $self->_is_known_dup_free) 0 4 4
Condition33%1/3
$allow_dup_tuples or $self->_is_known_dup_free
l!l&&r!l&&!r
040
MC/DC0%0/2
$allow_dup_tuples or $self->_is_known_dup_free
$allow_dup_tuples $self->_is_known_dup_free
Truth table33%1/3
A or B
A= $allow_dup_tuplesB= $self->_is_known_dup_free
ABresult
1X1
011
000
505 0 $self->_dup_free_want_index_over_all_attrs();
506 }
507  
508 return [CORE::map {
509 6 my $atvl = $_->{$name};
510 6 ▶ if (ref $atvl eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $atvl eq "HASH") 0 6 6
511 0 $atvl = $self->_export_nfmt_tuple( $atvl );
512 }
513 6 $atvl;
514 4 } values %{$self->_body()}];
515 }
516  
517 ###########################################################################
518  
519 0 ▶sub keys {
Subroutine keys: not called CC=1 SCAR=6.9
Pod undocumented
520 0 my ($self) = @_;
521 0 return [CORE::map { [sort @{$_}] } values %{$self->_keys()}];
522 }
523  
524 ###########################################################################
525  
526 13 ▶sub _normalize_same_heading_tuples_arg {
Subroutine _normalize_same_heading_tuples_arg: called CC=7 SCAR=21.0
527 13 my ($r, $rtn_nm, $arg_nm, $t) = @_;
528  
529 13 my $r_h = $r->_heading();
530  
531 13 ▶ if (ref $t eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t eq "HASH") 13 0 13
532 13 $t = [$t];
533 }
534 13 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg; it must be}
Branch: 1 branch
BranchTrueFalseTotal
if ref $t ne "ARRAY" 0 13 13
535 . q{ an array-ref or a hash-ref.}
536 if ref $t ne 'ARRAY';
537 13 for my $tuple (@{$t}) {
538 13 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg elem;}
Branch: 1 branch
BranchTrueFalseTotal
if ref $tuple ne "HASH" or not $r->_is_identical_hkeys($r_h, $tuple) 0 13 13
Condition33%1/3
ref $tuple ne "HASH" or not $r->_is_identical_hkeys($r_h, $tuple)
l!l&&r!l&&!r
0013
MC/DC0%0/2
ref $tuple ne "HASH" or not $r->_is_identical_hkeys($r_h, $tuple)
ref $tuple ne "HASH" not $r->_is_identical_hkeys($r_h, $tuple)
Truth table33%1/3
A or not(B)
A= ref $tuple ne "HASH"B= not $r->_is_identical_hkeys($r_h, $tuple)
ABresult
1X1
011
000
539 . q{ it isn't a hash-ref, or it doesn't have exactly the}
540 . q{ same set of attr names as the invocant.}
541 if ref $tuple ne 'HASH'
542 or !$r->_is_identical_hkeys( $r_h, $tuple );
543 13 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg elem;}
Branch: 1 branch
BranchTrueFalseTotal
if $r->_tuple_arg_has_circular_refs($tuple) 0 13 13
544 . q{ it is a hash-ref, and there exist circular refs}
545 . q{ between itself or its tuple-valued components.}
546 if $r->_tuple_arg_has_circular_refs( $tuple );
547 }
548  
549 13 return $t;
550 }
551  
552 ###########################################################################
553  
554 57 ▶sub _tuple_arg_has_circular_refs {
Subroutine _tuple_arg_has_circular_refs: called CC=6 SCAR=23.5
555 # This routine just checks that no Hash which would be treated as
556 # being of a value type contains itself as a component, where the
557 # component and any intermediate components are treated as value types.
558 # It *is* fine for a Hash to contain the same other Hash more than once
559 # such that the other is a sibling/cousin/etc to itself.
560 57 my ($self, $tuple, $ancs_of_tup_atvls) = @_;
561 0 ▶ $ancs_of_tup_atvls = $ancs_of_tup_atvls ? {%{$ancs_of_tup_atvls}} : {};
Branch: 1 branch
BranchTrueFalseTotal
$ancs_of_tup_atvls ? : 0 57 57
562 57 $ancs_of_tup_atvls->{refaddr $tuple} = undef;
563 57 for my $atvl (values %{$tuple}) {
564 231 ▶ if (ref $atvl eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $atvl eq "HASH") 0 231 231
565 return 1
566 0 ▶ if exists $ancs_of_tup_atvls->{refaddr $atvl};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$ancs_of_tup_atvls{builtin::refaddr($atvl)} 0 0 0
567 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $self->_tuple_arg_has_circular_refs($atvl, $ancs_of_tup_atvls) 0 0 0
568 if $self->_tuple_arg_has_circular_refs(
569 $atvl, $ancs_of_tup_atvls );
570 }
571 }
572 57 return 0;
573 }
574  
575 ###########################################################################
576  
577 93 ▶sub _is_identical_hkeys {
Subroutine _is_identical_hkeys: called CC=2 SCAR=7.0
578 93 my ($self, $h1, $h2) = @_;
579 93 my $h1_hkeys = [CORE::keys %{$h1}];
580 93 my $h2_hkeys = [CORE::keys %{$h2}];
581 93 return (@{$h1_hkeys} == @{$h2_hkeys}
582 93 ▶ and all { exists $h1->{$_} } @{$h2_hkeys});
Subroutine __ANON__: called CC=1 SCAR=0.4
Condition33%1/3
@{$h1_hkeys;} == @{$h2_hkeys;} && &all(sub { exists $h1->{$_}; } , @{$h2_hkeys;})
!ll&&!rl&&r
0093
MC/DC0%0/2
@{$h1_hkeys;} == @{$h2_hkeys;} && &all(sub { exists $h1->{$_}; } , @{$h2_hkeys;})
@{$h1_hkeys;} == @{$h2_hkeys;} &all(sub { exists $h1->{$_}; } , @{$h2_hkeys;})
Truth table33%1/3
A && B
A= @{$h1_hkeys;} == @{$h2_hkeys;}B= &all(sub { exists $h1->{$_}; } , @{$h2_hkeys;})
ABresult
0X0
100
111
583 }
584  
585 ###########################################################################
586  
587 60 ▶sub _heading_ident_str {
Subroutine _heading_ident_str: called CC=1 SCAR=0.0
588 60 my ($self, $heading) = @_;
589 my $vstr = CORE::join q{,}, CORE::map {
590 204 'Atnm:' . (length $_) . ':<' . $_ . '>'
591 60 } sort (CORE::keys %{$heading});
592 60 return 'Heading:' . (length $vstr) . ':{' . $vstr . '}';
593 }
594  
595 701 ▶sub _ident_str {
Subroutine _ident_str: called CC=6 SCAR=21.5
596 # Note, we assume that any hash-ref arg we get is specifically in
597 # internal tuple format, meaning each hval is a 2-elem array etc,
598 # and that this is recursive for hash-ref hvals of said.
599 701 my ($self, $value) = @_;
600 701 my $ident_str;
601 701 ▶ if (!defined $value) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $value) { } 0 701 701
elsif (not ref $value) { } 543 158 701
elsif (not builtin::blessed($value)) { } 158 0 158
602 # The Perl undef is equal to itself, distinct from all def values.
603 0 $ident_str = 'Undef';
604 }
605 elsif (!ref $value) {
606 # Treat all defined non-ref values as their string representation.
607 543 $ident_str = 'Scalar:' . (length $value) . ':<' . $value . '>';
608 }
609 elsif (!blessed $value) {
610 # By default, every non-object reference is distinct, and its
611 # identity is its memory address; the exception is if the reference
612 # is a hash-ref, in which case it is treated as an internal tuple.
613 158 ▶ if (ref $value eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 158 0 158
614 my $vstr = CORE::join q{,}, CORE::map {
615 543 my $atnm = 'Atnm:' . (length $_) . ':<' . $_ . '>';
616 543 my $atvl = $self->_ident_str( $value->{$_} );
617 543 "N=$atnm;V=$atvl";
618 158 } sort (CORE::keys %{$value});
619 158 $ident_str = 'Tuple:' . (length $vstr) . ':{' . $vstr . '}';
620 }
621 else {
622 0 my $vstr = "$value";
623 0 $ident_str = 'Ref:' . (length $vstr) . ':<' . $vstr . '>';
624 }
625 }
626 else {
627 # By default, every object instance is distinct, and its identity
628 # is its memory address; the exception is if the object is a
629 # Set::Relation::V2 or if it overloads stringification.
630 0 ▶ if ($value->isa( __PACKAGE__ )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa(__PACKAGE__)) { } 0 0 0
631 0 $ident_str = $value->which(); # 'Relation:...'
632 }
633 else {
634 0 my $vstr = "$value";
635 0 $ident_str = 'Object[' . (blessed $value) . ']:'
636 . (length $vstr) . ':<' . $vstr . '>';
637 }
638 }
639 701 return $ident_str;
640 }
641  
642 ###########################################################################
643  
644 57 ▶sub _import_nfmt_tuple {
Subroutine _import_nfmt_tuple: called CC=6 SCAR=22.4
645 57 my ($self, $tuple) = @_;
646 return {CORE::map {
647 231 my $atnm = $_;
648 231 my $atvl = $tuple->{$_};
649 231 ▶ if (ref $atvl eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $atvl eq 'HASH') { } 0 231 231
elsif (builtin::blessed($atvl) and $atvl->can('does') and $atvl->does('Set::Relation') and not $atvl->isa(__PACKAGE__)) { } 0 462 462
650 0 $atvl = $self->_import_nfmt_tuple( $atvl );
651 }
652 ▶ elsif (blessed $atvl and $atvl->can( 'does' )
Condition33%3/9
builtin::blessed($atvl) and $atvl->can("does") and $atvl->does("Set::Relation") and not $atvl->isa(__PACKAGE__)
!ll&&!rl&&r
23100
builtin::blessed($atvl) and $atvl->can("does") and $atvl->does("Set::Relation")
!ll&&!rl&&r
23100
builtin::blessed($atvl) and $atvl->can("does")
!ll&&!rl&&r
23100
MC/DC0%0/4
builtin::blessed($atvl) and $atvl->can("does") and $atvl->does("Set::Relation") and not $atvl->isa(__PACKAGE__)
builtin::blessed($atvl) $atvl->can("does") $atvl->does("Set::Relation") not $atvl->isa(__PACKAGE__)
Truth table20%1/5
A and B and C and not(D)
A= builtin::blessed($atvl)B= $atvl->can("does")C= $atvl->does("Set::Relation")D= not $atvl->isa(__PACKAGE__)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
653 and $atvl->does( 'Set::Relation' )
654 and !$atvl->isa( __PACKAGE__ )) {
655 0 $atvl = $self->_new( $atvl );
656 }
657 231 ($atnm => $atvl);
658 57 } CORE::keys %{$tuple}};
659 }
660  
661 181 ▶sub _export_nfmt_tuple {
Subroutine _export_nfmt_tuple: called CC=2 SCAR=7.1
662 181 my ($self, $tuple) = @_;
663 return {CORE::map {
664 724 my $atnm = $_;
665 724 my $atvl = $tuple->{$_};
666 724 ▶ if (ref $atvl eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $atvl eq "HASH") 0 724 724
667 0 $atvl = $self->_export_nfmt_tuple( $atvl );
668 }
669 724 ($atnm => $atvl);
670 181 } CORE::keys %{$tuple}};
671 }
672  
673 35 ▶sub _import_ofmt_tuple {
Subroutine _import_ofmt_tuple: called CC=6 SCAR=22.4
674 35 my ($self, $atnms, $atvls) = @_;
675 return {CORE::map {
676 125 my $atnm = $atnms->[$_];
677 125 my $atvl = $atvls->[$_];
678 125 ▶ if (ref $atvl eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $atvl eq 'HASH') { } 0 125 125
elsif (builtin::blessed($atvl) and $atvl->can('does') and $atvl->does('Set::Relation') and not $atvl->isa(__PACKAGE__)) { } 0 250 250
679 0 $atvl = $self->_import_nfmt_tuple( $atvl );
680 }
681 ▶ elsif (blessed $atvl and $atvl->can( 'does' )
Condition33%3/9
builtin::blessed($atvl) and $atvl->can("does") and $atvl->does("Set::Relation") and not $atvl->isa(__PACKAGE__)
!ll&&!rl&&r
12500
builtin::blessed($atvl) and $atvl->can("does") and $atvl->does("Set::Relation")
!ll&&!rl&&r
12500
builtin::blessed($atvl) and $atvl->can("does")
!ll&&!rl&&r
12500
MC/DC0%0/4
builtin::blessed($atvl) and $atvl->can("does") and $atvl->does("Set::Relation") and not $atvl->isa(__PACKAGE__)
builtin::blessed($atvl) $atvl->can("does") $atvl->does("Set::Relation") not $atvl->isa(__PACKAGE__)
Truth table20%1/5
A and B and C and not(D)
A= builtin::blessed($atvl)B= $atvl->can("does")C= $atvl->does("Set::Relation")D= not $atvl->isa(__PACKAGE__)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
682 and $atvl->does( 'Set::Relation' )
683 and !$atvl->isa( __PACKAGE__ )) {
684 0 $atvl = $self->_new( $atvl );
685 }
686 125 ($atnm => $atvl);
687 35 } 0..$#{$atnms}};
688 }
689  
690 5 ▶sub _export_ofmt_tuple {
Subroutine _export_ofmt_tuple: called CC=2 SCAR=7.1
691 5 my ($self, $atnms, $tuple) = @_;
692 return [CORE::map {
693 12 my $atvl = $tuple->{$_};
694 12 ▶ if (ref $atvl eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $atvl eq "HASH") 0 12 12
695 0 $atvl = $self->_export_nfmt_tuple( $atvl );
696 }
697 12 $atvl;
698 5 } @{$atnms}];
699 }
700  
701 ###########################################################################
702  
703 55 ▶sub degree {
Subroutine degree: called CC=1 SCAR=0.0
Pod undocumented
704 55 my ($topic) = @_;
705 55 return scalar CORE::keys %{$topic->_heading()};
706 }
707  
708 4 ▶sub is_nullary {
Subroutine is_nullary: called CC=1 SCAR=0.0
Pod undocumented
709 4 my ($topic) = @_;
710 4 return $topic->degree() == 0;
711 }
712  
713 0 ▶sub has_attrs {
Subroutine has_attrs: not called CC=1 SCAR=6.9
Pod undocumented
714 0 my ($topic, $attr_names) = @_;
715 0 (my $proj_h, $attr_names)
716 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
717 'has_attrs', '$attr_names', $attr_names );
718 0 my (undef, undef, $proj_only)
719 = $topic->_ptn_conj_and_disj( $topic->_heading(), $proj_h );
720 0 return @{$proj_only} == 0;
721 }
722  
723 0 ▶sub attr_names {
Subroutine attr_names: not called CC=1 SCAR=6.9
Pod undocumented
724 0 my ($topic) = @_;
725 0 return [sort (CORE::keys %{$topic->_heading()})];
726 }
727  
728 ###########################################################################
729  
730 119 ▶sub cardinality {
Subroutine cardinality: called CC=4 SCAR=13.9
Pod undocumented
731 119 my ($topic, $allow_dup_tuples) = @_;
732 119 my $on_entry_body_cardinality = scalar CORE::keys %{$topic->_body()};
733 119 ▶ if ($topic->_is_known_dup_free()) {
Branch: 3 branches
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) { } 87 32 119
elsif ($on_entry_body_cardinality == 0) { } 1 31 32
elsif ($allow_dup_tuples) { } 15 16 31
734 87 return $on_entry_body_cardinality;
735 }
736 elsif ($on_entry_body_cardinality == 0) {
737 1 $topic->_is_known_dup_free( 1 );
738 1 return 0;
739 }
740 elsif ($allow_dup_tuples) {
741 15 return $on_entry_body_cardinality;
742 }
743 else {
744 16 $topic->_dup_free_want_index_over_all_attrs();
745 16 return scalar CORE::keys %{$topic->_body()};
746 }
747 }
748  
749 0 ▶sub count {
Subroutine count: not called CC=1 SCAR=6.9
Pod undocumented
750 0 my ($self, @args) = @_;
751 0 return $self->cardinality( @args );
752 }
753  
754 58 ▶sub is_empty {
Subroutine is_empty: called CC=1 SCAR=0.0
Pod undocumented
755 58 my ($topic) = @_;
756 58 return $topic->cardinality( 1 ) == 0;
757 }
758  
759 0 ▶sub has_member {
Subroutine has_member: not called CC=1 SCAR=6.9
Pod undocumented
760 0 my ($r, $t) = @_;
761 0 $t = $r->_normalize_same_heading_tuples_arg( 'has_member', '$t', $t );
762 0 my $r_i = $r->_dup_free_want_index_over_all_attrs();
763 0 ▶ return all {
Subroutine __ANON__: not called CC=1 SCAR=6.9
764 0 exists $r_i->{$r->_ident_str( $r->_import_nfmt_tuple( $_ ) )}
765 0 } @{$t};
766 }
767  
768 ###########################################################################
769  
770 0 ▶sub has_key {
Subroutine has_key: not called CC=2 SCAR=17.9
Pod undocumented
771 0 my ($topic, $attr_names) = @_;
772 0 (undef, $attr_names) = $topic->_atnms_hr_from_assert_valid_atnms_arg(
773 'has_key', '$attr_names', $attr_names );
774 0 my $topic_h = $topic->_heading();
775 confess q{has_key(): Bad $attr_names arg; that attr list}
776 . q{ isn't a subset of the invocant's heading.}
777 0 ▶ if notall { exists $topic_h->{$_} } @{$attr_names};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { exists $topic_h->{$_}; } , @{$attr_names;}) 0 0 0
778 0 return $topic->_has_key( $attr_names );
779 }
780  
781 0 ▶sub _has_key {
Subroutine _has_key: not called CC=3 SCAR=24.8
782 0 my ($topic, $attr_names) = @_;
783  
784 0 my $subheading = {CORE::map { ($_ => undef) } @{$attr_names}};
785 0 my $subheading_ident_str = $topic->_heading_ident_str( $subheading );
786 0 my $keys = $topic->_keys();
787  
788 return 1
789 0 ▶ if exists $keys->{$subheading_ident_str};
Branch: 1 branch
BranchTrueFalseTotal
if exists $keys->{$subheading_ident_str} 0 0 0
790  
791 0 my $index = $topic->_want_index( $attr_names );
792  
793 return 0
794 0 ▶ if notall { (CORE::keys %{$_}) == 1 } values %{$index};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { CORE::keys %{$_;} == 1; } , values %{$index;}) 0 0 0
795  
796 0 $keys->{$subheading_ident_str} = $subheading;
797 0 return 1;
798 }
799  
800 ###########################################################################
801  
802 32 ▶sub empty {
Subroutine empty: called CC=2 SCAR=6.9
Pod undocumented
803 32 my ($topic) = @_;
804 32 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 1 31 32
805 1 return $topic;
806 }
807 31 my $result = $topic->_new();
808 31 $result->_heading( $topic->_heading() );
809 31 return $result;
810 }
811  
812 13 ▶sub insertion {
Subroutine insertion: called CC=2 SCAR=7.0
Pod undocumented
813 13 my ($r, $t) = @_;
814  
815 13 $t = $r->_normalize_same_heading_tuples_arg( 'insertion', '$t', $t );
816  
817 13 ▶ if (@{$t} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$t;} == 0) 0 13 13
818 0 return $r;
819 }
820  
821 my $tuples = {CORE::map {
822 13 my $tuple = $r->_import_nfmt_tuple( $_ );
823 13 (refaddr $tuple, $tuple);
824 13 } @{$t}};
825  
826 13 my $result = $r->empty();
827  
828 13 $result->_body( {%{$r->_body()}, %{$tuples}} );
829  
830 13 return $result;
831 }
832  
833 0 ▶sub deletion {
Subroutine deletion: not called CC=4 SCAR=30.0
Pod undocumented
834 0 my ($r, $t) = @_;
835  
836 0 $t = $r->_normalize_same_heading_tuples_arg( 'deletion', '$t', $t );
837  
838 0 ▶ if (@{$t} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$t;} == 0) 0 0 0
839 0 return $r;
840 }
841  
842 my $tuples = {CORE::map {
843 0 my $tuple = $r->_import_nfmt_tuple( $_ );
844 0 ($r->_ident_str( $tuple ), $tuple);
845 0 } @{$t}};
846  
847 0 my $result = $r->empty();
848  
849 0 my $r_i = $r->_dup_free_want_index_over_all_attrs();
850 0 my $result_b = $result->_body();
851  
852 0 for my $tuple_ident_str (CORE::keys %{$r_i}) {
853 0 ▶ if (!exists $tuples->{$tuple_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $tuples->{$tuple_ident_str}) 0 0 0
854 0 my ($tuple_refaddr, $tuple) = %{$r_i->{$tuple_ident_str}};
855 0 $result_b->{$tuple_refaddr} = $tuple;
856 }
857 }
858  
859 0 $result->_is_known_dup_free( 1 );
860  
861 0 return $result;
862 }
863  
864 ###########################################################################
865  
866 1 ▶sub rename {
Subroutine rename: called CC=6 SCAR=18.7
Pod undocumented
867 1 my ($topic, $map) = @_;
868  
869 1 ▶ confess q{rename(): Bad $map arg; it must be a hash-ref.}
Branch: 1 branch
BranchTrueFalseTotal
if ref $map ne "HASH" 0 1 1
870 if ref $map ne 'HASH';
871 confess q{rename(): Bad $map arg;}
872 . q{ its hash elem values should be just be a list of attr}
873 . q{ names, but at least one name is undefined or isa ref.}
874 1 ▶ if notall { defined $_ and !ref $_ } values %{$map};
Subroutine __ANON__: called CC=2 SCAR=7.4
Branch: 2 branches
BranchTrueFalseTotal
if &notall(sub { defined $_ and not ref $_; } , values %{$map;}) 0 1 1
defined $_ and not ref $_ 4 0 4
875 confess q{rename(): Bad $map arg;}
876 . q{ its hash elem values specify a list of}
877 . q{ attr names with at least one duplicated name.}
878 1 ▶ if (uniqstr values %{$map}) != (CORE::keys %{$map});
Branch: 1 branch
BranchTrueFalseTotal
if &uniqstr(values %{$map;}) != CORE::keys %{$map;} 0 1 1
879  
880 my ($topic_attrs_to_ren, $topic_attrs_no_ren, $map_hvals_not_in_topic)
881 = $topic->_ptn_conj_and_disj(
882 1 $topic->_heading(), {reverse %{$map}} );
883 confess q{rename(): Bad $map arg; that list of attrs to be renamed,}
884 . q{ the hash values, isn't a subset of th invocant's heading.}
885 1 ▶ if @{$map_hvals_not_in_topic} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$map_hvals_not_in_topic;} > 0 0 1 1
886  
887 my ($map_hkeys_same_as_topic_no_ren, undef, undef)
888 = $topic->_ptn_conj_and_disj(
889 0 {CORE::map { ($_ => undef) } @{$topic_attrs_no_ren}}, $map );
890 confess q{rename(): Bad $map arg; at least one key of that hash,}
891 . q{ a new name for an attr of the invocant to rename,}
892 . q{ duplicates an attr of the invocant not being renamed.}
893 1 ▶ if @{$map_hkeys_same_as_topic_no_ren} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$map_hkeys_same_as_topic_no_ren;} > 0 0 1 1
894  
895 1 return $topic->_rename( $map );
896 }
897  
898 1 ▶sub _rename {
Subroutine _rename: called CC=5 SCAR=16.2
899 1 my ($topic, $map) = @_;
900  
901 # Remove any explicit no-ops of an attr being renamed to the same name.
902 4 $map = {CORE::map { ($_ => $map->{$_}) }
903 1 grep { $map->{$_} ne $_ } CORE::keys %{$map}};
904  
905 1 ▶ if ((scalar CORE::keys %{$map}) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar CORE::keys %{$map;} == 0) 0 1 1
906 # Rename of zero attrs of input yields the input.
907 0 return $topic;
908 }
909  
910 # Expand map to specify all topic attrs being renamed to something.
911 1 my $inv_map = {reverse %{$map}};
912 $map = {CORE::map { ((
913 4 ▶ exists $inv_map->{$_} ? $inv_map->{$_} : $_
Branch: 1 branch
BranchTrueFalseTotal
exists $inv_map->{$_} ? : 4 0 4
914 1 ) => $_) } CORE::keys %{$topic->_heading()}};
915  
916 1 my $result = $topic->_new();
917  
918 1 $result->_heading( {CORE::map { ($_ => undef) } CORE::keys %{$map}} );
919  
920 1 my $result_b = $result->_body();
921  
922 1 for my $topic_t (values %{$topic->_body()}) {
923 my $result_t = {CORE::map {
924 20 ($_ => $topic_t->{$map->{$_}})
925 5 } CORE::keys %{$map}};
926 5 $result_b->{refaddr $result_t} = $result_t;
927 }
928  
929 1 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 1 0 1
930 1 $result->_is_known_dup_free( 1 );
931 }
932  
933 1 return $result;
934 }
935  
936 ###########################################################################
937  
938 1 ▶sub projection {
Subroutine projection: called CC=2 SCAR=7.0
Pod undocumented
939 1 my ($topic, $attr_names) = @_;
940  
941 1 (my $proj_h, $attr_names)
942 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
943 'projection', '$attr_names', $attr_names );
944 1 my (undef, undef, $proj_only)
945 = $topic->_ptn_conj_and_disj( $topic->_heading(), $proj_h );
946 confess q{projection(): Bad $attr_names arg; that attr list}
947 . q{ isn't a subset of the invocant's heading.}
948 1 ▶ if @{$proj_only} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$proj_only;} > 0 0 1 1
949  
950 1 return $topic->_projection( $attr_names );
951 }
952  
953 1 ▶sub _projection {
Subroutine _projection: called CC=5 SCAR=17.3
954 1 my ($topic, $attr_names) = @_;
955  
956 1 ▶ if (@{$attr_names} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$attr_names;} == 0) 0 1 1
957 # Projection of zero attrs yields identity relation zero or one.
958 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) { } 0 0 0
959 0 return $topic->_new();
960 }
961 else {
962 0 return $topic->_new( [ {} ] );
963 }
964 }
965 1 ▶ if (@{$attr_names} == $topic->degree()) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$attr_names;} == $topic->degree) 0 1 1
966 # Projection of all attrs of input yields the input.
967 0 return $topic;
968 }
969  
970 1 my $result = $topic->_new();
971  
972 1 $result->_heading( {CORE::map { ($_ => undef) } @{$attr_names}} );
973  
974 1 my $result_b = $result->_body();
975  
976 1 for my $topic_t (values %{$topic->_body()}) {
977 my $result_t
978 5 = {CORE::map { ($_ => $topic_t->{$_}) } @{$attr_names}};
979 5 $result_b->{refaddr $result_t} = $result_t;
980 }
981  
982 1 return $result;
983 }
984  
985 0 ▶sub cmpl_proj {
Subroutine cmpl_proj: not called CC=2 SCAR=17.9
Pod undocumented
986 0 my ($topic, $attr_names) = @_;
987  
988 0 my $topic_h = $topic->_heading();
989  
990 0 (my $cproj_h, $attr_names)
991 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
992 'cmpl_proj', '$attr_names', $attr_names );
993 0 my (undef, undef, $cproj_only)
994 = $topic->_ptn_conj_and_disj( $topic_h, $cproj_h );
995 confess q{cmpl_proj(): Bad $attr_names arg; that attr list}
996 . q{ isn't a subset of the invocant's heading.}
997 0 ▶ if @{$cproj_only} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$cproj_only;} > 0 0 0 0
998  
999 return $topic->_projection(
1000 0 [grep { !$cproj_h->{$_} } CORE::keys %{$topic_h}] );
1001 }
1002  
1003 ###########################################################################
1004  
1005 0 ▶sub wrap {
Subroutine wrap: not called CC=3 SCAR=24.8
Pod undocumented
1006 0 my ($topic, $outer, $inner) = @_;
1007  
1008 0 $topic->_assert_valid_atnm_arg( 'wrap', '$outer', $outer );
1009 0 (my $inner_h, $inner) = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1010 'wrap', '$inner', $inner );
1011  
1012 0 my (undef, $topic_attrs_no_wr, $inner_attrs_not_in_topic)
1013 = $topic->_ptn_conj_and_disj( $topic->_heading(), $inner_h );
1014 confess q{wrap(): Bad $inner arg; that list of attrs to be wrapped}
1015 . q{ isn't a subset of the invocant's heading.}
1016 0 ▶ if @{$inner_attrs_not_in_topic} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$inner_attrs_not_in_topic;} > 0 0 0 0
1017 confess q{wrap(): Bad $outer arg; that name for a new attr to add}
1018 . q{ to the invocant, consisting of wrapped invocant attrs,}
1019 . q{ duplicates an attr of the invocant not being wrapped.}
1020 0 ▶ if any { $_ eq $outer } @{$topic_attrs_no_wr};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_ eq $outer; } , @{$topic_attrs_no_wr;}) 0 0 0
1021  
1022 0 return $topic->_wrap( $outer, $inner, $topic_attrs_no_wr );
1023 }
1024  
1025 0 ▶sub _wrap {
Subroutine _wrap: not called CC=8 SCAR=42.8
1026 0 my ($topic, $outer, $inner, $topic_attrs_no_wr) = @_;
1027  
1028 0 my $result = $topic->_new();
1029  
1030 $result->_heading(
1031 0 {CORE::map { ($_ => undef) } @{$topic_attrs_no_wr}, $outer} );
1032  
1033 0 my $topic_b = $topic->_body();
1034 0 my $result_b = $result->_body();
1035  
1036 0 ▶ if ($topic->is_empty()) {
Branch: 3 branches
BranchTrueFalseTotal
if ($topic->is_empty) { } 0 0 0
elsif (@{$inner;} == 0) { } 0 0 0
elsif (@{$topic_attrs_no_wr;} == 0) { } 0 0 0
1037 # An empty $topic means an empty result.
1038 # So $result_b is already correct.
1039 }
1040 0 elsif (@{$inner} == 0) {
1041 # Wrap zero $topic attrs as new attr.
1042 # So this is a simple static extension of $topic w static $outer.
1043 0 my $inner_t = {};
1044 0 for my $topic_t (values %{$topic_b}) {
1045 0 my $result_t = {$outer => $inner_t, {%{$topic_t}}};
1046 0 $result_b->{refaddr $result_t} = $result_t;
1047 }
1048 }
1049 0 elsif (@{$topic_attrs_no_wr} == 0) {
1050 # Wrap all $topic attrs as new attr.
1051 0 for my $topic_t_refaddr (CORE::keys %{$topic_b}) {
1052 0 my $result_t = {$outer => $topic_b->{$topic_t_refaddr}};
1053 0 $result_b->{refaddr $result_t} = $result_t;
1054 }
1055 }
1056 else {
1057 # Wrap at least one but not all $topic attrs as new attr.
1058 0 for my $topic_t (values %{$topic_b}) {
1059 0 my $inner_t = {CORE::map { ($_ => $topic_t->{$_}) } @{$inner}};
1060 my $result_t = {
1061 $outer => $inner_t,
1062 0 CORE::map { ($_ => $topic_t->{$_}) } @{$topic_attrs_no_wr}
1063 };
1064 0 $result_b->{refaddr $result_t} = $result_t;
1065 }
1066 }
1067  
1068 0 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 0 0 0
1069 0 $result->_is_known_dup_free( 1 );
1070 }
1071  
1072 0 return $result;
1073 }
1074  
1075 0 ▶sub cmpl_wrap {
Subroutine cmpl_wrap: not called CC=3 SCAR=24.8
Pod undocumented
1076 0 my ($topic, $outer, $cmpl_inner) = @_;
1077  
1078 0 $topic->_assert_valid_atnm_arg( 'cmpl_wrap', '$outer', $outer );
1079 0 (my $cmpl_inner_h, $cmpl_inner)
1080 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1081 'cmpl_wrap', '$cmpl_inner', $cmpl_inner );
1082  
1083 0 my $topic_h = $topic->_heading();
1084  
1085 confess q{cmpl_wrap(): Bad $cmpl_inner arg; that attr list}
1086 . q{ isn't a subset of the invocant's heading.}
1087 0 ▶ if notall { exists $topic_h->{$_} } @{$cmpl_inner};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { exists $topic_h->{$_}; } , @{$cmpl_inner;}) 0 0 0
1088  
1089 0 my $inner = [grep { !$cmpl_inner_h->{$_} } CORE::keys %{$topic_h}];
1090 0 my $inner_h = {CORE::map { $_ => undef } @{$inner}};
1091  
1092 0 my (undef, $topic_attrs_no_wr, undef)
1093 = $topic->_ptn_conj_and_disj( $topic_h, $inner_h );
1094 confess q{cmpl_wrap(): Bad $outer arg; that name for a new attr to add}
1095 . q{ to the invocant, consisting of wrapped invocant attrs,}
1096 . q{ duplicates an attr of the invocant not being wrapped.}
1097 0 ▶ if any { $_ eq $outer } @{$topic_attrs_no_wr};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_ eq $outer; } , @{$topic_attrs_no_wr;}) 0 0 0
1098  
1099 0 return $topic->_wrap( $outer, $inner, $topic_attrs_no_wr );
1100 }
1101  
1102 ###########################################################################
1103  
1104 0 ▶sub unwrap {
Subroutine unwrap: not called CC=13 SCAR=52.0
Pod undocumented
1105 0 my ($topic, $inner, $outer) = @_;
1106  
1107 0 (my $inner_h, $inner) = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1108 'unwrap', '$inner', $inner );
1109 0 $topic->_assert_valid_atnm_arg( 'unwrap', '$outer', $outer );
1110  
1111 0 my $topic_h = $topic->_heading();
1112  
1113 confess q{unwrap(): Bad $outer arg; that attr name}
1114 . q{ doesn't match an attr of the invocant's heading.}
1115 0 ▶ if !exists $topic_h->{$outer};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $topic_h->{$outer} 0 0 0
1116  
1117 0 my $topic_h_except_outer = {%{$topic_h}};
1118 0 delete $topic_h_except_outer->{$outer};
1119  
1120 0 my ($inner_attrs_dupl_topic, $topic_attrs_no_uwr, undef)
1121 = $topic->_ptn_conj_and_disj( $topic_h_except_outer, $inner_h );
1122 confess q{unwrap(): Bad $inner arg; at least one name in that attr}
1123 . q{ list, which the invocant would be extended with when}
1124 . q{ unwrapping $topic{$outer}, duplicates an attr of the}
1125 . q{ invocant not being unwrapped.}
1126 0 ▶ if @{$inner_attrs_dupl_topic} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$inner_attrs_dupl_topic;} > 0 0 0 0
1127  
1128 0 my $topic_b = $topic->_body();
1129  
1130 0 for my $topic_t (values %{$topic_b}) {
1131 0 my $inner_t = $topic_t->{$outer};
1132 0 ▶ confess q{unwrap(): Can't unwrap $topic{$outer} because there is}
Branch: 1 branch
BranchTrueFalseTotal
if ref $inner_t ne "HASH" or not $topic->_is_identical_hkeys($inner_h, $inner_t) 0 0 0
Condition0%0/3
ref $inner_t ne "HASH" or not $topic->_is_identical_hkeys($inner_h, $inner_t)
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $inner_t ne "HASH" or not $topic->_is_identical_hkeys($inner_h, $inner_t)
ref $inner_t ne "HASH" not $topic->_is_identical_hkeys($inner_h, $inner_t)
Truth table0%0/3
A or not(B)
A= ref $inner_t ne "HASH"B= not $topic->_is_identical_hkeys($inner_h, $inner_t)
ABresult
1X1
011
000
1133 . q{ not a same-heading tuple value for the $outer attr of}
1134 . q{ every tuple of $topic whose heading matches $inner.}
1135 if ref $inner_t ne 'HASH'
1136 or !$topic->_is_identical_hkeys( $inner_h, $inner_t );
1137 }
1138  
1139 0 my $result = $topic->_new();
1140  
1141 0 $result->_heading( {%{$topic_h_except_outer}, %{$inner_h}} );
1142  
1143 0 my $result_b = $result->_body();
1144  
1145 0 ▶ if ($topic->is_empty()) {
Branch: 3 branches
BranchTrueFalseTotal
if ($topic->is_empty) { } 0 0 0
elsif (@{$topic_attrs_no_uwr;} == 0) { } 0 0 0
elsif (@{$inner;} == 0) { } 0 0 0
1146 # An empty $topic means an empty result.
1147 # So $result_b is already correct.
1148 }
1149 0 elsif (@{$topic_attrs_no_uwr} == 0) {
1150 # Only $topic attr is $outer, all result attrs from $outer unwrap.
1151 0 for my $topic_t (values %{$topic_b}) {
1152 0 my $result_t = $topic_t->{$outer};
1153 0 $result_b->{refaddr $result_t} = $result_t;
1154 }
1155 }
1156 0 elsif (@{$inner} == 0) {
1157 # Unwrap of $outer adds zero attrs to $topic.
1158 # So this is a simple projection of $topic excising $outer.
1159 0 for my $topic_t (values %{$topic_b}) {
1160 my $result_t = {
1161 0 CORE::map { ($_ => $topic_t->{$_}) } @{$topic_attrs_no_uwr}
1162 };
1163 0 $result_b->{refaddr $result_t} = $result_t;
1164 }
1165 }
1166 else {
1167 # Result has at least 1 attr from $outer, at least 1 not from it.
1168 0 for my $topic_t (values %{$topic_b}) {
1169 my $result_t = {
1170 0 %{$topic_t->{$outer}},
1171 0 CORE::map { ($_ => $topic_t->{$_}) } @{$topic_attrs_no_uwr}
1172 };
1173 0 $result_b->{refaddr $result_t} = $result_t;
1174 }
1175 }
1176  
1177 0 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 0 0 0
1178 0 $result->_is_known_dup_free( 1 );
1179 }
1180  
1181 0 return $result;
1182 }
1183  
1184 ###########################################################################
1185  
1186 1 ▶sub group {
Subroutine group: called CC=3 SCAR=11.1
Pod undocumented
1187 1 my ($topic, $outer, $inner) = @_;
1188  
1189 1 $topic->_assert_valid_atnm_arg( 'group', '$outer', $outer );
1190 1 (my $inner_h, $inner) = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1191 'group', '$inner', $inner );
1192  
1193 1 my (undef, $topic_attrs_no_gr, $inner_attrs_not_in_topic)
1194 = $topic->_ptn_conj_and_disj( $topic->_heading(), $inner_h );
1195 confess q{group(): Bad $inner arg; that list of attrs to be grouped}
1196 . q{ isn't a subset of the invocant's heading.}
1197 1 ▶ if @{$inner_attrs_not_in_topic} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$inner_attrs_not_in_topic;} > 0 0 1 1
1198 confess q{group(): Bad $outer arg; that name for a new attr to add}
1199 . q{ to the invocant, consisting of grouped invocant attrs,}
1200 . q{ duplicates an attr of the invocant not being grouped.}
1201 1 ▶ if any { $_ eq $outer } @{$topic_attrs_no_gr};
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_ eq $outer; } , @{$topic_attrs_no_gr;}) 0 1 1
1202  
1203 1 return $topic->_group( $outer, $inner, $topic_attrs_no_gr, $inner_h );
1204 }
1205  
1206 1 ▶sub _group {
Subroutine _group: called CC=8 SCAR=22.4
1207 1 my ($topic, $outer, $inner, $topic_attrs_no_gr, $inner_h) = @_;
1208  
1209 1 my $result = $topic->_new();
1210  
1211 $result->_heading(
1212 1 {CORE::map { ($_ => undef) } @{$topic_attrs_no_gr}, $outer} );
1213  
1214 1 ▶ if ($topic->is_empty()) {
Branch: 3 branches
BranchTrueFalseTotal
if ($topic->is_empty) { } 0 1 1
elsif (@{$inner;} == 0) { } 0 1 1
elsif (@{$topic_attrs_no_gr;} == 0) { } 0 1 1
1215 # An empty $topic means an empty result.
1216 # So result body is already correct.
1217 }
1218 1 elsif (@{$inner} == 0) {
1219 # Group zero $topic attrs as new attr.
1220 # So this is a simple static extension of $topic w static $outer.
1221 0 my $result_b = $result->_body();
1222 0 my $inner_r = $topic->_new( [ {} ] );
1223 0 for my $topic_t (values %{$topic->_body()}) {
1224 0 my $result_t = {$outer => $inner_r, {%{$topic_t}}};
1225 0 $result_b->{refaddr $result_t} = $result_t;
1226 }
1227 }
1228 1 elsif (@{$topic_attrs_no_gr} == 0) {
1229 # Group all $topic attrs as new attr.
1230 # So $topic is just used as sole attr of sole tuple of result.
1231 0 my $result_t = {$outer => $topic};
1232 0 $result->_body( {refaddr $result_t => $result_t} );
1233 }
1234 else {
1235 # Group at least one but not all $topic attrs as new attr.
1236 1 my $result_b = $result->_body();
1237 1 my $topic_index = $topic->_want_index( $topic_attrs_no_gr );
1238 1 for my $matched_topic_b (values %{$topic_index}) {
1239  
1240 3 my $inner_r = $topic->_new();
1241 3 $inner_r->_heading( $inner_h );
1242 3 my $inner_b = $inner_r->_body();
1243 3 for my $topic_t (values %{$matched_topic_b}) {
1244 my $inner_t
1245 5 = {CORE::map { ($_ => $topic_t->{$_}) } @{$inner}};
1246 5 $inner_b->{refaddr $inner_t} = $inner_t;
1247 }
1248  
1249 3 my $any_mtpt = (values %{$matched_topic_b})[0];
1250  
1251 my $result_t = {
1252 $outer => $inner_r,
1253 3 CORE::map { ($_ => $any_mtpt->{$_}) } @{$topic_attrs_no_gr}
1254 };
1255 3 $result_b->{refaddr $result_t} = $result_t;
1256 }
1257 }
1258  
1259 1 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 1 0 1
1260 1 $result->_is_known_dup_free( 1 );
1261 }
1262  
1263 1 return $result;
1264 }
1265  
1266 0 ▶sub cmpl_group {
Subroutine cmpl_group: not called CC=3 SCAR=24.8
Pod undocumented
1267 0 my ($topic, $outer, $group_per) = @_;
1268  
1269 0 $topic->_assert_valid_atnm_arg( 'cmpl_group', '$outer', $outer );
1270 0 (my $group_per_h, $group_per)
1271 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1272 'cmpl_group', '$group_per', $group_per );
1273  
1274 0 my $topic_h = $topic->_heading();
1275  
1276 confess q{cmpl_group(): Bad $group_per arg; that attr list}
1277 . q{ isn't a subset of the invocant's heading.}
1278 0 ▶ if notall { exists $topic_h->{$_} } @{$group_per};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { exists $topic_h->{$_}; } , @{$group_per;}) 0 0 0
1279  
1280 0 my $inner = [grep { !$group_per_h->{$_} } CORE::keys %{$topic_h}];
1281 0 my $inner_h = {CORE::map { $_ => undef } @{$inner}};
1282  
1283 0 my (undef, $topic_attrs_no_gr, undef)
1284 = $topic->_ptn_conj_and_disj( $topic_h, $inner_h );
1285 confess q{cmpl_group(): Bad $outer arg; that name for a new attr to}
1286 . q{ add to th invocant, consisting of grouped invocant attrs,}
1287 . q{ duplicates an attr of the invocant not being grouped.}
1288 0 ▶ if any { $_ eq $outer } @{$topic_attrs_no_gr};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_ eq $outer; } , @{$topic_attrs_no_gr;}) 0 0 0
1289  
1290 0 return $topic->_group( $outer, $inner, $topic_attrs_no_gr, $inner_h );
1291 }
1292  
1293 ###########################################################################
1294  
1295 0 ▶sub ungroup {
Subroutine ungroup: not called CC=13 SCAR=52.0
Pod undocumented
1296 0 my ($topic, $inner, $outer) = @_;
1297  
1298 0 (my $inner_h, $inner) = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1299 'ungroup', '$inner', $inner );
1300 0 $topic->_assert_valid_atnm_arg( 'ungroup', '$outer', $outer );
1301  
1302 0 my $topic_h = $topic->_heading();
1303  
1304 confess q{ungroup(): Bad $outer arg; that attr name}
1305 . q{ doesn't match an attr of the invocant's heading.}
1306 0 ▶ if !exists $topic_h->{$outer};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $topic_h->{$outer} 0 0 0
1307  
1308 0 my $topic_h_except_outer = {%{$topic_h}};
1309 0 delete $topic_h_except_outer->{$outer};
1310  
1311 0 my ($inner_attrs_dupl_topic, $topic_attrs_no_ugr, undef)
1312 = $topic->_ptn_conj_and_disj( $topic_h_except_outer, $inner_h );
1313 confess q{ungroup(): Bad $inner arg; at least one name in that attr}
1314 . q{ list, which the invocant would be extended with when}
1315 . q{ ungrouping $topic{$outer}, duplicates an attr of the}
1316 . q{ invocant not being ungrouped.}
1317 0 ▶ if @{$inner_attrs_dupl_topic} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$inner_attrs_dupl_topic;} > 0 0 0 0
1318  
1319 0 my $topic_b = $topic->_body();
1320  
1321 0 for my $topic_t (values %{$topic_b}) {
1322 0 my $inner_r = $topic_t->{$outer};
1323 0 ▶ confess q{ungroup(): Can't ungroup $topic{$outer} because there is}
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($inner_r) and $inner_r->isa(__PACKAGE__) and $topic->_is_identical_hkeys($inner_h, $inner_r->_heading) 0 0 0
Condition0%0/6
builtin::blessed($inner_r) and $inner_r->isa(__PACKAGE__) and $topic->_is_identical_hkeys($inner_h, $inner_r->_heading)
!ll&&!rl&&r
000
builtin::blessed($inner_r) and $inner_r->isa(__PACKAGE__)
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($inner_r) and $inner_r->isa(__PACKAGE__) and $topic->_is_identical_hkeys($inner_h, $inner_r->_heading)
builtin::blessed($inner_r) $inner_r->isa(__PACKAGE__) $topic->_is_identical_hkeys($inner_h, $inner_r->_heading)
Truth table0%0/4
A and B and C
A= builtin::blessed($inner_r)B= $inner_r->isa(__PACKAGE__)C= $topic->_is_identical_hkeys($inner_h, $inner_r->_heading)
ABCresult
0XX0
10X0
1100
1111
1324 . q{ not a same-heading relation val for the $outer attr}
1325 . q{ of every tuple of $topic whose head matches $inner.}
1326 if !blessed $inner_r or !$inner_r->isa( __PACKAGE__ )
1327 or !$topic->_is_identical_hkeys(
1328 $inner_h, $inner_r->_heading() );
1329 }
1330  
1331 0 ▶ if ($topic->degree() == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->degree == 1) 0 0 0
1332 # Ungroup of a unary relation is the N-adic union of its sole
1333 # attribute's value across all tuples.
1334 return $topic->_new( $inner )
1335 0 ->_union( [CORE::map { $_->{$outer} } values %{$topic_b}] );
1336 }
1337  
1338 # If we get here, the input relation is not unary.
1339  
1340 0 my $result = $topic->_new();
1341  
1342 0 $result->_heading( {%{$topic_h_except_outer}, %{$inner_h}} );
1343  
1344 my $topic_tuples_w_nonemp_inn
1345 0 = [grep { !$_->{$outer}->is_empty() } values %{$topic_b}];
1346  
1347 0 ▶ if (@{$topic_tuples_w_nonemp_inn} == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$topic_tuples_w_nonemp_inn;} == 0) { } 0 0 0
elsif (@{$inner;} == 0) { } 0 0 0
1348 # An empty post-basic-filtering $topic means an empty result.
1349 # So result body is already correct.
1350 }
1351 0 elsif (@{$inner} == 0) {
1352 # Ungroup of $outer adds zero attrs to $topic.
1353 # So this is a simple proj of post-basic-filt $topic excis $outer.
1354 0 my $result_b = $result->_body();
1355 0 for my $topic_t (@{$topic_tuples_w_nonemp_inn}) {
1356 my $result_t = {
1357 0 CORE::map { ($_ => $topic_t->{$_}) } @{$topic_attrs_no_ugr}
1358 };
1359 0 $result_b->{refaddr $result_t} = $result_t;
1360 }
1361 }
1362 else {
1363 # Result has at least 1 attr from $outer, at least 1 not from it.
1364 0 my $result_b = $result->_body();
1365 0 for my $topic_t (@{$topic_tuples_w_nonemp_inn}) {
1366 0 my $no_ugr_t = {CORE::map { ($_ => $topic_t->{$_}) }
1367 0 @{$topic_attrs_no_ugr}};
1368 0 my $inner_r = $topic_t->{$outer};
1369 0 for my $inner_t (values %{$inner_r->_body()}) {
1370 0 my $result_t = {%{$inner_t}, %{$no_ugr_t}};
1371 0 $result_b->{refaddr $result_t} = $result_t;
1372 }
1373 }
1374 }
1375  
1376 0 return $result;
1377 }
1378  
1379 ###########################################################################
1380  
1381 0 ▶sub tclose {
Subroutine tclose: not called CC=3 SCAR=24.8
Pod undocumented
1382 0 my ($topic) = @_;
1383  
1384 0 ▶ confess q{tclose(): This method may only be invoked on a}
Branch: 1 branch
BranchTrueFalseTotal
if $topic->degree != 2 0 0 0
1385 . q{ Set::Relation object with exactly 2 (same-typed) attrs.}
1386 if $topic->degree() != 2;
1387  
1388 0 ▶ if ($topic->cardinality() < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->cardinality < 2) 0 0 0
1389 # Can't create paths of 2+ arcs when not more than 1 arc exists.
1390 0 return $topic;
1391 }
1392  
1393 # If we get here, there are at least 2 arcs, so there is a chance they
1394 # may connect into longer paths.
1395  
1396 0 my ($atnm1, $atnm2) = sort (CORE::keys %{$topic->_heading()});
1397  
1398 0 return $topic->_rename( { 'x' => $atnm1, 'y' => $atnm2 } )
1399 ->_tclose_of_xy()
1400 ->_rename( { $atnm1 => 'x', $atnm2 => 'y' } );
1401 }
1402  
1403 # TODO: Reimplement tclose to do all the work internally rather
1404 # than farming out to rename/join/projection/union/etc; this should make
1405 # performance an order of magnitude better and without being complicated.
1406  
1407 0 ▶sub _tclose_of_xy {
Subroutine _tclose_of_xy: not called CC=4 SCAR=30.0
1408 0 my ($xy) = @_;
1409  
1410 0 ▶ if (!$xy->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xy->_is_known_dup_free) 0 0 0
1411 0 $xy->_dup_free_want_index_over_all_attrs();
1412 }
1413  
1414 0 my $xyz = $xy->_rename( { 'y' => 'x', 'z' => 'y' } )
1415 ->_regular_join( $xy, ['y'], ['z'], ['x'] );
1416  
1417 0 ▶ if ($xyz->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xyz->is_empty) 0 0 0
1418 # No paths of xy connect to any other paths of xy.
1419 0 return $xy;
1420 }
1421  
1422 # If we get here, then at least one pair of paths in xy can connect
1423 # to form a longer path.
1424  
1425 0 my $ttt = $xyz->_projection( ['x', 'z'] )
1426 ->_rename( { 'y' => 'z' } )
1427 ->_union( [$xy] );
1428  
1429 0 ▶ if ($ttt->_is_identical( $xy )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ttt->_is_identical($xy)) 0 0 0
1430 # All the longer paths resulting from conn were already in xy.
1431 0 return $xy;
1432 }
1433  
1434 # If we get here, then at least one longer path produced above was not
1435 # already in xy and was added; so now we need to check if any
1436 # yet-longer paths can be made from the just-produced.
1437  
1438 0 return $ttt->_tclose_of_xy();
1439 }
1440  
1441 ###########################################################################
1442  
1443 16 ▶sub restriction {
Subroutine restriction: called CC=7 SCAR=20.2
Pod undocumented
1444 16 my ($topic, $func, $allow_dup_tuples) = @_;
1445  
1446 16 $topic->_assert_valid_func_arg( 'restriction', '$func', $func );
1447  
1448 16 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 16 16
1449 0 return $topic;
1450 }
1451  
1452 16 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 16 16
Condition33%1/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
0160
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table33%1/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
1453 0 $topic->_dup_free_want_index_over_all_attrs();
1454 }
1455  
1456 16 my $result = $topic->empty();
1457  
1458 16 my $topic_b = $topic->_body();
1459 16 my $result_b = $result->_body();
1460  
1461 16 for my $topic_t_refaddr (CORE::keys %{$topic_b}) {
1462 74 my $topic_t = $topic_b->{$topic_t_refaddr};
1463 74 my $is_matched;
1464 {
1465 74 local $_ = $topic->_export_nfmt_tuple( $topic_t );
1466 74 $is_matched = $func->();
1467 }
1468 74 ▶ if ($is_matched) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_matched) 16 58 74
1469 16 $result_b->{$topic_t_refaddr} = $topic_t;
1470 }
1471 }
1472  
1473 16 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 16 0 16
1474 16 $result->_is_known_dup_free( 1 );
1475 }
1476  
1477 16 return $result;
1478 }
1479  
1480 0 ▶sub restr_and_cmpl {
Subroutine restr_and_cmpl: not called CC=1 SCAR=6.9
Pod undocumented
1481 0 my ($topic, $func, $allow_dup_tuples) = @_;
1482 0 $topic->_assert_valid_func_arg( 'restr_and_cmpl', '$func', $func );
1483 0 return $topic->_restr_and_cmpl( $func, $allow_dup_tuples );
1484 }
1485  
1486 0 ▶sub _restr_and_cmpl {
Subroutine _restr_and_cmpl: not called CC=7 SCAR=40.3
1487 0 my ($topic, $func, $allow_dup_tuples) = @_;
1488  
1489 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
1490 0 return [$topic, $topic];
1491 }
1492  
1493 0 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
1494 0 $topic->_dup_free_want_index_over_all_attrs();
1495 }
1496  
1497 0 my $pass_result = $topic->empty();
1498 0 my $fail_result = $topic->empty();
1499  
1500 0 my $topic_b = $topic->_body();
1501 0 my $pass_result_b = $pass_result->_body();
1502 0 my $fail_result_b = $fail_result->_body();
1503  
1504 0 for my $topic_t_refaddr (CORE::keys %{$topic_b}) {
1505 0 my $topic_t = $topic_b->{$topic_t_refaddr};
1506 0 my $is_matched;
1507 {
1508 0 local $_ = $topic->_export_nfmt_tuple( $topic_t );
1509 0 $is_matched = $func->();
1510 }
1511 0 ▶ if ($is_matched) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_matched) { } 0 0 0
1512 0 $pass_result_b->{$topic_t_refaddr} = $topic_t;
1513 }
1514 else {
1515 0 $fail_result_b->{$topic_t_refaddr} = $topic_t;
1516 }
1517 }
1518  
1519 0 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 0 0 0
1520 0 $pass_result->_is_known_dup_free( 1 );
1521 0 $fail_result->_is_known_dup_free( 1 );
1522 }
1523  
1524 0 return [$pass_result, $fail_result];
1525 }
1526  
1527 0 ▶sub cmpl_restr {
Subroutine cmpl_restr: not called CC=7 SCAR=40.3
Pod undocumented
1528 0 my ($topic, $func, $allow_dup_tuples) = @_;
1529  
1530 0 $topic->_assert_valid_func_arg( 'cmpl_restr', '$func', $func );
1531  
1532 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
1533 0 return $topic;
1534 }
1535  
1536 0 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
1537 0 $topic->_dup_free_want_index_over_all_attrs();
1538 }
1539  
1540 0 my $result = $topic->empty();
1541  
1542 0 my $topic_b = $topic->_body();
1543 0 my $result_b = $result->_body();
1544  
1545 0 for my $topic_t_refaddr (CORE::keys %{$topic_b}) {
1546 0 my $topic_t = $topic_b->{$topic_t_refaddr};
1547 0 my $is_matched;
1548 {
1549 0 local $_ = $topic->_export_nfmt_tuple( $topic_t );
1550 0 $is_matched = $func->();
1551 }
1552 0 ▶ if (!$is_matched) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_matched) 0 0 0
1553 0 $result_b->{$topic_t_refaddr} = $topic_t;
1554 }
1555 }
1556  
1557 0 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 0 0 0
1558 0 $result->_is_known_dup_free( 1 );
1559 }
1560  
1561 0 return $result;
1562 }
1563  
1564 ###########################################################################
1565  
1566 0 ▶sub classification {
Subroutine classification: not called CC=8 SCAR=42.8
Pod undocumented
1567 0 my ($topic, $func, $class_attr_name, $group_attr_name,
1568 $allow_dup_tuples) = @_;
1569  
1570 0 $topic->_assert_valid_func_arg( 'classification', '$func', $func );
1571 0 $topic->_assert_valid_atnm_arg(
1572 'classification', '$class_attr_name', $class_attr_name );
1573 0 $topic->_assert_valid_atnm_arg(
1574 'classification', '$group_attr_name', $group_attr_name );
1575  
1576 0 my $result = $topic->_new();
1577  
1578 0 $result->_heading(
1579 {$class_attr_name => undef, $group_attr_name => undef} );
1580  
1581 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
1582 # An empty $topic means an empty result.
1583 # So result body is already correct.
1584 0 return $result;
1585 }
1586  
1587 0 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
1588 0 $topic->_dup_free_want_index_over_all_attrs();
1589 }
1590  
1591 0 my $topic_h = $topic->_heading();
1592 0 my $topic_b = $topic->_body();
1593  
1594 0 my $tuples_per_class = {};
1595  
1596 0 for my $topic_t (values %{$topic_b}) {
1597 0 my $class;
1598 {
1599 0 local $_ = $topic->_export_nfmt_tuple( $topic_t );
1600 0 $class = $func->();
1601 }
1602 0 my $class_ident_str = $topic->_ident_str( $class );
1603 0 ▶ if (!exists $tuples_per_class->{$class_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $tuples_per_class->{$class_ident_str}) 0 0 0
1604 0 $tuples_per_class->{$class_ident_str} = [$class, []];
1605 }
1606 0 push @{$tuples_per_class->{$class_ident_str}->[1]}, $topic_t;
1607 }
1608  
1609 0 my $result_b = $result->_body();
1610 0 for my $class_ident_str (CORE::keys %{$tuples_per_class}) {
1611 my ($class, $tuples_in_class)
1612 0 = @{$tuples_per_class->{$class_ident_str}};
1613  
1614 0 my $inner_r = $topic->_new();
1615 0 $inner_r->_heading( $topic_h );
1616 $inner_r->_body(
1617 0 {CORE::map { (refaddr $_ => $_) } @{$tuples_in_class}} );
1618  
1619 0 my $result_t = {
1620 $class_attr_name => $class,
1621 $group_attr_name => $inner_r,
1622 };
1623 0 $result_b->{refaddr $result_t} = $result_t;
1624 }
1625  
1626 0 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 0 0 0
1627 0 $result->_is_known_dup_free( 1 );
1628 }
1629  
1630 0 return $result;
1631 }
1632  
1633 ###########################################################################
1634  
1635 0 ▶sub extension {
Subroutine extension: not called CC=2 SCAR=17.9
Pod undocumented
1636 0 my ($topic, $attr_names, $func, $allow_dup_tuples) = @_;
1637  
1638 0 (my $exten_h, $attr_names)
1639 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1640 'extension', '$attr_names', $attr_names );
1641 0 $topic->_assert_valid_func_arg( 'extension', '$func', $func );
1642  
1643 0 my ($both, undef, undef)
1644 = $topic->_ptn_conj_and_disj( $topic->_heading(), $exten_h );
1645 confess q{extension(): Bad $attr_names arg; that attr list}
1646 . q{ isn't disjoint with the invocant's heading.}
1647 0 ▶ if @{$both} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$both;} > 0 0 0 0
1648  
1649 0 return $topic->_extension(
1650 $attr_names, $func, $exten_h, $allow_dup_tuples );
1651 }
1652  
1653 0 ▶sub _extension {
Subroutine _extension: not called CC=6 SCAR=37.4
1654 0 my ($topic, $attr_names, $func, $exten_h, $allow_dup_tuples) = @_;
1655  
1656 0 ▶ if (@{$attr_names} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$attr_names;} == 0) 0 0 0
1657 # Extension of input by zero attrs yields the input.
1658 0 return $topic;
1659 }
1660  
1661 0 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
1662 0 $topic->_dup_free_want_index_over_all_attrs();
1663 }
1664  
1665 0 my $result = $topic->_new();
1666  
1667 0 $result->_heading( {%{$topic->_heading()}, %{$exten_h}} );
1668  
1669 0 my $result_b = $result->_body();
1670  
1671 0 for my $topic_t (values %{$topic->_body()}) {
1672 0 my $exten_t;
1673 {
1674 0 local $_ = $topic->_export_nfmt_tuple( $topic_t );
1675 0 $exten_t = $func->();
1676 }
1677 $topic->_assert_valid_tuple_result_of_func_arg(
1678 0 'extension', '$func', '$attr_names', $exten_t, $exten_h );
1679 0 $exten_t = $topic->_import_nfmt_tuple( $exten_t );
1680 0 my $result_t = {%{$topic_t}, %{$exten_t}};
1681 0 $result_b->{refaddr $result_t} = $result_t;
1682 }
1683  
1684 0 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 0 0 0
1685 0 $result->_is_known_dup_free( 1 );
1686 }
1687  
1688 0 return $result;
1689 }
1690  
1691 ###########################################################################
1692  
1693 0 ▶sub static_exten {
Subroutine static_exten: not called CC=4 SCAR=30.0
Pod undocumented
1694 0 my ($topic, $attrs) = @_;
1695  
1696 0 ▶ confess q{static_exten(): Bad $attrs arg; it isn't a hash-ref.}
Branch: 1 branch
BranchTrueFalseTotal
if ref $attrs ne "HASH" 0 0 0
1697 if ref $attrs ne 'HASH';
1698  
1699 0 my ($both, undef, undef)
1700 = $topic->_ptn_conj_and_disj( $topic->_heading(), $attrs );
1701 confess q{static_exten(): Bad $attrs arg; that attr list}
1702 . q{ isn't disjoint with the invocant's heading.}
1703 0 ▶ if @{$both} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$both;} > 0 0 0 0
1704  
1705 0 ▶ confess q{static_exten(): Bad $attrs arg;}
Branch: 1 branch
BranchTrueFalseTotal
if $topic->_tuple_arg_has_circular_refs($attrs) 0 0 0
1706 . q{ it is a hash-ref, and there exist circular refs}
1707 . q{ between itself or its tuple-valued components.}
1708 if $topic->_tuple_arg_has_circular_refs( $attrs );
1709  
1710 0 return $topic->_static_exten( $attrs );
1711 }
1712  
1713 0 ▶sub _static_exten {
Subroutine _static_exten: not called CC=4 SCAR=30.0
1714 0 my ($topic, $attrs) = @_;
1715  
1716 0 ▶ if ((scalar CORE::keys %{$attrs}) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar CORE::keys %{$attrs;} == 0) 0 0 0
1717 # Extension of input by zero attrs yields the input.
1718 0 return $topic;
1719 }
1720  
1721 0 $attrs = $topic->_import_nfmt_tuple( $attrs );
1722  
1723 0 my $result = $topic->_new();
1724  
1725 0 $result->_heading( {%{$topic->_heading()},
1726 0 CORE::map { ($_ => undef) } CORE::keys %{$attrs}} );
1727  
1728 0 my $result_b = $result->_body();
1729  
1730 0 for my $topic_t (values %{$topic->_body()}) {
1731 0 my $result_t = {%{$topic_t}, %{$attrs}};
1732 0 $result_b->{refaddr $result_t} = $result_t;
1733 }
1734  
1735 0 ▶ if ($topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free) 0 0 0
1736 0 $result->_is_known_dup_free( 1 );
1737 }
1738  
1739 0 return $result;
1740 }
1741  
1742 ###########################################################################
1743  
1744 0 ▶sub map {
Subroutine map: not called CC=6 SCAR=37.4
Pod undocumented
1745 0 my ($topic, $result_attr_names, $func, $allow_dup_tuples) = @_;
1746  
1747 0 (my $result_h, $result_attr_names)
1748 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1749 'map', '$result_attr_names', $result_attr_names );
1750 0 $topic->_assert_valid_func_arg( 'map', '$func', $func );
1751  
1752 0 ▶ if (@{$result_attr_names} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$result_attr_names;} == 0) 0 0 0
1753 # Map to zero attrs yields identity relation zero or one.
1754 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) { } 0 0 0
1755 0 return $topic->_new();
1756 }
1757 else {
1758 0 return $topic->_new( [ {} ] );
1759 }
1760 }
1761  
1762 0 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
1763 0 $topic->_dup_free_want_index_over_all_attrs();
1764 }
1765  
1766 0 my $result = $topic->_new();
1767  
1768 0 $result->_heading( $result_h );
1769  
1770 0 my $result_b = $result->_body();
1771  
1772 0 for my $topic_t (values %{$topic->_body()}) {
1773 0 my $result_t;
1774 {
1775 0 local $_ = $topic->_export_nfmt_tuple( $topic_t );
1776 0 $result_t = $func->();
1777 }
1778 $topic->_assert_valid_tuple_result_of_func_arg(
1779 0 'map', '$func', '$result_attr_names', $result_t, $result_h );
1780 0 $result_t = $topic->_import_nfmt_tuple( $result_t );
1781 0 $result_b->{refaddr $result_t} = $result_t;
1782 }
1783  
1784 0 return $result;
1785 }
1786  
1787 ###########################################################################
1788  
1789 0 ▶sub summary {
Subroutine summary: not called CC=8 SCAR=42.8
Pod undocumented
1790 0 my ($topic, $group_per, $summ_attr_names, $summ_func,
1791 $allow_dup_tuples) = @_;
1792  
1793 0 (my $group_per_h, $group_per)
1794 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1795 'summary', '$group_per', $group_per );
1796 0 (my $exten_h, $summ_attr_names)
1797 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1798 'summary', '$summ_attr_names', $summ_attr_names );
1799 0 $topic->_assert_valid_func_arg( 'summary', '$summ_func', $summ_func );
1800  
1801 0 my $topic_h = $topic->_heading();
1802  
1803 confess q{summary(): Bad $group_per arg; that attr list}
1804 . q{ isn't a subset of the invocant's heading.}
1805 0 ▶ if notall { exists $topic_h->{$_} } @{$group_per};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { exists $topic_h->{$_}; } , @{$group_per;}) 0 0 0
1806  
1807 confess q{summary(): Bad $summ_attr_names arg; one or more of those}
1808 . q{ names for new summary attrs to add to the invocant }
1809 . q{ duplicates an attr of the invocant not being grouped.}
1810 0 ▶ if any { exists $group_per_h->{$_} } @{$summ_attr_names};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { exists $group_per_h->{$_}; } , @{$summ_attr_names;}) 0 0 0
1811  
1812 0 my $inner = [grep { !$group_per_h->{$_} } CORE::keys %{$topic_h}];
1813 0 my $inner_h = {CORE::map { $_ => undef } @{$inner}};
1814  
1815 0 my (undef, $topic_attrs_no_gr, undef)
1816 = $topic->_ptn_conj_and_disj( $topic_h, $inner_h );
1817  
1818 0 my $result = $topic->_new();
1819  
1820 0 $result->_heading( {%{$group_per_h}, %{$exten_h}} );
1821  
1822 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
1823 # An empty $topic means an empty result.
1824 0 return $result;
1825 }
1826  
1827 0 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
1828 0 $topic->_dup_free_want_index_over_all_attrs();
1829 }
1830  
1831 # Note: We skipped a number of shortcuts that _group() has for
1832 # brevity, leaving just the general case; they might come back later.
1833  
1834 0 my $result_b = $result->_body();
1835 0 my $topic_index = $topic->_want_index( $topic_attrs_no_gr );
1836 0 for my $matched_topic_b (values %{$topic_index}) {
1837  
1838 0 my $inner_r = $topic->_new();
1839 0 $inner_r->_heading( $inner_h );
1840 0 my $inner_b = $inner_r->_body();
1841 0 for my $topic_t (values %{$matched_topic_b}) {
1842 0 my $inner_t = {CORE::map { ($_ => $topic_t->{$_}) } @{$inner}};
1843 0 $inner_b->{refaddr $inner_t} = $inner_t;
1844 }
1845  
1846 0 my $any_mtpt = (values %{$matched_topic_b})[0];
1847 0 my $group_per_t = {CORE::map { ($_ => $any_mtpt->{$_}) }
1848 0 @{$topic_attrs_no_gr}};
1849  
1850 0 my $exten_t;
1851 {
1852 0 local $_ = {
1853 'summarize' => $inner_r,
1854 'per' => $topic->_export_nfmt_tuple( $group_per_t ),
1855 };
1856 0 $exten_t = $summ_func->();
1857 }
1858 0 $topic->_assert_valid_tuple_result_of_func_arg( 'summary',
1859 '$summ_func', '$summ_attr_names', $exten_t, $exten_h );
1860 0 $exten_t = $topic->_import_nfmt_tuple( $exten_t );
1861  
1862 0 my $result_t = {%{$group_per_t}, %{$exten_t}};
1863 0 $result_b->{refaddr $result_t} = $result_t;
1864 }
1865  
1866 0 return $result;
1867 }
1868  
1869 ###########################################################################
1870  
1871 0 ▶sub cardinality_per_group {
Subroutine cardinality_per_group: not called CC=7 SCAR=40.3
Pod undocumented
1872 0 my ($topic, $count_attr_name, $group_per, $allow_dup_tuples) = @_;
1873  
1874 0 $topic->_assert_valid_atnm_arg(
1875 'cardinality_per_group', '$count_attr_name', $count_attr_name );
1876 0 (my $group_per_h, $group_per)
1877 = $topic->_atnms_hr_from_assert_valid_atnms_arg(
1878 'cardinality_per_group', '$group_per', $group_per );
1879  
1880 0 my $topic_h = $topic->_heading();
1881  
1882 confess q{cardinality_per_group(): Bad $group_per arg;}
1883 . q{ that attr list isn't a subset of the invocant's heading.}
1884 0 ▶ if notall { exists $topic_h->{$_} } @{$group_per};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { exists $topic_h->{$_}; } , @{$group_per;}) 0 0 0
1885  
1886 confess q{cardinality_per_group(): Bad $count_attr_name arg;}
1887 . q{ that name for a new attr to add to the invocant}
1888 . q{ duplicates an attr of the invocant not being grouped.}
1889 0 ▶ if exists $group_per_h->{$count_attr_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $group_per_h->{$count_attr_name} 0 0 0
1890  
1891 0 my $inner = [grep { !$group_per_h->{$_} } CORE::keys %{$topic_h}];
1892 0 my $inner_h = {CORE::map { $_ => undef } @{$inner}};
1893  
1894 0 my (undef, $topic_attrs_no_gr, undef)
1895 = $topic->_ptn_conj_and_disj( $topic_h, $inner_h );
1896  
1897 0 my $result = $topic->_new();
1898  
1899 0 $result->_heading( {%{$group_per_h}, $count_attr_name => undef} );
1900  
1901 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
1902 # An empty $topic means an empty result.
1903 0 return $result;
1904 }
1905  
1906 0 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
1907 0 $topic->_dup_free_want_index_over_all_attrs();
1908 }
1909  
1910 0 my $result_b = $result->_body();
1911 0 my $topic_index = $topic->_want_index( $topic_attrs_no_gr );
1912 0 for my $matched_topic_b (values %{$topic_index}) {
1913 0 my $count = scalar CORE::keys %{$matched_topic_b};
1914 0 my $any_mtpt = (values %{$matched_topic_b})[0];
1915 0 my $group_per_t = {CORE::map { ($_ => $any_mtpt->{$_}) }
1916 0 @{$topic_attrs_no_gr}};
1917 0 my $result_t = {%{$group_per_t}, $count_attr_name => $count};
1918 0 $result_b->{refaddr $result_t} = $result_t;
1919 }
1920  
1921 0 return $result;
1922 }
1923  
1924 0 ▶sub count_per_group {
Subroutine count_per_group: not called CC=1 SCAR=6.9
Pod undocumented
1925 0 my ($self, @args) = @_;
1926 0 return $self->cardinality_per_group( @args );
1927 }
1928  
1929 ###########################################################################
1930  
1931 2 ▶sub _atnms_hr_from_assert_valid_atnms_arg {
Subroutine _atnms_hr_from_assert_valid_atnms_arg: called CC=6 SCAR=18.3
1932 2 my ($self, $rtn_nm, $arg_nm, $atnms) = @_;
1933  
1934 2 ▶ if (defined $atnms and !ref $atnms) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $atnms and not ref $atnms) 1 1 2
Condition66%2/3
defined $atnms and not ref $atnms
!ll&&!rl&&r
011
MC/DC50%1/2
defined $atnms and not ref $atnms
defined $atnms not ref $atnms
Truth table66%2/3
A and not(B)
A= defined $atnmsB= not ref $atnms
ABresult
0X0
100
111
1935 1 $atnms = [$atnms];
1936 }
1937 2 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg;}
Branch: 1 branch
BranchTrueFalseTotal
if ref $atnms ne "ARRAY" 0 2 2
1938 . q{ it must be an array-ref or a defined non-ref.}
1939 if ref $atnms ne 'ARRAY';
1940 confess qq{$rtn_nm(): Bad $arg_nm arg;}
1941 . q{ it should be just be a list of attr names,}
1942 . q{ but at least one name is undefined or is a ref.}
1943 2 ▶ if notall { defined $_ and !ref $_ } @{$atnms};
Subroutine __ANON__: called CC=2 SCAR=7.4
Branch: 2 branches
BranchTrueFalseTotal
if &notall(sub { defined $_ and not ref $_; } , @{$atnms;}) 0 2 2
defined $_ and not ref $_ 4 0 4
1944 confess qq{$rtn_nm(): Bad $arg_nm arg;}
1945 . q{ it specifies a list of}
1946 . q{ attr names with at least one duplicated name.}
1947 2 ▶ if (uniqstr @{$atnms}) != @{$atnms};
Branch: 1 branch
BranchTrueFalseTotal
if &uniqstr(@{$atnms;}) != @{$atnms;} 0 2 2
1948  
1949 2 my $heading = {CORE::map { ($_ => undef) } @{$atnms}};
1950 2 return ($heading, $atnms);
1951 }
1952  
1953 5 ▶sub _assert_valid_atnm_arg {
Subroutine _assert_valid_atnm_arg: called CC=3 SCAR=13.1
1954 5 my ($self, $rtn_nm, $arg_nm, $atnm) = @_;
1955 5 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg;}
Branch: 1 branch
BranchTrueFalseTotal
if not defined $atnm or ref $atnm 0 5 5
Condition33%1/3
not defined $atnm or ref $atnm
l!l&&r!l&&!r
005
MC/DC0%0/2
not defined $atnm or ref $atnm
not defined $atnm ref $atnm
Truth table33%1/3
not(A) or B
A= not defined $atnmB= ref $atnm
ABresult
1X1
011
000
1956 . q{ it should be just be an attr name,}
1957 . q{ but it is undefined or is a ref.}
1958 if !defined $atnm or ref $atnm;
1959 }
1960  
1961 0 ▶sub _assert_valid_nnint_arg {
Subroutine _assert_valid_nnint_arg: not called CC=4 SCAR=30.0
1962 0 my ($self, $rtn_nm, $arg_nm, $atnm) = @_;
1963 0 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg;}
Branch: 1 branch
BranchTrueFalseTotal
if not defined $atnm or ref $atnm or not $atnm =~ /^[0-9]+$/ 0 0 0
Condition0%0/6
not defined $atnm or ref $atnm or not $atnm =~ /^[0-9]+$/
l!l&&r!l&&!r
000
not defined $atnm or ref $atnm
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $atnm or ref $atnm or not $atnm =~ /^[0-9]+$/
not defined $atnm ref $atnm not $atnm =~ /^[0-9]+$/
Truth table0%0/4
not(A) or B or not(C)
A= not defined $atnmB= ref $atnmC= not $atnm =~ /^[0-9]+$/
ABCresult
1XX1
01X1
0011
0000
1964 . q{ it should be just be a non-negative integer,}
1965 . q{ but it is undefined or is a ref or is some other scalar.}
1966 if !defined $atnm or ref $atnm or not $atnm =~ /^[0-9]+$/;
1967 }
1968  
1969 16 ▶sub _assert_valid_func_arg {
Subroutine _assert_valid_func_arg: called CC=2 SCAR=7.2
1970 16 my ($self, $rtn_nm, $arg_nm, $func) = @_;
1971 16 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg;}
Branch: 1 branch
BranchTrueFalseTotal
if ref $func ne "CODE" 0 16 16
1972 . q{ it must be a Perl subroutine reference.}
1973 if ref $func ne 'CODE';
1974 }
1975  
1976 0 ▶sub _assert_valid_tuple_result_of_func_arg {
Subroutine _assert_valid_tuple_result_of_func_arg: not called CC=4 SCAR=30.0
1977 0 my ($self, $rtn_nm, $arg_nm_func, $arg_nm_attrs, $result_t, $heading)
1978 = @_;
1979 0 ▶ confess qq{$rtn_nm(): Bad $arg_nm_func arg;}
Branch: 1 branch
BranchTrueFalseTotal
if ref $result_t ne "HASH" or not $self->_is_identical_hkeys($heading, $result_t) 0 0 0
Condition0%0/3
ref $result_t ne "HASH" or not $self->_is_identical_hkeys($heading, $result_t)
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $result_t ne "HASH" or not $self->_is_identical_hkeys($heading, $result_t)
ref $result_t ne "HASH" not $self->_is_identical_hkeys($heading, $result_t)
Truth table0%0/3
A or not(B)
A= ref $result_t ne "HASH"B= not $self->_is_identical_hkeys($heading, $result_t)
ABresult
1X1
011
000
1980 . q{ at least one result of executing that Perl subroutine}
1981 . q{ reference was not a hash-ref or it didn't have the same}
1982 . qq{ set of hkeys as specified by the $arg_nm_attrs arg.}
1983 if ref $result_t ne 'HASH'
1984 or !$self->_is_identical_hkeys( $heading, $result_t );
1985 0 ▶ confess qq{$rtn_nm(): Bad $arg_nm_func arg;}
Branch: 1 branch
BranchTrueFalseTotal
if $self->_tuple_arg_has_circular_refs($result_t) 0 0 0
1986 . q{ at least one result of executing that Perl subroutine}
1987 . q{ reference was a hash-ref, and there exist circular refs}
1988 . q{ between itself or its tuple-valued components.}
1989 if $self->_tuple_arg_has_circular_refs( $result_t );
1990 }
1991  
1992 0 ▶sub _normalize_same_heading_relation_arg {
Subroutine _normalize_same_heading_relation_arg: not called CC=8 SCAR=42.8
1993 0 my ($self, $rtn_nm, $arg_nm, $other) = @_;
1994 0 ▶ if (blessed $other and $other->can( 'does' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)) 0 0 0
Condition0%0/9
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)
!ll&&!rl&&r
000
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation")
!ll&&!rl&&r
000
builtin::blessed($other) and $other->can("does")
!ll&&!rl&&r
000
MC/DC0%0/4
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)
builtin::blessed($other) $other->can("does") $other->does("Set::Relation") not $other->isa(__PACKAGE__)
Truth table0%0/5
A and B and C and not(D)
A= builtin::blessed($other)B= $other->can("does")C= $other->does("Set::Relation")D= not $other->isa(__PACKAGE__)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1995 and $other->does( 'Set::Relation' )
1996 and !$other->isa( __PACKAGE__ )) {
1997 0 $other = $self->_new( $other );
1998 }
1999 0 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg; it isn't a Set::Relation}
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa(__PACKAGE__) and $self->_is_identical_hkeys($self->_heading, $other->_heading) 0 0 0
Condition0%0/6
builtin::blessed($other) and $other->isa(__PACKAGE__) and $self->_is_identical_hkeys($self->_heading, $other->_heading)
!ll&&!rl&&r
000
builtin::blessed($other) and $other->isa(__PACKAGE__)
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($other) and $other->isa(__PACKAGE__) and $self->_is_identical_hkeys($self->_heading, $other->_heading)
builtin::blessed($other) $other->isa(__PACKAGE__) $self->_is_identical_hkeys($self->_heading, $other->_heading)
Truth table0%0/4
A and B and C
A= builtin::blessed($other)B= $other->isa(__PACKAGE__)C= $self->_is_identical_hkeys($self->_heading, $other->_heading)
ABCresult
0XX0
10X0
1100
1111
2000 . q{ object, or it doesn't have exactly the}
2001 . q{ same set of attr names as the invocant.}
2002 if !blessed $other or !$other->isa( __PACKAGE__ )
2003 or !$self->_is_identical_hkeys(
2004 $self->_heading(), $other->_heading() );
2005 0 return $other;
2006 }
2007  
2008 22 ▶sub _normalize_relation_arg {
Subroutine _normalize_relation_arg: called CC=7 SCAR=26.4
2009 22 my ($self, $rtn_nm, $arg_nm, $other) = @_;
2010 22 ▶ if (blessed $other and $other->can( 'does' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)) 0 22 22
Condition33%3/9
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)
!ll&&!rl&&r
0220
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation")
!ll&&!rl&&r
0022
builtin::blessed($other) and $other->can("does")
!ll&&!rl&&r
0022
MC/DC0%0/4
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)
builtin::blessed($other) $other->can("does") $other->does("Set::Relation") not $other->isa(__PACKAGE__)
Truth table20%1/5
A and B and C and not(D)
A= builtin::blessed($other)B= $other->can("does")C= $other->does("Set::Relation")D= not $other->isa(__PACKAGE__)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2011 and $other->does( 'Set::Relation' )
2012 and !$other->isa( __PACKAGE__ )) {
2013 0 $other = $self->_new( $other );
2014 }
2015 22 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg;}
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa(__PACKAGE__) 0 22 22
Condition33%1/3
builtin::blessed($other) and $other->isa(__PACKAGE__)
!ll&&!rl&&r
0022
MC/DC0%0/2
builtin::blessed($other) and $other->isa(__PACKAGE__)
builtin::blessed($other) $other->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($other)B= $other->isa(__PACKAGE__)
ABresult
0X0
100
111
2016 . q{ it isn't a Set::Relation object.}
2017 if !blessed $other or !$other->isa( __PACKAGE__ );
2018 22 return $other;
2019 }
2020  
2021 ###########################################################################
2022  
2023 22 ▶sub is_identical {
Subroutine is_identical: called CC=1 SCAR=0.0
Pod undocumented
2024 22 my ($topic, $other) = @_;
2025 22 $other = $topic->_normalize_relation_arg(
2026 'is_identical', '$other', $other );
2027 22 return $topic->_is_identical( $other );
2028 }
2029  
2030 22 ▶sub _is_identical {
Subroutine _is_identical: called CC=4 SCAR=14.1
2031 22 my ($topic, $other) = @_;
2032 22 ▶ return ($topic->degree() == $other->degree()
Condition77%7/9
$topic->degree == $other->degree && $topic->_is_identical_hkeys($topic->_heading, $other->_heading) && $topic->cardinality == $other->cardinality && $topic->_is_identical_hkeys($topic->_dup_free_want_index_over_all_attrs, $other->_dup_free_want_index_over_all_attrs)
!ll&&!rl&&r
6016
$topic->degree == $other->degree and $topic->_is_identical_hkeys($topic->_heading, $other->_heading) and $topic->cardinality == $other->cardinality
!ll&&!rl&&r
5116
$topic->degree == $other->degree and $topic->_is_identical_hkeys($topic->_heading, $other->_heading)
!ll&&!rl&&r
5017
MC/DC50%2/4
$topic->degree == $other->degree && $topic->_is_identical_hkeys($topic->_heading, $other->_heading) && $topic->cardinality == $other->cardinality && $topic->_is_identical_hkeys($topic->_dup_free_want_index_over_all_attrs, $other->_dup_free_want_index_over_all_attrs)
$topic->degree == $other->degree $topic->_is_identical_hkeys($topic->_heading, $other->_heading) $topic->cardinality == $other->cardinality $topic->_is_identical_hkeys($topic->_dup_free_want_index_over_all_attrs, $other->_dup_free_want_index_over_all_attrs)
Truth table60%3/5
A and B and C && D
A= $topic->degree == $other->degreeB= $topic->_is_identical_hkeys($topic->_heading, $other->_heading)C= $topic->cardinality == $other->cardinalityD= $topic->_is_identical_hkeys($topic->_dup_free_want_index_over_all_attrs, $other->_dup_free_want_index_over_all_attrs)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2033 and $topic->_is_identical_hkeys(
2034 $topic->_heading(), $other->_heading() )
2035 and $topic->cardinality() == $other->cardinality()
2036 and $topic->_is_identical_hkeys(
2037 $topic->_dup_free_want_index_over_all_attrs(),
2038 $other->_dup_free_want_index_over_all_attrs() ));
2039 }
2040  
2041 ###########################################################################
2042  
2043 0 ▶sub is_subset {
Subroutine is_subset: not called CC=1 SCAR=6.9
Pod undocumented
2044 0 my ($topic, $other) = @_;
2045 0 $other = $topic->_normalize_same_heading_relation_arg(
2046 'is_subset', '$other', $other );
2047 0 my $other_i = $other->_dup_free_want_index_over_all_attrs();
2048 0 ▶ return all { exists $other_i->{$_} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
2049 0 CORE::keys %{$topic->_dup_free_want_index_over_all_attrs()};
2050 }
2051  
2052 0 ▶sub is_superset {
Subroutine is_superset: not called CC=1 SCAR=6.9
Pod undocumented
2053 0 my ($topic, $other) = @_;
2054 0 $other = $topic->_normalize_same_heading_relation_arg(
2055 'is_superset', '$other', $other );
2056 0 my $topic_i = $topic->_dup_free_want_index_over_all_attrs();
2057 0 ▶ return all { exists $topic_i->{$_} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
2058 0 CORE::keys %{$other->_dup_free_want_index_over_all_attrs()};
2059 }
2060  
2061 0 ▶sub is_proper_subset {
Subroutine is_proper_subset: not called CC=2 SCAR=17.9
Pod undocumented
2062 0 my ($topic, $other) = @_;
2063 0 $other = $topic->_normalize_same_heading_relation_arg(
2064 'is_proper_subset', '$other', $other );
2065 0 my $other_i = $other->_dup_free_want_index_over_all_attrs();
2066 return ($topic->cardinality() < $other->cardinality()
2067 0 ▶ and all { exists $other_i->{$_} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
2068 0 ▶ CORE::keys %{$topic->_dup_free_want_index_over_all_attrs()});
Condition0%0/3
$topic->cardinality < $other->cardinality && &all(sub { exists $other_i->{$_}; } , CORE::keys %{$topic->_dup_free_want_index_over_all_attrs;})
!ll&&!rl&&r
000
MC/DC0%0/2
$topic->cardinality < $other->cardinality && &all(sub { exists $other_i->{$_}; } , CORE::keys %{$topic->_dup_free_want_index_over_all_attrs;})
$topic->cardinality < $other->cardinality &all(sub { exists $other_i->{$_}; } , CORE::keys %{$topic->_dup_free_want_index_over_all_attrs;})
Truth table0%0/3
A && B
A= $topic->cardinality < $other->cardinalityB= &all(sub { exists $other_i->{$_}; } , CORE::keys %{$topic->_dup_free_want_index_over_all_attrs;})
ABresult
0X0
100
111
2069 }
2070  
2071 0 ▶sub is_proper_superset {
Subroutine is_proper_superset: not called CC=2 SCAR=17.9
Pod undocumented
2072 0 my ($topic, $other) = @_;
2073 0 $other = $topic->_normalize_same_heading_relation_arg(
2074 'is_proper_superset', '$other', $other );
2075 0 my $topic_i = $topic->_dup_free_want_index_over_all_attrs();
2076 return ($other->cardinality() < $topic->cardinality()
2077 0 ▶ and all { exists $topic_i->{$_} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
2078 0 ▶ CORE::keys %{$other->_dup_free_want_index_over_all_attrs()});
Condition0%0/3
$other->cardinality < $topic->cardinality && &all(sub { exists $topic_i->{$_}; } , CORE::keys %{$other->_dup_free_want_index_over_all_attrs;})
!ll&&!rl&&r
000
MC/DC0%0/2
$other->cardinality < $topic->cardinality && &all(sub { exists $topic_i->{$_}; } , CORE::keys %{$other->_dup_free_want_index_over_all_attrs;})
$other->cardinality < $topic->cardinality &all(sub { exists $topic_i->{$_}; } , CORE::keys %{$other->_dup_free_want_index_over_all_attrs;})
Truth table0%0/3
A && B
A= $other->cardinality < $topic->cardinalityB= &all(sub { exists $topic_i->{$_}; } , CORE::keys %{$other->_dup_free_want_index_over_all_attrs;})
ABresult
0X0
100
111
2079 }
2080  
2081 0 ▶sub is_disjoint {
Subroutine is_disjoint: not called CC=1 SCAR=6.9
Pod undocumented
2082 0 my ($topic, $other) = @_;
2083 0 $other = $topic->_normalize_same_heading_relation_arg(
2084 'is_disjoint', '$other', $other );
2085 0 return $topic->_intersection( [$other] )->is_empty();
2086 }
2087  
2088 ###########################################################################
2089  
2090 2 ▶sub union {
Subroutine union: called CC=1 SCAR=0.0
Pod undocumented
2091 2 my ($topic, $others) = @_;
2092 2 $others = $topic->_normalize_same_heading_relations_arg(
2093 'union', '$others', $others );
2094 2 return $topic->_union( $others );
2095 }
2096  
2097 2 ▶sub _union {
Subroutine _union: called CC=3 SCAR=11.2
2098 2 my ($topic, $others) = @_;
2099  
2100 my $inputs = [
2101 4 grep { !$_->is_empty() } # filter out identity value instances
2102 2 $topic, @{$others}];
2103  
2104 2 ▶ if (@{$inputs} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$inputs;} == 0) 0 2 2
2105 # All inputs were the identity value; so is result.
2106 0 return $topic->empty();
2107 }
2108 2 ▶ if (@{$inputs} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$inputs;} == 1) 0 2 2
2109 # Only one non-identity value input; so it is the result.
2110 0 return $inputs->[0];
2111 }
2112  
2113 # If we get here, there are at least 2 non-empty input relations.
2114  
2115 2 my $result = $topic->empty();
2116  
2117 2 $result->_body( {CORE::map { %{$_->_body()} } @{$inputs}} );
2118  
2119 2 return $result;
2120 }
2121  
2122 ###########################################################################
2123  
2124 0 ▶sub exclusion {
Subroutine exclusion: not called CC=6 SCAR=37.4
Pod undocumented
2125 # Also known as symmetric_diff().
2126 0 my ($topic, $others) = @_;
2127  
2128 0 $others = $topic->_normalize_same_heading_relations_arg(
2129 'exclusion', '$others', $others );
2130  
2131 my $inputs = [
2132 0 sort { $b->cardinality() <=> $a->cardinality() }
2133 0 grep { !$_->is_empty() } # filter out identity value instances
2134 0 $topic, @{$others}];
2135  
2136 0 ▶ if (@{$inputs} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$inputs;} == 0) 0 0 0
2137 # All inputs were the identity value; so is result.
2138 0 return $topic->empty();
2139 }
2140 0 ▶ if (@{$inputs} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$inputs;} == 1) 0 0 0
2141 # Only one non-identity value input; so it is the result.
2142 0 return $inputs->[0];
2143 }
2144  
2145 # If we get here, there are at least 2 non-empty input relations.
2146  
2147 0 my $largest = shift @{$inputs};
2148 0 my $largest_i = $largest->_dup_free_want_index_over_all_attrs();
2149  
2150 my $t_by_ident_str = {CORE::map {
2151 0 ($_ => (values %{$largest_i->{$_}})[0])
2152 0 } CORE::keys %{$largest_i}};
2153  
2154 0 for my $input (@{$inputs}) {
2155 0 my $input_i = $input->_dup_free_want_index_over_all_attrs();
2156 0 for my $tuple_ident_str (CORE::keys %{$input_i}) {
2157 0 ▶ if (exists $t_by_ident_str->{$tuple_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $t_by_ident_str->{$tuple_ident_str}) { } 0 0 0
2158 0 delete $t_by_ident_str->{$tuple_ident_str};
2159 }
2160 else {
2161 $t_by_ident_str->{$tuple_ident_str}
2162 0 = (values %{$input_i->{$tuple_ident_str}})[0];
2163 }
2164 }
2165 }
2166  
2167 0 my $result = $topic->empty();
2168  
2169 $result->_body(
2170 0 {CORE::map { (refaddr $_ => $_) } values %{$t_by_ident_str}} );
2171  
2172 0 $result->_is_known_dup_free( 1 );
2173  
2174 0 return $result;
2175 }
2176  
2177 0 ▶sub symmetric_diff {
Subroutine symmetric_diff: not called CC=1 SCAR=6.9
Pod undocumented
2178 0 my ($self, @args) = @_;
2179 0 return $self->exclusion( @args );
2180 }
2181  
2182 ###########################################################################
2183  
2184 1 ▶sub intersection {
Subroutine intersection: called CC=1 SCAR=0.0
Pod undocumented
2185 1 my ($topic, $others) = @_;
2186 1 $others = $topic->_normalize_same_heading_relations_arg(
2187 'intersection', '$others', $others );
2188 1 return $topic->_intersection( $others );
2189 }
2190  
2191 1 ▶sub _intersection {
Subroutine _intersection: called CC=6 SCAR=18.0
2192 1 my ($topic, $others) = @_;
2193  
2194 1 ▶ if (@{$others} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$others;} == 0) 0 1 1
2195 0 return $topic;
2196 }
2197  
2198 my $inputs = [
2199 1 sort { $a->cardinality( 1 ) <=> $b->cardinality( 1 ) }
2200 1 $topic, @{$others}];
2201  
2202 1 my $smallest = shift @{$inputs};
2203  
2204 1 ▶ if ($smallest->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($smallest->is_empty) 0 1 1
2205 0 return $smallest;
2206 }
2207  
2208 # If we get here, there are at least 2 non-empty input relations.
2209  
2210 1 my $result = $topic->empty();
2211  
2212 1 my $smallest_i = $smallest->_dup_free_want_index_over_all_attrs();
2213 my $larger_is = [CORE::map {
2214 1 $_->_dup_free_want_index_over_all_attrs()
2215 1 } @{$inputs}];
2216 1 my $result_b = $result->_body();
2217  
2218 TUPLE:
2219 1 for my $tuple_ident_str (CORE::keys %{$smallest_i}) {
2220 3 for my $larger_i (@{$larger_is}) {
2221 next TUPLE
2222 3 ▶ if !exists $larger_i->{$tuple_ident_str};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $larger_i->{$tuple_ident_str} 1 2 3
2223 }
2224 2 my ($tuple_refaddr, $tuple) = %{$smallest_i->{$tuple_ident_str}};
2225 2 $result_b->{$tuple_refaddr} = $tuple;
2226 }
2227  
2228 1 $result->_is_known_dup_free( 1 );
2229  
2230 1 return $result;
2231 }
2232  
2233 ###########################################################################
2234  
2235 3 ▶sub _normalize_same_heading_relations_arg {
Subroutine _normalize_same_heading_relations_arg: called CC=12 SCAR=32.3
2236 3 my ($self, $rtn_nm, $arg_nm, $others) = @_;
2237  
2238 3 my $self_h = $self->_heading();
2239  
2240 3 ▶ if (blessed $others and $others->can( 'does' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($others) and $others->can("does") and $others->does("Set::Relation")) 3 0 3
Condition33%2/6
builtin::blessed($others) and $others->can("does") and $others->does("Set::Relation")
!ll&&!rl&&r
003
builtin::blessed($others) and $others->can("does")
!ll&&!rl&&r
003
MC/DC0%0/3
builtin::blessed($others) and $others->can("does") and $others->does("Set::Relation")
builtin::blessed($others) $others->can("does") $others->does("Set::Relation")
Truth table25%1/4
A and B and C
A= builtin::blessed($others)B= $others->can("does")C= $others->does("Set::Relation")
ABCresult
0XX0
10X0
1100
1111
2241 and $others->does( 'Set::Relation' )) {
2242 3 $others = [$others];
2243 }
2244 3 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg;}
Branch: 1 branch
BranchTrueFalseTotal
if ref $others ne "ARRAY" 0 3 3
2245 . q{ it must be an array-ref or a Set::Relation object.}
2246 if ref $others ne 'ARRAY';
2247 $others = [CORE::map {
2248 3 my $other = $_;
2249 3 ▶ if (blessed $other and $other->can( 'does' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)) 0 3 3
Condition33%3/9
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)
!ll&&!rl&&r
030
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation")
!ll&&!rl&&r
003
builtin::blessed($other) and $other->can("does")
!ll&&!rl&&r
003
MC/DC0%0/4
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)
builtin::blessed($other) $other->can("does") $other->does("Set::Relation") not $other->isa(__PACKAGE__)
Truth table20%1/5
A and B and C and not(D)
A= builtin::blessed($other)B= $other->can("does")C= $other->does("Set::Relation")D= not $other->isa(__PACKAGE__)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2250 and $other->does( 'Set::Relation' )
2251 and !$other->isa( __PACKAGE__ )) {
2252 0 $other = $self->_new( $other );
2253 }
2254 3 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg elem;}
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa(__PACKAGE__) and $self->_is_identical_hkeys($self_h, $other->_heading) 0 3 3
Condition33%2/6
builtin::blessed($other) and $other->isa(__PACKAGE__) and $self->_is_identical_hkeys($self_h, $other->_heading)
!ll&&!rl&&r
003
builtin::blessed($other) and $other->isa(__PACKAGE__)
!ll&&!rl&&r
003
MC/DC0%0/3
builtin::blessed($other) and $other->isa(__PACKAGE__) and $self->_is_identical_hkeys($self_h, $other->_heading)
builtin::blessed($other) $other->isa(__PACKAGE__) $self->_is_identical_hkeys($self_h, $other->_heading)
Truth table25%1/4
A and B and C
A= builtin::blessed($other)B= $other->isa(__PACKAGE__)C= $self->_is_identical_hkeys($self_h, $other->_heading)
ABCresult
0XX0
10X0
1100
1111
2255 . q{ it isn't a Set::Relation object, or it doesn't have}
2256 . q{ exactly the same set of attr names as the invocant.}
2257 if !blessed $other or !$other->isa( __PACKAGE__ )
2258 or !$self->_is_identical_hkeys(
2259 $self_h, $other->_heading() );
2260 3 $other;
2261 3 } @{$others}];
2262  
2263 3 return $others;
2264 }
2265  
2266 2 ▶sub _normalize_relations_arg {
Subroutine _normalize_relations_arg: called CC=11 SCAR=30.8
2267 2 my ($self, $rtn_nm, $arg_nm, $others) = @_;
2268  
2269 2 ▶ if (blessed $others and $others->can( 'does' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($others) and $others->can("does") and $others->does("Set::Relation")) 2 0 2
Condition33%2/6
builtin::blessed($others) and $others->can("does") and $others->does("Set::Relation")
!ll&&!rl&&r
002
builtin::blessed($others) and $others->can("does")
!ll&&!rl&&r
002
MC/DC0%0/3
builtin::blessed($others) and $others->can("does") and $others->does("Set::Relation")
builtin::blessed($others) $others->can("does") $others->does("Set::Relation")
Truth table25%1/4
A and B and C
A= builtin::blessed($others)B= $others->can("does")C= $others->does("Set::Relation")
ABCresult
0XX0
10X0
1100
1111
2270 and $others->does( 'Set::Relation' )) {
2271 2 $others = [$others];
2272 }
2273 2 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg;}
Branch: 1 branch
BranchTrueFalseTotal
if ref $others ne "ARRAY" 0 2 2
2274 . q{ it must be an array-ref or a Set::Relation object.}
2275 if ref $others ne 'ARRAY';
2276 $others = [CORE::map {
2277 2 my $other = $_;
2278 2 ▶ if (blessed $other and $other->can( 'does' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)) 0 2 2
Condition33%3/9
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)
!ll&&!rl&&r
020
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation")
!ll&&!rl&&r
002
builtin::blessed($other) and $other->can("does")
!ll&&!rl&&r
002
MC/DC0%0/4
builtin::blessed($other) and $other->can("does") and $other->does("Set::Relation") and not $other->isa(__PACKAGE__)
builtin::blessed($other) $other->can("does") $other->does("Set::Relation") not $other->isa(__PACKAGE__)
Truth table20%1/5
A and B and C and not(D)
A= builtin::blessed($other)B= $other->can("does")C= $other->does("Set::Relation")D= not $other->isa(__PACKAGE__)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2279 and $other->does( 'Set::Relation' )
2280 and !$other->isa( __PACKAGE__ )) {
2281 0 $other = $self->_new( $other );
2282 }
2283 2 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg elem;}
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa(__PACKAGE__) 0 2 2
Condition33%1/3
builtin::blessed($other) and $other->isa(__PACKAGE__)
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($other) and $other->isa(__PACKAGE__)
builtin::blessed($other) $other->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($other)B= $other->isa(__PACKAGE__)
ABresult
0X0
100
111
2284 . q{ it isn't a Set::Relation object.}
2285 if !blessed $other or !$other->isa( __PACKAGE__ );
2286 2 $other;
2287 2 } @{$others}];
2288  
2289 2 return $others;
2290 }
2291  
2292 ###########################################################################
2293  
2294 0 ▶sub diff {
Subroutine diff: not called CC=1 SCAR=6.9
Pod undocumented
2295 0 my ($source, $filter) = @_;
2296 0 $filter = $source->_normalize_same_heading_relation_arg(
2297 'diff', '$other', $filter );
2298 0 return $source->_diff( $filter );
2299 }
2300  
2301 0 ▶sub _diff {
Subroutine _diff: not called CC=3 SCAR=24.8
2302 0 my ($source, $filter) = @_;
2303 0 ▶ if ($source->is_empty() or $filter->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->is_empty or $filter->is_empty) 0 0 0
Condition0%0/3
$source->is_empty or $filter->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/2
$source->is_empty or $filter->is_empty
$source->is_empty $filter->is_empty
Truth table0%0/3
A or B
A= $source->is_emptyB= $filter->is_empty
ABresult
1X1
011
000
2304 0 return $source;
2305 }
2306 0 return $source->_regular_diff( $filter );
2307 }
2308  
2309 0 ▶sub _regular_diff {
Subroutine _regular_diff: not called CC=3 SCAR=24.8
2310 0 my ($source, $filter) = @_;
2311  
2312 0 my $result = $source->empty();
2313  
2314 0 my $source_i = $source->_dup_free_want_index_over_all_attrs();
2315 0 my $filter_i = $filter->_dup_free_want_index_over_all_attrs();
2316 0 my $result_b = $result->_body();
2317  
2318 0 for my $tuple_ident_str (CORE::keys %{$source_i}) {
2319 0 ▶ if (!exists $filter_i->{$tuple_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $filter_i->{$tuple_ident_str}) 0 0 0
2320 0 my ($tuple_refaddr, $tuple) = %{$source_i->{$tuple_ident_str}};
2321 0 $result_b->{$tuple_refaddr} = $tuple;
2322 }
2323 }
2324  
2325 0 $result->_is_known_dup_free( 1 );
2326  
2327 0 return $result;
2328 }
2329  
2330 ###########################################################################
2331  
2332 0 ▶sub semidiff {
Subroutine semidiff: not called CC=3 SCAR=24.8
Pod undocumented
2333 0 my ($source, $filter) = @_;
2334 0 $filter = $source->_normalize_relation_arg(
2335 'semidiff', '$filter', $filter );
2336 0 ▶ if ($source->is_empty() or $filter->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->is_empty or $filter->is_empty) 0 0 0
Condition0%0/3
$source->is_empty or $filter->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/2
$source->is_empty or $filter->is_empty
$source->is_empty $filter->is_empty
Truth table0%0/3
A or B
A= $source->is_emptyB= $filter->is_empty
ABresult
1X1
011
000
2337 0 return $source;
2338 }
2339 0 return $source->_regular_diff( $source->_semijoin( $filter ) );
2340 }
2341  
2342 0 ▶sub antijoin {
Subroutine antijoin: not called CC=1 SCAR=6.9
Pod undocumented
2343 0 my ($self, @args) = @_;
2344 0 return $self->semidiff( @args );
2345 }
2346  
2347 0 ▶sub semijoin_and_diff {
Subroutine semijoin_and_diff: not called CC=1 SCAR=6.9
Pod undocumented
2348 0 my ($source, $filter) = @_;
2349 0 $filter = $source->_normalize_relation_arg(
2350 'semijoin_and_diff', '$filter', $filter );
2351 0 return $source->_semijoin_and_diff( $filter );
2352 }
2353  
2354 0 ▶sub _semijoin_and_diff {
Subroutine _semijoin_and_diff: not called CC=3 SCAR=24.8
2355 0 my ($source, $filter) = @_;
2356 0 ▶ if ($source->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->is_empty) 0 0 0
2357 0 return [$source, $source];
2358 }
2359 0 ▶ if ($filter->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter->is_empty) 0 0 0
2360 0 return [$source->empty(), $source];
2361 }
2362 0 my $semijoin = $source->_semijoin( $filter );
2363 0 return [$semijoin, $source->_regular_diff( $semijoin )];
2364 }
2365  
2366 0 ▶sub semijoin {
Subroutine semijoin: not called CC=1 SCAR=6.9
Pod undocumented
2367 0 my ($source, $filter) = @_;
2368 0 $filter = $source->_normalize_relation_arg(
2369 'semijoin', '$filter', $filter );
2370 0 return $source->_semijoin( $filter );
2371 }
2372  
2373 0 ▶sub _semijoin {
Subroutine _semijoin: not called CC=8 SCAR=42.8
2374 0 my ($source, $filter) = @_;
2375  
2376 0 ▶ if ($source->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->is_empty) 0 0 0
2377 0 return $source;
2378 }
2379 0 ▶ if ($filter->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter->is_empty) 0 0 0
2380 0 return $source->empty();
2381 }
2382  
2383 # If we get here, both inputs have at least one tuple.
2384  
2385 0 ▶ if ($source->is_nullary() or $filter->is_nullary()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->is_nullary or $filter->is_nullary) 0 0 0
Condition0%0/3
$source->is_nullary or $filter->is_nullary
l!l&&r!l&&!r
000
MC/DC0%0/2
$source->is_nullary or $filter->is_nullary
$source->is_nullary $filter->is_nullary
Truth table0%0/3
A or B
A= $source->is_nullaryB= $filter->is_nullary
ABresult
1X1
011
000
2386 0 return $source;
2387 }
2388  
2389 # If we get here, both inputs also have at least one attribute.
2390  
2391 0 my ($both, $source_only, $filter_only) = $source->_ptn_conj_and_disj(
2392 $source->_heading(), $filter->_heading() );
2393  
2394 0 ▶ if (@{$both} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$both;} == 0) 0 0 0
2395 # The inputs have disjoint headings; result is source.
2396 0 return $source;
2397 }
2398 0 ▶ if (@{$source_only} == 0 and @{$filter_only} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$source_only;} == 0 and @{$filter_only;} == 0) 0 0 0
Condition0%0/3
@{$source_only;} == 0 and @{$filter_only;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
@{$source_only;} == 0 and @{$filter_only;} == 0
@{$source_only;} == 0 @{$filter_only;} == 0
Truth table0%0/3
A and B
A= @{$source_only;} == 0B= @{$filter_only;} == 0
ABresult
0X0
100
111
2399 # The inputs have identical headings; result is intersection.
2400 0 return $source->_intersection( [$filter] );
2401 }
2402  
2403 # If we get here, the inputs also have overlapping non-ident headings.
2404  
2405 0 return $source->_regular_semijoin( $filter, $both );
2406 }
2407  
2408 0 ▶sub _regular_semijoin {
Subroutine _regular_semijoin: not called CC=7 SCAR=40.3
2409 0 my ($source, $filter, $both) = @_;
2410  
2411 0 my $result = $source->empty();
2412  
2413 0 ▶ my ($sm, $lg) = ($source->cardinality( 1 ) < $filter->cardinality( 1 ))
Branch: 1 branch
BranchTrueFalseTotal
$source->cardinality(1) < $filter->cardinality(1) ? : 0 0 0
2414 ? ($source, $filter) : ($filter, $source);
2415  
2416 0 my $sm_index = $sm->_want_index( $both );
2417 0 my $lg_index = $lg->_want_index( $both );
2418 0 my $source_index = $source->_want_index( $both );
2419 0 my $result_b = $result->_body();
2420  
2421 0 for my $subtuple_ident_str (CORE::keys %{$sm_index}) {
2422 0 ▶ if (exists $lg_index->{$subtuple_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lg_index->{$subtuple_ident_str}) 0 0 0
2423 0 my $matched_source_b = $source_index->{$subtuple_ident_str};
2424 0 for my $tuple_refaddr (CORE::keys %{$matched_source_b}) {
2425 $result_b->{$tuple_refaddr}
2426 0 = $matched_source_b->{$tuple_refaddr};
2427 }
2428 }
2429 }
2430  
2431 0 ▶ if ($source->_is_known_dup_free() and $filter->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->_is_known_dup_free and $filter->_is_known_dup_free) 0 0 0
Condition0%0/3
$source->_is_known_dup_free and $filter->_is_known_dup_free
!ll&&!rl&&r
000
MC/DC0%0/2
$source->_is_known_dup_free and $filter->_is_known_dup_free
$source->_is_known_dup_free $filter->_is_known_dup_free
Truth table0%0/3
A and B
A= $source->_is_known_dup_freeB= $filter->_is_known_dup_free
ABresult
0X0
100
111
2432 0 $result->_is_known_dup_free( 1 );
2433 }
2434  
2435 0 return $result;
2436 }
2437  
2438 ###########################################################################
2439  
2440 2 ▶sub join {
Subroutine join: called CC=1 SCAR=0.0
Pod undocumented
2441 2 my ($topic, $others) = @_;
2442 2 $others = $topic->_normalize_relations_arg(
2443 'join', '$others', $others );
2444 2 return $topic->_join( $others );
2445 }
2446  
2447 2 ▶sub _join {
Subroutine _join: called CC=11 SCAR=29.9
2448 2 my ($topic, $others) = @_;
2449  
2450 2 ▶ if (@{$others} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$others;} == 0) 0 2 2
2451 0 return $topic;
2452 }
2453  
2454 2 my $inputs = [$topic, @{$others}];
2455  
2456 2 ▶ if (any { $_->is_empty() } @{$inputs}) {
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_->is_empty; } , @{$inputs;})) 0 2 2
2457 # At least one input has zero tuples; so does result.
2458 0 my $result = $topic->_new();
2459 0 my $result_h = {CORE::map { %{$_->_heading()} } @{$inputs}};
2460 0 $result->_heading( $result_h );
2461 0 return $result;
2462 }
2463  
2464 # If we get here, all inputs have at least one tuple.
2465  
2466 $inputs = [
2467 2 sort { $a->cardinality( 1 ) <=> $b->cardinality( 1 ) }
2468 4 grep { !$_->is_nullary() } # filter out identity value instances
2469 2 @{$inputs}];
2470  
2471 2 ▶ if (@{$inputs} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$inputs;} == 0) 0 2 2
2472 # All inputs were the identity value; so is result.
2473 0 return $topic;
2474 }
2475 2 ▶ if (@{$inputs} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$inputs;} == 1) 0 2 2
2476 # Only one non-identity value input; so it is the result.
2477 0 return $inputs->[0];
2478 }
2479  
2480 # If we get here, there are at least 2 non-empty non-nullary inp rels.
2481  
2482 2 my $result = shift @{$inputs};
2483 INPUT:
2484 2 for my $input (@{$inputs}) {
2485 # TODO: Optimize this better by determining more strategic order
2486 # to join the various inputs, such as by doing intersections first,
2487 # then semijoins, then regular joins, then cross-products.
2488 # But at least we're going min to max cardinality meanwhile.
2489  
2490 2 my ($both, $result_only, $input_only)
2491 = $result->_ptn_conj_and_disj(
2492 $result->_heading(), $input->_heading() );
2493  
2494 2 ▶ if (@{$both} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$both;} == 0) 0 2 2
2495 # The inputs have disjoint headings; result is cross-product.
2496 0 $result = $result->_regular_product( $input );
2497 0 next INPUT;
2498 }
2499 0 ▶ if (@{$result_only} == 0 and @{$input_only} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$result_only;} == 0 and @{$input_only;} == 0) 0 2 2
Condition33%1/3
@{$result_only;} == 0 and @{$input_only;} == 0
!ll&&!rl&&r
200
MC/DC0%0/2
@{$result_only;} == 0 and @{$input_only;} == 0
@{$result_only;} == 0 @{$input_only;} == 0
Truth table33%1/3
A and B
A= @{$result_only;} == 0B= @{$input_only;} == 0
ABresult
0X0
100
111
2500 # The inputs have identical headings; result is intersection.
2501 0 $result = $result->_intersection( [$input] );
2502 0 next INPUT;
2503 }
2504  
2505 # If we get here, the inputs also have overlapping non-ident heads.
2506  
2507 2 ▶ if (@{$result_only} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$result_only;} == 0) 0 2 2
2508 # The first input's attrs are a proper subset of the second's;
2509 # result has same heading as second, a subset of sec's tuples.
2510 0 $result = $input->_regular_semijoin( $result, $both );
2511 0 next INPUT;
2512 }
2513 2 ▶ if (@{$input_only} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$input_only;} == 0) 0 2 2
2514 # The second input's attrs are a proper subset of the first's;
2515 # result has same heading as first, a subset of first's tuples.
2516 0 $result = $result->_regular_semijoin( $input, $both );
2517 0 next INPUT;
2518 }
2519  
2520 # If we get here, both inputs also have mini one attr of their own.
2521  
2522 2 $result = $result->_regular_join(
2523 $input, $both, $result_only, $input_only );
2524 }
2525 2 return $result;
2526 }
2527  
2528 2 ▶sub _regular_join {
Subroutine _regular_join: called CC=8 SCAR=20.9
2529 2 my ($topic, $other, $both, $topic_only, $other_only) = @_;
2530  
2531 2 my $result = $topic->_new();
2532  
2533 9 $result->_heading( {CORE::map { ($_ => undef) }
2534 2 @{$both}, @{$topic_only}, @{$other_only}} );
2535  
2536 2 ▶ my ($sm, $lg) = ($topic->cardinality( 1 ) < $other->cardinality( 1 ))
Branch: 1 branch
BranchTrueFalseTotal
$topic->cardinality(1) < $other->cardinality(1) ? : 2 0 2
2537 ? ($topic, $other) : ($other, $topic);
2538  
2539 2 my $sm_index = $sm->_want_index( $both );
2540 2 my $lg_index = $lg->_want_index( $both );
2541 2 my $result_b = {};
2542  
2543 2 for my $subtuple_ident_str (CORE::keys %{$sm_index}) {
2544 7 ▶ if (exists $lg_index->{$subtuple_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lg_index->{$subtuple_ident_str}) 5 2 7
2545 5 my $matched_sm_b = $sm_index->{$subtuple_ident_str};
2546 5 my $matched_lg_b = $lg_index->{$subtuple_ident_str};
2547 5 for my $sm_t (values %{$matched_sm_b}) {
2548 5 for my $lg_t (values %{$matched_lg_b}) {
2549 14 my $result_t = {%{$sm_t}, %{$lg_t}};
2550 14 $result_b->{refaddr $result_t} = $result_t;
2551 }
2552 }
2553 }
2554 }
2555 2 $result->_body( $result_b );
2556  
2557 2 ▶ if ($topic->_is_known_dup_free() and $other->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free and $other->_is_known_dup_free) 2 0 2
Condition33%1/3
$topic->_is_known_dup_free and $other->_is_known_dup_free
!ll&&!rl&&r
002
MC/DC0%0/2
$topic->_is_known_dup_free and $other->_is_known_dup_free
$topic->_is_known_dup_free $other->_is_known_dup_free
Truth table33%1/3
A and B
A= $topic->_is_known_dup_freeB= $other->_is_known_dup_free
ABresult
0X0
100
111
2558 2 $result->_is_known_dup_free( 1 );
2559 }
2560  
2561 2 return $result;
2562 }
2563  
2564 ###########################################################################
2565  
2566 0 ▶sub product {
Subroutine product: not called CC=7 SCAR=40.3
Pod undocumented
2567 0 my ($topic, $others) = @_;
2568  
2569 0 $others = $topic->_normalize_relations_arg(
2570 'product', '$others', $others );
2571  
2572 0 ▶ if (@{$others} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$others;} == 0) 0 0 0
2573 0 return $topic;
2574 }
2575  
2576 0 my $inputs = [$topic, @{$others}];
2577  
2578 my $attr_names
2579 0 = [CORE::map { CORE::keys %{$_->_heading()} } @{$inputs}];
2580  
2581 confess q{product(): Bad $others arg;}
2582 . q{ one of its elems has an attr name duplicated by}
2583 . q{ either the invocant or another $others elem.}
2584 0 ▶ if (uniqstr @{$attr_names}) != @{$attr_names};
Branch: 1 branch
BranchTrueFalseTotal
if &uniqstr(@{$attr_names;}) != @{$attr_names;} 0 0 0
2585  
2586 0 ▶ if (any { $_->is_empty() } @{$inputs}) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_->is_empty; } , @{$inputs;})) 0 0 0
2587 # At least one input has zero tuples; so does result.
2588 0 my $result = $topic->_new();
2589 0 $result->_heading( {CORE::map { ($_ => undef) } @{$attr_names}} );
2590 0 return $result;
2591 }
2592  
2593 # If we get here, all inputs have at least one tuple.
2594  
2595 $inputs = [
2596 0 sort { $a->cardinality( 1 ) <=> $b->cardinality( 1 ) }
2597 0 grep { !$_->is_nullary() } # filter out identity value instances
2598 0 @{$inputs}];
2599  
2600 0 ▶ if (@{$inputs} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$inputs;} == 0) 0 0 0
2601 # All inputs were the identity value; so is result.
2602 0 return $topic;
2603 }
2604 0 ▶ if (@{$inputs} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$inputs;} == 1) 0 0 0
2605 # Only one non-identity value input; so it is the result.
2606 0 return $inputs->[0];
2607 }
2608  
2609 # If we get here, there are at least 2 non-empty non-nullary inp rels.
2610  
2611 0 my $result = shift @{$inputs};
2612 0 for my $input (@{$inputs}) {
2613 0 $result = $result->_regular_product( $input );
2614 }
2615 0 return $result;
2616 }
2617  
2618 0 ▶sub _regular_product {
Subroutine _regular_product: not called CC=6 SCAR=37.4
2619 0 my ($topic, $other) = @_;
2620  
2621 0 my $result = $topic->_new();
2622  
2623 0 $result->_heading( {%{$topic->_heading()}, %{$other->_heading()}} );
2624  
2625 0 ▶ my ($sm, $lg) = ($topic->cardinality( 1 ) < $other->cardinality( 1 ))
Branch: 1 branch
BranchTrueFalseTotal
$topic->cardinality(1) < $other->cardinality(1) ? : 0 0 0
2626 ? ($topic, $other) : ($other, $topic);
2627  
2628 0 my $sm_b = $sm->_body();
2629 0 my $lg_b = $lg->_body();
2630 0 my $result_b = {};
2631  
2632 0 for my $sm_t (values %{$sm_b}) {
2633 0 for my $lg_t (values %{$lg_b}) {
2634 0 my $result_t = {%{$sm_t}, %{$lg_t}};
2635 0 $result_b->{refaddr $result_t} = $result_t;
2636 }
2637 }
2638 0 $result->_body( $result_b );
2639  
2640 0 ▶ if ($topic->_is_known_dup_free() and $other->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->_is_known_dup_free and $other->_is_known_dup_free) 0 0 0
Condition0%0/3
$topic->_is_known_dup_free and $other->_is_known_dup_free
!ll&&!rl&&r
000
MC/DC0%0/2
$topic->_is_known_dup_free and $other->_is_known_dup_free
$topic->_is_known_dup_free $other->_is_known_dup_free
Truth table0%0/3
A and B
A= $topic->_is_known_dup_freeB= $other->_is_known_dup_free
ABresult
0X0
100
111
2641 0 $result->_is_known_dup_free( 1 );
2642 }
2643  
2644 0 return $result;
2645 }
2646  
2647 ###########################################################################
2648  
2649 0 ▶sub quotient {
Subroutine quotient: not called CC=6 SCAR=37.4
Pod undocumented
2650 0 my ($dividend, $divisor) = @_;
2651  
2652 0 $divisor = $dividend->_normalize_relation_arg(
2653 'quotient', '$divisor', $divisor );
2654  
2655 0 my (undef, $dividend_only, $divisor_only)
2656 = $dividend->_ptn_conj_and_disj(
2657 $dividend->_heading(), $divisor->_heading() );
2658  
2659 confess q{quotient(): Bad $divisor arg;}
2660 . q{ its heading isn't a subset of the invocant's heading.}
2661 0 ▶ if @{$divisor_only} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$divisor_only;} > 0 0 0 0
2662  
2663 0 my $proj_of_dividend_only = $dividend->_projection( $dividend_only );
2664  
2665 0 ▶ if ($dividend->is_empty() or $divisor->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dividend->is_empty or $divisor->is_empty) 0 0 0
Condition0%0/3
$dividend->is_empty or $divisor->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/2
$dividend->is_empty or $divisor->is_empty
$dividend->is_empty $divisor->is_empty
Truth table0%0/3
A or B
A= $dividend->is_emptyB= $divisor->is_empty
ABresult
1X1
011
000
2666 # At least one input has zero tup; res has all tup o dividend proj.
2667 0 return $proj_of_dividend_only;
2668 }
2669  
2670 # If we get here, both inputs have at least one tuple.
2671  
2672 0 ▶ if ($dividend->is_nullary() or $divisor->is_nullary()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dividend->is_nullary or $divisor->is_nullary) 0 0 0
Condition0%0/3
$dividend->is_nullary or $divisor->is_nullary
l!l&&r!l&&!r
000
MC/DC0%0/2
$dividend->is_nullary or $divisor->is_nullary
$dividend->is_nullary $divisor->is_nullary
Truth table0%0/3
A or B
A= $dividend->is_nullaryB= $divisor->is_nullary
ABresult
1X1
011
000
2673 # Both inputs or just divisor is ident-one rel; result is dividend.
2674 0 return $dividend;
2675 }
2676  
2677 # If we get here, divisor has at least one attribute,
2678 # and divisor heading is proper subset of dividend heading.
2679  
2680 0 return $proj_of_dividend_only
2681 ->_diff( $proj_of_dividend_only
2682 ->_regular_product( $divisor )
2683 ->_diff( $dividend )
2684 ->_projection( $dividend_only )
2685 );
2686 }
2687  
2688 ###########################################################################
2689  
2690 0 ▶sub composition {
Subroutine composition: not called CC=10 SCAR=47.0
Pod undocumented
2691 0 my ($topic, $other) = @_;
2692  
2693 0 $other = $topic->_normalize_relation_arg(
2694 'composition', '$other', $other );
2695  
2696 0 my ($both, $topic_only, $other_only) = $topic->_ptn_conj_and_disj(
2697 $topic->_heading(), $other->_heading() );
2698  
2699 0 ▶ if ($topic->is_empty() or $other->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty or $other->is_empty) 0 0 0
Condition0%0/3
$topic->is_empty or $other->is_empty
l!l&&r!l&&!r
000
MC/DC0%0/2
$topic->is_empty or $other->is_empty
$topic->is_empty $other->is_empty
Truth table0%0/3
A or B
A= $topic->is_emptyB= $other->is_empty
ABresult
1X1
011
000
2700 # At least one input has zero tuples; so does result.
2701 0 return $topic->_new( [@{$topic_only}, @{$other_only}] );
2702 }
2703  
2704 # If we get here, both inputs have at least one tuple.
2705  
2706 0 ▶ if ($topic->is_nullary()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_nullary) 0 0 0
2707 # First input is identity-one relation; result is second input.
2708 0 return $other;
2709 }
2710 0 ▶ if ($other->is_nullary()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other->is_nullary) 0 0 0
2711 # Second input is identity-one relation; result is first input.
2712 0 return $topic;
2713 }
2714  
2715 # If we get here, both inputs also have at least one attribute.
2716  
2717 0 ▶ if (@{$both} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$both;} == 0) 0 0 0
2718 # The inputs have disjoint headings; result is cross-product.
2719 0 return $topic->_regular_product( $other );
2720 }
2721 0 ▶ if (@{$topic_only} == 0 and @{$other_only} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$topic_only;} == 0 and @{$other_only;} == 0) 0 0 0
Condition0%0/3
@{$topic_only;} == 0 and @{$other_only;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
@{$topic_only;} == 0 and @{$other_only;} == 0
@{$topic_only;} == 0 @{$other_only;} == 0
Truth table0%0/3
A and B
A= @{$topic_only;} == 0B= @{$other_only;} == 0
ABresult
0X0
100
111
2722 # The inputs have identical headings; result is ident-one relation.
2723 0 return $topic->_new( [ {} ] );
2724 }
2725  
2726 # If we get here, the inputs also have overlapping non-ident headings.
2727  
2728 0 ▶ if (@{$topic_only} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$topic_only;} == 0) 0 0 0
2729 # The first input's attributes are a proper subset of the second's;
2730 # result has same heading as second, a subset of second's tuples.
2731 0 return $other->_regular_semijoin( $topic, $both )
2732 ->_projection( $other_only );
2733 }
2734 0 ▶ if (@{$other_only} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$other_only;} == 0) 0 0 0
2735 # The second input's attributes are a proper subset of the first's;
2736 # result has same heading as first, a subset of first's tuples.
2737 0 return $topic->_regular_semijoin( $other, $both )
2738 ->_projection( $topic_only );
2739 }
2740  
2741 # If we get here, both inputs also have at least one attr of their own.
2742  
2743 return $topic->_regular_join(
2744 $other, $both, $topic_only, $other_only )
2745 0 ->_projection( [@{$topic_only}, @{$other_only}] );
2746 }
2747  
2748 ###########################################################################
2749  
2750 6 ▶sub _ptn_conj_and_disj {
Subroutine _ptn_conj_and_disj: called CC=1 SCAR=0.0
2751 # inputs are hashes, results are arrays
2752 6 my ($self, $src1, $src2) = @_;
2753 6 my $both = [grep { exists $src1->{$_} } CORE::keys %{$src2}];
2754 6 my $both_h = {CORE::map { ($_ => undef) } @{$both}};
2755 6 my $only1 = [grep { !exists $both_h->{$_} } CORE::keys %{$src1}];
2756 6 my $only2 = [grep { !exists $both_h->{$_} } CORE::keys %{$src2}];
2757 6 return ($both, $only1, $only2);
2758 }
2759  
2760 ###########################################################################
2761  
2762 5 ▶sub _want_index {
Subroutine _want_index: called CC=5 SCAR=16.2
2763 5 my ($self, $atnms) = @_;
2764 5 ▶ if (@{$atnms} == $self->degree()) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$atnms;} == $self->degree) 0 5 5
2765 # Special case; index is over all attributes of the relation, so
2766 # create this index in a special way that includes dup elimination.
2767 0 return $self->_dup_free_want_index_over_all_attrs();
2768 }
2769 5 my $subheading = {CORE::map { ($_ => undef) } @{$atnms}};
2770 5 my $subheading_ident_str = $self->_heading_ident_str( $subheading );
2771 5 my $indexes = $self->_indexes();
2772 5 ▶ if (!exists $indexes->{$subheading_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $indexes->{$subheading_ident_str}) 5 0 5
2773 5 my $index_and_meta = $indexes->{$subheading_ident_str}
2774 = [ $subheading, {} ];
2775 5 my $index = $index_and_meta->[1];
2776 5 my $body = $self->_body();
2777 5 for my $tuple_refaddr (CORE::keys %{$body}) {
2778 27 my $tuple = $body->{$tuple_refaddr};
2779 my $subtuple_ident_str = $self->_ident_str(
2780 27 {CORE::map { ($_ => $tuple->{$_}) } @{$atnms}} );
2781 27 ▶ my $matched_b = $index->{$subtuple_ident_str} ||= {};
Condition100%2/2
$index->{$subtuple_ident_str} ||= {}
l!l
1116
MC/DC100%1/1
$index->{$subtuple_ident_str} ||= {}
$index->{$subtuple_ident_str}
Truth table100%2/2
A
A= $index->{$subtuple_ident_str}
Aresult
11
00
2782 27 $matched_b->{$tuple_refaddr} = $tuple;
2783 }
2784 }
2785 5 return $indexes->{$subheading_ident_str}->[1];
2786 }
2787  
2788 ###########################################################################
2789  
2790 55 ▶sub _dup_free_want_index_over_all_attrs {
Subroutine _dup_free_want_index_over_all_attrs: called CC=8 SCAR=21.8
2791 55 my ($self) = @_;
2792  
2793 55 my $heading = $self->_heading();
2794 55 my $indexes = $self->_indexes();
2795  
2796 55 my $heading_ident_str = $self->_heading_ident_str( $heading );
2797  
2798 55 ▶ if (!exists $indexes->{$heading_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $indexes->{$heading_ident_str}) 28 27 55
2799 28 my $extras_to_delete = {};
2800  
2801 28 my $body = $self->_body();
2802 28 my $index_and_meta = $indexes->{$heading_ident_str}
2803 = [ $heading, {} ];
2804 28 my $index = $index_and_meta->[1];
2805 28 for my $tuple_refaddr (CORE::keys %{$body}) {
2806 131 my $tuple = $body->{$tuple_refaddr};
2807 131 my $tuple_ident_str = $self->_ident_str( $tuple );
2808 131 ▶ if (exists $index->{$tuple_ident_str}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index->{$tuple_ident_str}) 4 127 131
2809 4 delete $body->{$tuple_refaddr};
2810 4 $extras_to_delete->{$tuple_refaddr} = $tuple;
2811 4 next;
2812 }
2813 127 $index->{$tuple_ident_str} = {$tuple_refaddr => $tuple};
2814 }
2815  
2816 28 ▶ if ((CORE::keys %{$extras_to_delete}) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::keys %{$extras_to_delete;} > 0) 2 26 28
2817 2 for my $subheading_ident_str (CORE::keys %{$indexes}) {
2818 next
2819 2 ▶ if $subheading_ident_str eq $heading_ident_str;
Branch: 1 branch
BranchTrueFalseTotal
if $subheading_ident_str eq $heading_ident_str 2 0 2
2820 my ($subheading, $index)
2821 0 = @{$indexes->{$subheading_ident_str}};
2822 0 for my $tuple_refaddr (CORE::keys %{$extras_to_delete}) {
2823 0 my $tuple = $extras_to_delete->{$tuple_refaddr};
2824 my $subtuple_ident_str = $self->_ident_str(
2825 0 {CORE::map { ($_ => $tuple->{$_}) }
2826 0 CORE::keys %{$subheading}} );
2827 0 delete $index->{$subtuple_ident_str}->{$tuple_refaddr};
2828 }
2829 }
2830 }
2831  
2832 28 $self->_is_known_dup_free( 1 );
2833 }
2834  
2835 55 return $indexes->{$heading_ident_str}->[1];
2836 }
2837  
2838 ###########################################################################
2839  
2840 0 ▶sub join_with_group {
Subroutine join_with_group: not called CC=2 SCAR=17.9
Pod undocumented
2841 0 my ($primary, $secondary, $group_attr) = @_;
2842  
2843 0 $secondary = $primary->_normalize_relation_arg(
2844 'join_with_group', '$secondary', $secondary );
2845 0 $primary->_assert_valid_atnm_arg(
2846 'join_with_group', '$group_attr', $group_attr );
2847  
2848 0 my $primary_h = $primary->_heading();
2849  
2850 confess q{join_with_group(): Bad $group_attr arg;}
2851 . q{ that name for a new attr to add}
2852 . q{ to $primary, consisting of grouped $secondary-only attrs,}
2853 . q{ duplicates an attr of $primary (not being grouped).}
2854 0 ▶ if exists $primary_h->{$group_attr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $primary_h->{$group_attr} 0 0 0
2855  
2856 # TODO: inline+merge what join/group do for better performance.
2857  
2858 0 my ($both, $primary_only, $inner) = $primary->_ptn_conj_and_disj(
2859 $primary_h, $secondary->_heading() );
2860 0 my $inner_h = {CORE::map { $_ => undef } @{$inner}};
2861  
2862 return $primary
2863 ->_join( [$secondary] )
2864 0 ->_group( $group_attr, $inner, [CORE::keys %{$primary_h}],
2865 $inner_h );
2866 }
2867  
2868 ###########################################################################
2869  
2870 0 ▶sub rank {
Subroutine rank: not called CC=6 SCAR=37.4
Pod undocumented
2871 0 my ($topic, $name, $ord_func) = @_;
2872  
2873 0 my $topic_h = $topic->_heading();
2874  
2875 0 $topic->_assert_valid_atnm_arg( 'rank', '$name', $name );
2876 confess q{rank(): Bad $name arg; that name for a new attr to add}
2877 . q{ to the invocant, consisting of each tuple's numeric rank,}
2878 . q{ duplicates an existing attr of the invocant.}
2879 0 ▶ if exists $topic_h->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $topic_h->{$name} 0 0 0
2880  
2881 0 $topic->_assert_valid_func_arg( 'rank', '$ord_func', $ord_func );
2882  
2883 0 my $result = $topic->_new();
2884  
2885 0 $result->_heading( {%{$topic_h}, $name => undef} );
2886  
2887 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
2888 0 return $result;
2889 }
2890  
2891 0 ▶ if (!$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($topic->_is_known_dup_free) 0 0 0
2892 0 $topic->_dup_free_want_index_over_all_attrs();
2893 }
2894  
2895 0 my $ext_topic_tuples = [];
2896 0 my $topic_tuples_by_ext_tt_ref = {};
2897  
2898 0 for my $topic_t (values %{$topic->_body()}) {
2899 0 my $ext_topic_t = $topic->_export_nfmt_tuple( $topic_t );
2900 0 push @{$ext_topic_tuples}, $ext_topic_t;
2901 0 $topic_tuples_by_ext_tt_ref->{refaddr $ext_topic_t} = $topic_t;
2902 }
2903  
2904 my $sorted_ext_topic_tuples = [sort {
2905 0 local $_ = { 'a' => $a, 'b' => $b };
2906 0 $ord_func->();
2907 0 } @{$ext_topic_tuples}];
2908  
2909 0 my $result_b = $result->_body();
2910  
2911 0 my $rank = -1;
2912 0 for my $ext_topic_t (@{$sorted_ext_topic_tuples}) {
2913 0 my $topic_t = $topic_tuples_by_ext_tt_ref->{refaddr $ext_topic_t};
2914 0 $rank ++;
2915 0 my $result_t = {$name => $rank, %{$topic_t}};
2916 0 $result_b->{refaddr $result_t} = $result_t;
2917 }
2918  
2919 0 return $result;
2920 }
2921  
2922 ###########################################################################
2923  
2924 0 ▶sub rank_by_attr_names {
Subroutine rank_by_attr_names: not called CC=5 SCAR=34.0
Pod undocumented
2925 0 my ($topic, $name, $order_by) = @_;
2926  
2927 0 my $topic_h = $topic->_heading();
2928  
2929 0 $topic->_assert_valid_atnm_arg( 'rank_by_attr_names', '$name', $name );
2930 confess q{rank_by_attr_names(): Bad $name arg; that name for a new}
2931 . q{ attr to add to the invocant, consisting of each tuple's}
2932 . q{ numeric rank, duplicates an existing attr of th invocant.}
2933 0 ▶ if exists $topic_h->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $topic_h->{$name} 0 0 0
2934  
2935 0 $order_by = $topic->_normalize_order_by_arg(
2936 'rank_by_attr_names', '$order_by', $order_by );
2937  
2938 0 my $result = $topic->_new();
2939  
2940 0 $result->_heading( {%{$topic_h}, $name => undef} );
2941  
2942 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
2943 0 return $result;
2944 }
2945  
2946 0 my $sort_func = $topic->_sort_func_from_order_by( $order_by );
2947  
2948 0 ▶ if (!$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($topic->_is_known_dup_free) 0 0 0
2949 0 $topic->_dup_free_want_index_over_all_attrs();
2950 }
2951  
2952 0 my $result_b = $result->_body();
2953  
2954 0 my $rank = -1;
2955 0 for my $topic_t (@{$sort_func->( $topic )}) {
2956 0 $rank ++;
2957 0 my $result_t = {$name => $rank, %{$topic_t}};
2958 0 $result_b->{refaddr $result_t} = $result_t;
2959 }
2960  
2961 0 return $result;
2962 }
2963  
2964 ###########################################################################
2965  
2966 0 ▶sub _normalize_order_by_arg {
Subroutine _normalize_order_by_arg: not called CC=10 SCAR=47.0
2967 0 my ($topic, $rtn_nm, $arg_nm, $order_by) = @_;
2968  
2969 0 ▶ if (defined $order_by and !ref $order_by) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $order_by and not ref $order_by) 0 0 0
Condition0%0/3
defined $order_by and not ref $order_by
!ll&&!rl&&r
000
MC/DC0%0/2
defined $order_by and not ref $order_by
defined $order_by not ref $order_by
Truth table0%0/3
A and not(B)
A= defined $order_byB= not ref $order_by
ABresult
0X0
100
111
2970 0 $order_by = [$order_by];
2971 }
2972 0 ▶ confess qq{$rtn_nm(): Bad $arg_nm arg;}
Branch: 1 branch
BranchTrueFalseTotal
if ref $order_by ne "ARRAY" 0 0 0
2973 . q{ it must be an array-ref or a defined non-ref.}
2974 if ref $order_by ne 'ARRAY';
2975  
2976 $order_by = [CORE::map {
2977 (ref $_ ne 'ARRAY') ? [$_, 0, 'cmp']
2978 0 ▶ : (@{$_} == 1) ? [@{$_}, 0, 'cmp']
Branch: 1 branch
BranchTrueFalseTotal
@{$_;} == 2 ? : 0 0 0
2979 0 ▶ : (@{$_} == 2) ? [@{$_}, 'cmp']
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ne 'ARRAY' ? : 0 0 0
@{$_;} == 1 ? : 0 0 0
2980 : $_
2981 0 } @{$order_by}];
2982 confess qq{$rtn_nm(): Bad $arg_nm arg elem;}
2983 . q{ it must be a 1-3 elem array-ref or a defined non-ref,}
2984 . q{ its first elem must be a valid attr name (defin non-ref),}
2985 . q{ and its third elem must be undef or one of 'cmp'|'<=>'.}
2986 0 ▶ if notall {
Subroutine __ANON__: not called CC=7 SCAR=40.3
2987 0 ▶ ref $_ eq 'ARRAY' and @{$_} == 3
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "ARRAY" and @{$_;} == 3 and defined $_->[0] and not ref $_->[0] and !defined($_->[2]) || $_->[2] eq "cmp" || $_->[2] eq "<=>" 0 0 0
Condition0%0/18
ref $_ eq 'ARRAY' && @{$_;} == 3 && defined $_->[0] && !ref($_->[0]) && (!defined($_->[2]) || $_->[2] eq 'cmp' || $_->[2] eq '<=>')
!ll&&!rl&&r
000
ref $_ eq "ARRAY" and @{$_;} == 3 and defined $_->[0] and not ref $_->[0]
!ll&&!rl&&r
000
ref $_ eq "ARRAY" and @{$_;} == 3 and defined $_->[0]
!ll&&!rl&&r
000
ref $_ eq "ARRAY" and @{$_;} == 3
!ll&&!rl&&r
000
not defined $_->[2] or $_->[2] eq "cmp" or $_->[2] eq "<=>"
l!l&&r!l&&!r
000
not defined $_->[2] or $_->[2] eq "cmp"
l!l&&r!l&&!r
000
MC/DC0%0/7
ref $_ eq 'ARRAY' && @{$_;} == 3 && defined $_->[0] && !ref($_->[0]) && (!defined($_->[2]) || $_->[2] eq 'cmp' || $_->[2] eq '<=>')
ref $_ eq "ARRAY" @{$_;} == 3 defined $_->[0] not ref $_->[0] not defined $_->[2] $_->[2] eq "cmp" $_->[2] eq "<=>"
Truth table0%0/8
A and B and C and not(D) && not(E) or F or G
A= ref $_ eq "ARRAY"B= @{$_;} == 3C= defined $_->[0]D= not ref $_->[0]E= not defined $_->[2]F= $_->[2] eq "cmp"G= $_->[2] eq "<=>"
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110000
11111XX1
111101X1
11110011
2988 and defined $_->[0] and !ref $_->[0]
2989 and (!defined $_->[2]
2990 or $_->[2] eq 'cmp' or $_->[2] eq '<=>')
2991 0 ▶ } @{$order_by};
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { ref $_ eq "ARRAY" and @{$_;} == 3 and defined $_->[0] and not ref $_->[0] and !defined($_->[2]) || $_->[2] eq "cmp" || $_->[2] eq "<=>"; } , @{$order_by;}) 0 0 0
2992  
2993 0 my $atnms = [CORE::map { $_->[0] } @{$order_by}];
2994 confess qq{$rtn_nm(): Bad $arg_nm arg;}
2995 . q{ it specifies a list of}
2996 . q{ attr names with at least one duplicated name.}
2997 0 ▶ if (uniqstr @{$atnms}) != @{$atnms};
Branch: 1 branch
BranchTrueFalseTotal
if &uniqstr(@{$atnms;}) != @{$atnms;} 0 0 0
2998  
2999 0 my $topic_h = $topic->_heading();
3000 confess qq{$rtn_nm(): Bad $arg_nm arg;}
3001 . q{ the list of attr names it specifies isn't a subset of the}
3002 . q{ heading of the relation defined by the $members arg.}
3003 0 ▶ if notall { exists $topic_h->{$_} } @{$atnms};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &notall(sub { exists $topic_h->{$_}; } , @{$atnms;}) 0 0 0
3004  
3005 0 return $order_by;
3006 }
3007  
3008 ###########################################################################
3009  
3010 0 ▶sub _sort_func_from_order_by {
Subroutine _sort_func_from_order_by: not called CC=4 SCAR=30.0
3011 0 my ($topic, $order_by) = @_;
3012 my $sort_func_perl
3013 = "sub {\n"
3014 . "my (\$topic) = \@_;\n"
3015 . "return [sort {\n"
3016 . (CORE::join ' || ', '0', CORE::map {
3017 0 my ($name, $is_reverse_order, $compare_op) = @{$_};
3018 0 ▶ $compare_op ||= 'cmp';
Condition0%0/2
$compare_op ||= "cmp"
l!l
00
MC/DC0%0/1
$compare_op ||= "cmp"
$compare_op
Truth table0%0/2
A
A= $compare_op
Aresult
11
00
3019 0 ▶ ($is_reverse_order
Branch: 1 branch
BranchTrueFalseTotal
$is_reverse_order ? : 0 0 0
3020 ? "\$b->{'$name'} $compare_op \$a->{'$name'}"
3021 : "\$a->{'$name'} $compare_op \$b->{'$name'}");
3022 0 } @{$order_by}) . "\n"
3023 . "} values \%{\$topic->_body()}];\n"
3024 . "}\n"
3025 ;
3026 0 my $sort_func = eval $sort_func_perl;
3027 0 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 0 0
3028 0 confess qq{Oops, failed to compile Perl sort func from order by;\n}
3029 . qq{ error message is [[$err]];\n}
3030 . qq{ source code is [[$sort_func_perl]].}
3031 }
3032 0 return $sort_func;
3033 }
3034  
3035 ###########################################################################
3036  
3037 0 ▶sub limit {
Subroutine limit: not called CC=6 SCAR=37.4
Pod undocumented
3038 0 my ($topic, $ord_func, $min_rank, $max_rank) = @_;
3039  
3040 0 $topic->_assert_valid_func_arg( 'limit', '$ord_func', $ord_func );
3041  
3042 0 $topic->_assert_valid_nnint_arg( 'limit', '$min_rank', $min_rank );
3043 0 $topic->_assert_valid_nnint_arg( 'limit', '$max_rank', $max_rank );
3044 0 ▶ confess q{limit(): The $max_rank arg can't be less than the $min_rank.}
Branch: 1 branch
BranchTrueFalseTotal
if $max_rank < $min_rank 0 0 0
3045 if $max_rank < $min_rank;
3046  
3047 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
3048 0 return $topic;
3049 }
3050  
3051 0 ▶ if (!$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($topic->_is_known_dup_free) 0 0 0
3052 0 $topic->_dup_free_want_index_over_all_attrs();
3053 }
3054  
3055 0 my $topic_b = $topic->_body();
3056  
3057 0 my $ext_topic_tuples = [];
3058 0 my $topic_tuples_by_ext_tt_ref = {};
3059  
3060 0 for my $topic_t_refaddr (CORE::keys %{$topic_b}) {
3061 0 my $topic_t = $topic_b->{$topic_t_refaddr};
3062 0 my $ext_topic_t = $topic->_export_nfmt_tuple( $topic_t );
3063 0 push @{$ext_topic_tuples}, $ext_topic_t;
3064 0 $topic_tuples_by_ext_tt_ref->{refaddr $ext_topic_t}
3065 = $topic_t_refaddr;
3066 }
3067  
3068 my $sorted_ext_topic_tuples = [sort {
3069 0 local $_ = { 'a' => $a, 'b' => $b };
3070 0 $ord_func->();
3071 0 } @{$ext_topic_tuples}];
3072  
3073 0 my $result = $topic->empty();
3074  
3075 0 my $result_b = $result->_body();
3076  
3077 0 for my $ext_topic_t
3078 0 (@{$sorted_ext_topic_tuples}[$min_rank..$max_rank]) {
3079 my $topic_t_refaddr
3080 0 = $topic_tuples_by_ext_tt_ref->{refaddr $ext_topic_t};
3081 0 $result_b->{$topic_t_refaddr} = $topic_b->{$topic_t_refaddr};
3082 }
3083  
3084 0 return $result;
3085 }
3086  
3087 ###########################################################################
3088  
3089 0 ▶sub limit_by_attr_names {
Subroutine limit_by_attr_names: not called CC=5 SCAR=34.0
Pod undocumented
3090 0 my ($topic, $order_by, $min_rank, $max_rank) = @_;
3091  
3092 0 $order_by = $topic->_normalize_order_by_arg(
3093 'limit_by_attr_names', '$order_by', $order_by );
3094  
3095 0 $topic->_assert_valid_nnint_arg(
3096 'limit_by_attr_names', '$min_rank', $min_rank );
3097 0 $topic->_assert_valid_nnint_arg(
3098 'limit_by_attr_names', '$max_rank', $max_rank );
3099 0 ▶ confess q{limit_by_attr_names():}
Branch: 1 branch
BranchTrueFalseTotal
if $max_rank < $min_rank 0 0 0
3100 . q{ The $max_rank arg can't be less than the $min_rank.}
3101 if $max_rank < $min_rank;
3102  
3103 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
3104 0 return $topic;
3105 }
3106  
3107 0 my $sort_func = $topic->_sort_func_from_order_by( $order_by );
3108  
3109 0 ▶ if (!$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($topic->_is_known_dup_free) 0 0 0
3110 0 $topic->_dup_free_want_index_over_all_attrs();
3111 }
3112  
3113 0 my $result = $topic->empty();
3114  
3115 0 my $result_b = $result->_body();
3116  
3117 0 for my $topic_t (@{$sort_func->( $topic )}[$min_rank..$max_rank]) {
3118 0 $result_b->{refaddr $topic_t} = $topic_t;
3119 }
3120  
3121 0 return $result;
3122 }
3123  
3124 ###########################################################################
3125  
3126 0 ▶sub substitution {
Subroutine substitution: not called CC=1 SCAR=6.9
Pod undocumented
3127 0 my ($topic, $attr_names, $func, $allow_dup_tuples) = @_;
3128 0 (my $subst_h, $attr_names)
3129 = $topic->_atnms_hr_from_assert_valid_subst_args(
3130 'substitution', '$attr_names', '$func', $attr_names, $func );
3131 0 return $topic->_substitution(
3132 'substitution', '$attr_names', '$func',
3133 $attr_names, $func, $subst_h, $allow_dup_tuples );
3134 }
3135  
3136 0 ▶sub _atnms_hr_from_assert_valid_subst_args {
Subroutine _atnms_hr_from_assert_valid_subst_args: not called CC=2 SCAR=17.9
3137 0 my ($topic, $rtn_nm, $arg_nm_atnms, $arg_nm_func, $atnms, $func) = @_;
3138  
3139 0 (my $subst_h, $atnms) = $topic->_atnms_hr_from_assert_valid_atnms_arg(
3140 $rtn_nm, $arg_nm_atnms, $atnms );
3141 0 my (undef, undef, $subst_only)
3142 = $topic->_ptn_conj_and_disj( $topic->_heading(), $subst_h );
3143 confess qq{$rtn_nm(): Bad $arg_nm_atnms arg; that attr list}
3144 . q{ isn't a subset of the invocant's heading.}
3145 0 ▶ if @{$subst_only} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$subst_only;} > 0 0 0 0
3146  
3147 0 $topic->_assert_valid_func_arg( $rtn_nm, $arg_nm_func, $func );
3148  
3149 0 return ($subst_h, $atnms);
3150 }
3151  
3152 0 ▶sub _substitution {
Subroutine _substitution: not called CC=6 SCAR=37.4
3153 0 my ($topic, $rtn_nm, $arg_nm_attrs, $arg_nm_func, $attrs, $func,
3154 $subst_h, $allow_dup_tuples) = @_;
3155  
3156 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
3157 0 return $topic;
3158 }
3159 0 ▶ if (@{$attrs} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$attrs;} == 0) 0 0 0
3160 # Substitution in zero attrs of input yields the input.
3161 0 return $topic;
3162 }
3163  
3164 0 ▶ if (!$allow_dup_tuples and !$topic->_is_known_dup_free()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_dup_tuples or $topic->_is_known_dup_free) 0 0 0
Condition0%0/3
$allow_dup_tuples or $topic->_is_known_dup_free
l!l&&r!l&&!r
000
MC/DC0%0/2
$allow_dup_tuples or $topic->_is_known_dup_free
$allow_dup_tuples $topic->_is_known_dup_free
Truth table0%0/3
A or B
A= $allow_dup_tuplesB= $topic->_is_known_dup_free
ABresult
1X1
011
000
3165 0 $topic->_dup_free_want_index_over_all_attrs();
3166 }
3167  
3168 0 my $result = $topic->empty();
3169  
3170 0 my $result_b = $result->_body();
3171  
3172 0 for my $topic_t (values %{$topic->_body()}) {
3173 0 my $subst_t;
3174 {
3175 0 local $_ = $topic->_export_nfmt_tuple( $topic_t );
3176 0 $subst_t = $func->();
3177 }
3178 $topic->_assert_valid_tuple_result_of_func_arg(
3179 0 $rtn_nm, $arg_nm_func, $arg_nm_attrs, $subst_t, $subst_h );
3180 0 $subst_t = $topic->_import_nfmt_tuple( $subst_t );
3181 0 my $result_t = {%{$topic_t}, %{$subst_t}};
3182 0 $result_b->{refaddr $result_t} = $result_t;
3183 }
3184  
3185 0 return $result;
3186 }
3187  
3188 ###########################################################################
3189  
3190 0 ▶sub static_subst {
Subroutine static_subst: not called CC=1 SCAR=6.9
Pod undocumented
3191 0 my ($topic, $attrs) = @_;
3192 0 $topic->_assert_valid_static_subst_args(
3193 'static_subst', '$attrs', $attrs );
3194 0 return $topic->_static_subst( $attrs );
3195 }
3196  
3197 0 ▶sub _assert_valid_static_subst_args {
Subroutine _assert_valid_static_subst_args: not called CC=4 SCAR=30.0
3198 0 my ($topic, $rtn_nm, $arg_nm_attrs, $attrs) = @_;
3199  
3200 0 ▶ confess qq{$rtn_nm(): Bad $arg_nm_attrs arg; it isn't a hash-ref.}
Branch: 1 branch
BranchTrueFalseTotal
if ref $attrs ne "HASH" 0 0 0
3201 if ref $attrs ne 'HASH';
3202  
3203 0 my (undef, undef, $subst_only)
3204 = $topic->_ptn_conj_and_disj( $topic->_heading(), $attrs );
3205 confess qq{$rtn_nm(): Bad $arg_nm_attrs arg; that attr list}
3206 . q{ isn't a subset of the invocant's heading.}
3207 0 ▶ if @{$subst_only} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$subst_only;} > 0 0 0 0
3208  
3209 0 ▶ confess qq{$rtn_nm(): Bad $arg_nm_attrs arg;}
Branch: 1 branch
BranchTrueFalseTotal
if $topic->_tuple_arg_has_circular_refs($attrs) 0 0 0
3210 . q{ it is a hash-ref, and there exist circular refs}
3211 . q{ between itself or its tuple-valued components.}
3212 if $topic->_tuple_arg_has_circular_refs( $attrs );
3213  
3214 0 return;
3215 }
3216  
3217 0 ▶sub _static_subst {
Subroutine _static_subst: not called CC=4 SCAR=30.0
3218 0 my ($topic, $attrs) = @_;
3219  
3220 0 ▶ if ($topic->is_empty()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic->is_empty) 0 0 0
3221 0 return $topic;
3222 }
3223 0 ▶ if ((scalar CORE::keys %{$attrs}) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar CORE::keys %{$attrs;} == 0) 0 0 0
3224 # Substitution in zero attrs of input yields the input.
3225 0 return $topic;
3226 }
3227  
3228 0 $attrs = $topic->_import_nfmt_tuple( $attrs );
3229  
3230 0 my $result = $topic->empty();
3231  
3232 0 my $result_b = $result->_body();
3233  
3234 0 for my $topic_t (values %{$topic->_body()}) {
3235 0 my $result_t = {%{$topic_t}, %{$attrs}};
3236 0 $result_b->{refaddr $result_t} = $result_t;
3237 }
3238  
3239 0 return $result;
3240 }
3241  
3242 ###########################################################################
3243  
3244 0 ▶sub subst_in_restr {
Subroutine subst_in_restr: not called CC=1 SCAR=6.9
Pod undocumented
3245 0 my ($topic, $restr_func, $subst_attr_names, $subst_func,
3246 $allow_dup_tuples) = @_;
3247  
3248 0 $topic->_assert_valid_func_arg(
3249 'subst_in_restr', '$restr_func', $restr_func );
3250  
3251 0 (my $subst_h, $subst_attr_names) = $topic
3252 ->_atnms_hr_from_assert_valid_subst_args( 'subst_in_restr',
3253 '$subst_attr_names', '$subst_func',
3254 $subst_attr_names, $subst_func );
3255  
3256 my ($topic_to_subst, $topic_no_subst)
3257 0 = @{$topic->_restr_and_cmpl( $restr_func, $allow_dup_tuples )};
3258  
3259 0 return $topic_to_subst
3260 ->_substitution( 'subst_in_restr', '$subst_attr_names',
3261 '$subst_func', $subst_attr_names, $subst_func, $subst_h,
3262 $allow_dup_tuples )
3263 ->_union( [$topic_no_subst] );
3264 }
3265  
3266 ###########################################################################
3267  
3268 0 ▶sub static_subst_in_restr {
Subroutine static_subst_in_restr: not called CC=1 SCAR=6.9
Pod undocumented
3269 0 my ($topic, $restr_func, $subst, $allow_dup_tuples) = @_;
3270  
3271 0 $topic->_assert_valid_func_arg(
3272 'static_subst_in_restr', '$restr_func', $restr_func );
3273  
3274 0 $topic->_assert_valid_static_subst_args(
3275 'static_subst_in_restr', '$subst', $subst );
3276  
3277 my ($topic_to_subst, $topic_no_subst)
3278 0 = @{$topic->_restr_and_cmpl( $restr_func, $allow_dup_tuples )};
3279  
3280 0 return $topic_to_subst
3281 ->_static_subst( $subst )
3282 ->_union( [$topic_no_subst] );
3283 }
3284  
3285 ###########################################################################
3286  
3287 0 ▶sub subst_in_semijoin {
Subroutine subst_in_semijoin: not called CC=1 SCAR=6.9
Pod undocumented
3288 0 my ($topic, $restr, $subst_attr_names, $subst_func, $allow_dup_tuples)
3289 = @_;
3290  
3291 0 $restr = $topic->_normalize_relation_arg(
3292 'subst_in_semijoin', '$restr', $restr );
3293  
3294 0 (my $subst_h, $subst_attr_names) = $topic
3295 ->_atnms_hr_from_assert_valid_subst_args( 'subst_in_semijoin',
3296 '$subst_attr_names', '$subst_func',
3297 $subst_attr_names, $subst_func );
3298  
3299 my ($topic_to_subst, $topic_no_subst)
3300 0 = @{$topic->_semijoin_and_diff( $restr )};
3301  
3302 0 return $topic_to_subst
3303 ->_substitution( 'subst_in_semijoin', '$subst_attr_names',
3304 '$subst_func', $subst_attr_names, $subst_func, $subst_h,
3305 $allow_dup_tuples )
3306 ->_union( [$topic_no_subst] );
3307 }
3308  
3309 ###########################################################################
3310  
3311 0 ▶sub static_subst_in_semijoin {
Subroutine static_subst_in_semijoin: not called CC=1 SCAR=6.9
Pod undocumented
3312 0 my ($topic, $restr, $subst) = @_;
3313  
3314 0 $restr = $topic->_normalize_relation_arg(
3315 'static_subst_in_semijoin', '$restr', $restr );
3316  
3317 0 $topic->_assert_valid_static_subst_args(
3318 'static_subst_in_semijoin', '$subst', $subst );
3319  
3320 my ($topic_to_subst, $topic_no_subst)
3321 0 = @{$topic->_semijoin_and_diff( $restr )};
3322  
3323 0 return $topic_to_subst
3324 ->_static_subst( $subst )
3325 ->_union( [$topic_no_subst] );
3326 }
3327  
3328 ###########################################################################
3329  
3330 0 ▶sub outer_join_with_group {
Subroutine outer_join_with_group: not called CC=4 SCAR=30.0
Pod undocumented
3331 0 my ($primary, $secondary, $group_attr) = @_;
3332  
3333 0 $secondary = $primary->_normalize_relation_arg(
3334 'outer_join_with_group', '$secondary', $secondary );
3335 0 $primary->_assert_valid_atnm_arg(
3336 'outer_join_with_group', '$group_attr', $group_attr );
3337  
3338 0 my $primary_h = $primary->_heading();
3339  
3340 confess q{outer_join_with_group(): Bad $group_attr arg;}
3341 . q{ that name for a new attr to add}
3342 . q{ to $primary, consisting of grouped $secondary-only attrs,}
3343 . q{ duplicates an attr of $primary (not being grouped).}
3344 0 ▶ if exists $primary_h->{$group_attr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $primary_h->{$group_attr} 0 0 0
3345  
3346 # TODO: inline+merge what join/group/etc do for better performance.
3347  
3348 0 my ($both, $primary_only, $inner) = $primary->_ptn_conj_and_disj(
3349 $primary_h, $secondary->_heading() );
3350 0 my $inner_h = {CORE::map { $_ => undef } @{$inner}};
3351  
3352 my ($pri_matched, $pri_nonmatched)
3353 0 = @{$primary->_semijoin_and_diff( $secondary )};
3354  
3355 my $result_matched = $pri_matched
3356 ->_join( [$secondary] )
3357 0 ->_group( $group_attr, $inner, [CORE::keys %{$primary_h}],
3358 $inner_h );
3359  
3360 0 my $result_nonmatched = $pri_nonmatched
3361 ->_static_exten( {$group_attr => $primary->_new( $inner )} );
3362  
3363 0 my $result = $result_matched->_union( [$result_nonmatched] );
3364  
3365 0 ▶ if ($primary->_is_known_dup_free()
Branch: 1 branch
BranchTrueFalseTotal
if ($primary->_is_known_dup_free and $secondary->_is_known_dup_free) 0 0 0
Condition0%0/3
$primary->_is_known_dup_free and $secondary->_is_known_dup_free
!ll&&!rl&&r
000
MC/DC0%0/2
$primary->_is_known_dup_free and $secondary->_is_known_dup_free
$primary->_is_known_dup_free $secondary->_is_known_dup_free
Truth table0%0/3
A and B
A= $primary->_is_known_dup_freeB= $secondary->_is_known_dup_free
ABresult
0X0
100
111
3366 and $secondary->_is_known_dup_free()) {
3367 0 $result->_is_known_dup_free( 1 );
3368 }
3369  
3370 0 return $result;
3371 }
3372  
3373 ###########################################################################
3374  
3375 0 ▶sub outer_join_with_undefs {
Subroutine outer_join_with_undefs: not called CC=3 SCAR=24.8
Pod undocumented
3376 0 my ($primary, $secondary) = @_;
3377  
3378 0 $secondary = $primary->_normalize_relation_arg(
3379 'outer_join_with_undefs', '$secondary', $secondary );
3380  
3381 0 my (undef, undef, $exten_attrs) = $primary->_ptn_conj_and_disj(
3382 $primary->_heading(), $secondary->_heading() );
3383 0 my $filler = {CORE::map { $_ => undef } @{$exten_attrs}};
3384  
3385 my ($pri_matched, $pri_nonmatched)
3386 0 = @{$primary->_semijoin_and_diff( $secondary )};
3387  
3388 0 my $result_matched = $pri_matched->_join( [$secondary] );
3389  
3390 0 my $result_nonmatched = $pri_nonmatched->_static_exten( $filler );
3391  
3392 0 my $result = $result_matched->_union( [$result_nonmatched] );
3393  
3394 0 ▶ if ($primary->_is_known_dup_free()
Branch: 1 branch
BranchTrueFalseTotal
if ($primary->_is_known_dup_free and $secondary->_is_known_dup_free) 0 0 0
Condition0%0/3
$primary->_is_known_dup_free and $secondary->_is_known_dup_free
!ll&&!rl&&r
000
MC/DC0%0/2
$primary->_is_known_dup_free and $secondary->_is_known_dup_free
$primary->_is_known_dup_free $secondary->_is_known_dup_free
Truth table0%0/3
A and B
A= $primary->_is_known_dup_freeB= $secondary->_is_known_dup_free
ABresult
0X0
100
111
3395 and $secondary->_is_known_dup_free()) {
3396 0 $result->_is_known_dup_free( 1 );
3397 }
3398  
3399 0 return $result;
3400 }
3401  
3402 ###########################################################################
3403  
3404 0 ▶sub outer_join_with_static_exten {
Subroutine outer_join_with_static_exten: not called CC=6 SCAR=37.4
Pod undocumented
3405 0 my ($primary, $secondary, $filler) = @_;
3406  
3407 0 $secondary = $primary->_normalize_relation_arg(
3408 'outer_join_with_static_exten', '$secondary', $secondary );
3409  
3410 0 ▶ confess q{outer_join_with_static_exten(): Bad $filler arg;}
Branch: 1 branch
BranchTrueFalseTotal
if ref $filler ne "HASH" 0 0 0
3411 . q{ it isn't a hash-ref.}
3412 if ref $filler ne 'HASH';
3413 0 ▶ confess q{outer_join_with_static_exten(): Bad $filler arg;}
Branch: 1 branch
BranchTrueFalseTotal
if $primary->_tuple_arg_has_circular_refs($filler) 0 0 0
3414 . q{ it is a hash-ref, and there exist circular refs}
3415 . q{ between itself or its tuple-valued components.}
3416 if $primary->_tuple_arg_has_circular_refs( $filler );
3417  
3418 0 my (undef, undef, $exten_attrs) = $primary->_ptn_conj_and_disj(
3419 $primary->_heading(), $secondary->_heading() );
3420 0 my $exten_h = {CORE::map { $_ => undef } @{$exten_attrs}};
3421  
3422 0 ▶ confess q{outer_join_with_static_exten(): Bad $filler arg elem;}
Branch: 1 branch
BranchTrueFalseTotal
unless $primary->_is_identical_hkeys($exten_h, $filler) 0 0 0
3423 . q{ it doesn't have exactly the}
3424 . q{ same set of attr names as the sub-heading of $secondary}
3425 . q{ that doesn't overlap with the heading of $primary.}
3426 if !$primary->_is_identical_hkeys( $exten_h, $filler );
3427  
3428 my ($pri_matched, $pri_nonmatched)
3429 0 = @{$primary->_semijoin_and_diff( $secondary )};
3430  
3431 0 my $result_matched = $pri_matched->_join( [$secondary] );
3432  
3433 0 my $result_nonmatched = $pri_nonmatched->_static_exten( $filler );
3434  
3435 0 my $result = $result_matched->_union( [$result_nonmatched] );
3436  
3437 0 ▶ if ($primary->_is_known_dup_free()
Branch: 1 branch
BranchTrueFalseTotal
if ($primary->_is_known_dup_free and $secondary->_is_known_dup_free) 0 0 0
Condition0%0/3
$primary->_is_known_dup_free and $secondary->_is_known_dup_free
!ll&&!rl&&r
000
MC/DC0%0/2
$primary->_is_known_dup_free and $secondary->_is_known_dup_free
$primary->_is_known_dup_free $secondary->_is_known_dup_free
Truth table0%0/3
A and B
A= $primary->_is_known_dup_freeB= $secondary->_is_known_dup_free
ABresult
0X0
100
111
3438 and $secondary->_is_known_dup_free()) {
3439 0 $result->_is_known_dup_free( 1 );
3440 }
3441  
3442 0 return $result;
3443 }
3444  
3445 ###########################################################################
3446  
3447 0 ▶sub outer_join_with_exten {
Subroutine outer_join_with_exten: not called CC=3 SCAR=24.8
Pod undocumented
3448 0 my ($primary, $secondary, $exten_func, $allow_dup_tuples) = @_;
3449  
3450 0 $secondary = $primary->_normalize_relation_arg(
3451 'outer_join_with_exten', '$secondary', $secondary );
3452 0 $primary->_assert_valid_func_arg(
3453 'outer_join_with_exten', '$exten_func', $exten_func );
3454  
3455 0 my (undef, undef, $exten_attrs) = $primary->_ptn_conj_and_disj(
3456 $primary->_heading(), $secondary->_heading() );
3457 0 my $exten_h = {CORE::map { $_ => undef } @{$exten_attrs}};
3458  
3459 my ($pri_matched, $pri_nonmatched)
3460 0 = @{$primary->_semijoin_and_diff( $secondary )};
3461  
3462 0 my $result_matched = $pri_matched->_join( [$secondary] );
3463  
3464 # Note: if '_extension' dies due to what $exten_func did it would
3465 # state the error is reported by 'extension' and with some wrong
3466 # details; todo fix later; on correct it won't affect users though.
3467 0 my $result_nonmatched = $pri_nonmatched->_extension(
3468 $exten_attrs, $exten_func, $exten_h, $allow_dup_tuples );
3469  
3470 0 my $result = $result_matched->_union( [$result_nonmatched] );
3471  
3472 0 ▶ if ($primary->_is_known_dup_free()
Branch: 1 branch
BranchTrueFalseTotal
if ($primary->_is_known_dup_free and $secondary->_is_known_dup_free) 0 0 0
Condition0%0/3
$primary->_is_known_dup_free and $secondary->_is_known_dup_free
!ll&&!rl&&r
000
MC/DC0%0/2
$primary->_is_known_dup_free and $secondary->_is_known_dup_free
$primary->_is_known_dup_free $secondary->_is_known_dup_free
Truth table0%0/3
A and B
A= $primary->_is_known_dup_freeB= $secondary->_is_known_dup_free
ABresult
0X0
100
111
3473 and $secondary->_is_known_dup_free()) {
3474 0 $result->_is_known_dup_free( 1 );
3475 }
3476  
3477 0 return $result;
3478 }
3479  
3480 ###########################################################################
3481  
3482 } # class Set::Relation::V2
3483  
3484 ###########################################################################
3485 ###########################################################################
3486  
3487 3 1;
↑ Summary Relation/V1.pm »