blib/lib/Set/Object.pm

filter: Statementstmt 82.2% 260 / 316 Branchbran 79.6% 94 / 118 Conditioncond 48.8% 22 / 45 MC/DCmcdc 21.4% 6 / 28 Subroutinesub 80.2% 57 / 71 Podpod 84.2% 32 / 38 totaltotal 76.4% 471 / 616 SCAR 48.7
CC
75
Cov
78%
is_key
10.2
compare
10.0
difference
9.1
CRAP 130.9
↑ Summary blib/lib/Set/Object/Weak.pm »
1 =head1 NAME
2  
3 Set::Object - set of objects and strings
4  
5 =head1 SYNOPSIS
6  
7 use Set::Object qw(set);
8  
9 my $set = set(); # or Set::Object->new()
10  
11 $set->insert(@thingies);
12 $set->remove(@thingies);
13  
14 @items = @$set; # or $set->members for the unsorted array
15  
16 $union = $set1 + $set2;
17 $intersection = $set1 * $set2;
18 $difference = $set1 - $set2;
19 $symmetric_difference = $set1 % $set2;
20  
21 print "set1 is a proper subset of set2"
22 if $set1 < $set2;
23  
24 print "set1 is a subset of set2"
25 if $set1 <= $set2;
26  
27 # common idiom - iterate over any pure Perl structure
28 use Set::Object qw(reftype);
29 my @stack = $root;
30 my $seen = Set::Object->new(@stack);
31 while (my $object = pop @stack) {
32 if (reftype $object eq "HASH") {
33 # do something with hash members
34  
35 # add the new nodes to the stack
36 push @stack, grep { ref $_ && $seen->insert($_) }
37 values %$object;
38 }
39 elsif (reftype $object eq "ARRAY") {
40 # do something with array members
41  
42 # add the new nodes to the stack
43 push @stack, grep { ref $_ && $seen->insert($_) }
44 @$object;
45  
46 }
47 elsif (reftype $object =~ /SCALAR|REF/) {
48 push @stack, $$object
49 if ref $$object && $seen->insert($$object);
50 }
51 }
52  
53 =head1 DESCRIPTION
54  
55 This modules implements a set of objects, that is, an unordered
56 collection of objects without duplication.
57  
58 The term I<objects> is applied loosely - for the sake of
59 L<Set::Object>, anything that is a reference is considered an object.
60  
61 L<Set::Object> 1.09 and later includes support for inserting scalars
62 (including the empty string, but excluding C<undef>) as well as
63 objects. This can be thought of as (and is currently implemented as)
64 a degenerate hash that only has keys and no values. Unlike objects
65 placed into a Set::Object, scalars that are inserted will be flattened
66 into strings, so will lose any magic (eg, tie) or other special bits
67 that they went in with; only strings come out.
68  
69 =head1 CONSTRUCTORS
70  
71 =head2 Set::Object->new( [I<list>] )
72  
73 Return a new C<Set::Object> containing the elements passed in I<list>.
74  
75 =head2 C<set(@members)>
76  
77 Return a new C<Set::Object> filled with C<@members>. You have to
78 explicitly import this method.
79  
80 B<New in Set::Object 1.22>: this function is now called as a method
81 to return new sets the various methods that return a new set, such as
82 C<-E<gt>intersection>, C<-E<gt>union>, etc and their overloaded
83 counterparts. The default method always returns C<Set::Object>
84 objects, preserving previous behaviour and not second guessing the
85 nature of your derived L<Set::Object> class.
86  
87 =head2 C<weak_set()>
88  
89 Return a new C<Set::Object::Weak>, filled with C<@members>. You have
90 to explicitly import this method.
91  
92 =head1 INSTANCE METHODS
93  
94 =head2 insert( [I<list>] )
95  
96 Add items to the C<Set::Object>.
97  
98 Adding the same object several times is not an error, but any
99 C<Set::Object> will contain at most one occurrence of the same object.
100  
101 Returns the number of elements that were actually added. As of
102 Set::Object 1.23, C<undef> will not insert.
103  
104 =head2 includes( [I<list>] )
105  
106 =head2 has( [I<list>] )
107  
108 =head2 contains( [I<list>] )
109  
110 Return C<true> if B<all> the objects in I<list> are members of the
111 C<Set::Object>. I<list> may be empty, in which case C<true> is
112 always returned.
113  
114 As of Set::Object 1.23, C<undef> will never appear to be present in
115 any set (even if the set contains the empty string). Prior to 1.23,
116 there would have been a run-time warning.
117  
118 =head2 member( [I<item>] )
119  
120 =head2 element( [I<item>] )
121  
122 Like C<includes>, but takes a single item to check and returns that
123 item if the value is found, rather than just a true value.
124  
125 =head2 members
126  
127 =head2 elements
128  
129 Return the objects contained in the C<Set::Object> in random (hash)
130 order.
131  
132 Note that the elements of a C<Set::Object> in list context are returned
133 sorted - C<@$set> - so using the C<members> method is much faster.
134  
135 =head2 size
136  
137 Return the number of elements in the C<Set::Object>.
138  
139 =head2 remove( [I<list>] )
140  
141 =head2 delete( [I<list>] )
142  
143 Remove objects from a C<Set::Object>.
144  
145 Removing the same object more than once, or removing an object absent
146 from the C<Set::Object> is not an error.
147  
148 Returns the number of elements that were actually removed.
149  
150 As of Set::Object 1.23, removing C<undef> is safe (but having an
151 C<undef> in the passed in list does not increase the return value,
152 because it could never be in the set)
153  
154 =head2 weaken
155  
156 Makes all the references in the set "weak" - that is, they do not
157 increase the reference count of the object they point to, just like
158 L<Scalar::Util|Scalar::Util>'s C<weaken> function.
159  
160 This was introduced with Set::Object 1.16, and uses a brand new type
161 of magic. B<Use with caution>. If you get segfaults when you use
162 C<weaken>, please reduce your problem to a test script before
163 submission.
164  
165 B<New:> as of Set::Object 1.19, you may use the C<weak_set> function
166 to make weak sets, or C<Set::Object::Weak-E<gt>new>, or import the
167 C<set> constructor from C<Set::Object::Weak> instead. See
168 L<Set::Object::Weak> for more.
169  
170 B<Note to people sub-classing C<Set::Object>:> this method re-blesses
171 the invocant to C<Set::Object::Weak>. Override the method C<weak_pkg>
172 in your sub-class to control this behaviour.
173  
174 =head2 is_weak
175  
176 Returns a true value if this set is a weak set.
177  
178 =head2 strengthen
179  
180 Turns a weak set back into a normal one.
181  
182 B<Note to people sub-classing C<Set::Object>:> this method re-blesses
183 the invocant to C<Set::Object>. Override the method C<strong_pkg> in
184 your sub-class to control this behaviour.
185  
186 =head2 invert( [I<list>] )
187  
188 For each item in I<list>, it either removes it or adds it to the set,
189 so that a change is always made.
190  
191 Also available as the overloaded operator C</>, in which case it
192 expects another set (or a single scalar element), and returns a new
193 set that is the original set with all the second set's items inverted.
194  
195 =head2 clear
196  
197 Empty this C<Set::Object>.
198  
199 =head2 as_string
200  
201 Return a textual Smalltalk-ish representation of the C<Set::Object>.
202 Also available as overloaded operator "".
203  
204 =head2 equal( I<set> )
205  
206 Returns a true value if I<set> contains exactly the same members as
207 the invocant.
208  
209 Also available as overloaded operator C<==> (or C<eq>).
210  
211 =head2 not_equal( I<set> )
212  
213 Returns a false value if I<set> contains exactly the same members as
214 the invocant.
215  
216 Also available as overloaded operator C<!=> (or C<ne>).
217  
218 =head2 intersection( [I<list>] )
219  
220 Return a new C<Set::Object> containing the intersection of the
221 C<Set::Object>s passed as arguments.
222  
223 Also available as overloaded operator C<*>.
224  
225 =head2 union( [I<list>] )
226  
227 Return a new C<Set::Object> containing the union of the
228 C<Set::Object>s passed as arguments.
229  
230 Also available as overloaded operator C<+>.
231  
232 =head2 difference ( I<set> )
233  
234 Return a new C<Set::Object> containing the members of the first
235 (invocant) set with the passed C<Set::Object>s' elements removed.
236  
237 Also available as overloaded operator C<->.
238  
239 =head2 unique ( I<set> )
240  
241 =head2 symmetric_difference ( I<set> )
242  
243 Return a new C<Set::Object> containing the members of all passed sets
244 (including the invocant), with common elements removed. This will be
245 the opposite (complement) of the I<intersection> of the two sets.
246  
247 Also available as overloaded operator C<%>.
248  
249 =head2 subset( I<set> )
250  
251 Return C<true> if this C<Set::Object> is a subset of I<set>.
252  
253 Also available as operator C<E<lt>=>.
254  
255 =head2 proper_subset( I<set> )
256  
257 Return C<true> if this C<Set::Object> is a proper subset of I<set>
258 Also available as operator C<E<lt>>.
259  
260 =head2 superset( I<set> )
261  
262 Return C<true> if this C<Set::Object> is a superset of I<set>.
263 Also available as operator C<E<gt>=>.
264  
265 =head2 proper_superset( I<set> )
266  
267 Return C<true> if this C<Set::Object> is a proper superset of I<set>
268 Also available as operator C<E<gt>>.
269  
270 =head2 is_null( I<set> )
271  
272 Returns a true value if this set does not contain any members, that
273 is, if its size is zero.
274  
275 =head1 Set::Scalar compatibility methods
276  
277 By and large, L<Set::Object> is not and probably never will be
278 feature-compatible with L<Set::Scalar>; however the following
279 functions are provided anyway.
280  
281 =head2 compare( I<set> )
282  
283 returns one of:
284  
285 "proper intersect"
286 "proper subset"
287 "proper superset"
288 "equal"
289 "disjoint"
290  
291 =head2 is_disjoint( I<set> )
292  
293 Returns a true value if the two sets have no common items.
294  
295 =head2 as_string_callback( I<set> )
296  
297 Allows you to define a custom stringify function. This is only a
298 class method. If you want anything fancier than this, you should
299 sub-class Set::Object.
300  
301  
302 =head1 FUNCTIONS
303  
304 The following functions are defined by the Set::Object XS code for
305 convenience; they are largely identical to the versions in the
306 Scalar::Util module, but there are a couple that provide functions not
307 catered to by that module.
308  
309 Please use the versions in L<Scalar::Util> in preference to these
310 functions. In fact, if you use these functions in your production
311 code then you may have to rewrite it some day. They are retained only
312 because they are "mostly harmless".
313  
314 =over
315  
316 =item B<blessed>
317  
318 B<Do not use in production code>
319  
320 Returns a true value if the passed reference (RV) is blessed. See
321 also L<Acme::Holy>.
322  
323 =item B<reftype>
324  
325 B<Do not use in production code>
326  
327 A bit like the perl built-in C<ref> function, but returns the I<type>
328 of reference; ie, if the reference is blessed then it returns what
329 C<ref> would have if it were not blessed. Useful for "seeing through"
330 blessed references.
331  
332 =item B<refaddr>
333  
334 B<Do not use in production code>
335  
336 Returns the memory address of a scalar. B<Warning>: this is I<not>
337 guaranteed to be unique for scalars created in a program; memory might
338 get re-used!
339  
340 =item B<is_int>, B<is_string>, B<is_double>
341  
342 B<Do not use in production code>
343  
344 A quick way of checking the three bits on scalars - IOK (is_int), NOK
345 (is_double) and POK (is_string). Note that the exact behaviour of
346 when these bits get set is not defined by the perl API.
347  
348 This function returns the "p" versions of the macro (SvIOKp, etc); use
349 with caution.
350  
351 =item B<is_overloaded>
352  
353 B<Do not use in production code>
354  
355 A quick way to check if an object has overload magic on it.
356  
357 =item B<ish_int>
358  
359 B<Deprecated and will be removed in 2014>
360  
361 This function returns true, if the value it is passed looks like it
362 I<already is> a representation of an I<integer>. This is so that you
363 can decide whether the value passed is a hash key or an array
364 index.
365  
366 =item B<is_key>
367  
368 B<Deprecated and will be removed in 2014>
369  
370 This function returns true, if the value it is passed looks more like
371 an I<index> to a collection than a I<value> of a collection. Similar
372 to the looks_like_number internal function, but weird. Avoid.
373  
374 =item B<get_magic>
375  
376 B<Do not use in production code>
377  
378 Pass to a scalar, and get the magick wand (C<mg_obj>) used by the weak
379 set implementation. The return will be a list of integers which are
380 pointers to the actual C<ISET> structure. Whatever you do don't
381 change the array :). This is used only by the test suite, and if you
382 find it useful for something then you should probably conjure up a
383 test suite and send it to me, otherwise it could get pulled.
384  
385 =back
386  
387 =head1 CLASS METHODS
388  
389 These class methods are probably only interesting to those
390 sub-classing C<Set::Object>.
391  
392 =over
393  
394 =item strong_pkg
395  
396 When a set that was already weak is strengthened using
397 C<-E<gt>strengthen>, it gets re-blessed into this package.
398  
399 =item weak_pkg
400  
401 When a set that was NOT already weak is weakened using
402 C<-E<gt>weaken>, it gets re-blessed into this package.
403  
404 =item tie_array_pkg
405  
406 When the object is accessed as an array, tie the array into this
407 package.
408  
409 =item tie_hash_pkg
410  
411 When the object is accessed as a hash, tie the hash into this package.
412  
413 =back
414  
415 =head1 SERIALIZATION
416  
417 It is possible to serialize C<Set::Object> objects via L<Storable> and
418 duplicate via C<dclone>; such support was added in release 1.04. As
419 of C<Set::Object> version 1.15, it is possible to freeze scalar items,
420 too.
421  
422 However, the support for freezing scalar items introduced a backwards
423 incompatibility. Earlier versions than 1.15 will C<thaw> sets frozen
424 using Set::Object 1.15 and later as a set with one item - an array
425 that contains the actual members.
426  
427 Additionally, version 1.15 had a bug that meant that it would not
428 detect C<freeze> protocol upgrades, instead reverting to pre-1.15
429 behaviour.
430  
431 C<Set::Object> 1.16 and above are capable of dealing correctly with
432 all serialized forms, as well as correctly aborting if a "newer"
433 C<freeze> protocol is detected during C<thaw>.
434  
435 =head1 PERFORMANCE
436  
437 The following benchmark compares C<Set::Object> with using a hash to
438 emulate a set-like collection (this is an old benchmark, but still
439 holds true):
440  
441 use Set::Object;
442  
443 package Obj;
444 sub new { bless { } }
445  
446 @els = map { Obj->new() } 1..1000;
447  
448 require Benchmark;
449  
450 Benchmark::timethese(100, {
451 'Control' => sub { },
452 'H insert' => sub { my %h = (); @h{@els} = @els; },
453 'S insert' => sub { my $s = Set::Object->new(); $s->insert(@els) },
454 } );
455  
456 %gh = ();
457 @gh{@els} = @els;
458  
459 $gs = Set::Object->new(@els);
460 $el = $els[33];
461  
462 Benchmark::timethese(100_000, {
463 'H lookup' => sub { exists $gh{33} },
464 'S lookup' => sub { $gs->includes($el) }
465 } );
466  
467 On my computer the results are:
468  
469 Benchmark: timing 100 iterations of Control, H insert, S insert...
470 Control: 0 secs ( 0.01 usr 0.00 sys = 0.01 cpu)
471 (warning: too few iterations for a reliable count)
472 H insert: 68 secs (67.81 usr 0.00 sys = 67.81 cpu)
473 S insert: 9 secs ( 8.81 usr 0.00 sys = 8.81 cpu)
474 Benchmark: timing 100000 iterations of H lookup, S lookup...
475 H lookup: 7 secs ( 7.14 usr 0.00 sys = 7.14 cpu)
476 S lookup: 6 secs ( 5.94 usr 0.00 sys = 5.94 cpu)
477  
478 =head1 THREAD SAFETY
479  
480 This module is not thread-safe.
481  
482 =head1 AUTHOR
483  
484 Original Set::Object module by Jean-Louis Leroy, <jll@skynet.be>
485  
486 Set::Scalar compatibility, XS debugging, weak references support
487 courtesy of Sam Vilain, <samv@cpan.org>.
488  
489 New maintainer is Reini Urban <rurban@cpan.org>.
490 Patches against L<https://github.com/rurban/Set-Object/> please.
491 Tickets at RT L<https://rt.cpan.org/Public/Dist/Display.html?Name=Set-Object>
492  
493 =head1 LICENCE
494  
495 Copyright (c) 1998-1999, Jean-Louis Leroy. All Rights Reserved.
496 This module is free software. It may be used, redistributed
497 and/or modified under the terms of the Perl Artistic License, either the
498 original, or at your option, any later version.
499  
500 Portions Copyright (c) 2003 - 2005, Sam Vilain. Same license.
501  
502 Portions Copyright (c) 2006, 2007, Catalyst IT (NZ) Limited. This
503 module is free software. It may be used, redistributed and/or modified
504 under the terms of the Perl Artistic License
505  
506 Portions Copyright (c) 2013, cPanel. Same license.
507 Portions Copyright (c) 2020, Reini Urban. Same license.
508  
509 =head1 SEE ALSO
510  
511 perl(1), perltie(1), L<Set::Scalar>, L<overload>
512  
513 =cut
514  
515 package Set::Object;
516  
517 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
518 42 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
519 42 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
520  
521 42 require Exporter;
522 42 require DynaLoader;
523 42 require AutoLoader;
524  
525 42 @ISA = qw(Exporter DynaLoader);
526 # Items to export into callers namespace by default. Note: do not export
527 # names by default without a very good reason. Use EXPORT_OK instead.
528 # Do not simply export all your public functions/methods/constants.
529  
530 42 @EXPORT_OK = qw( ish_int is_int is_string is_double blessed reftype
531 refaddr is_overloaded is_object is_key set weak_set );
532 42 $VERSION = '1.41';
533  
534 42 bootstrap Set::Object $VERSION;
535  
536 # Preloaded methods go here.
537  
538 42 our $cust_disp;
539  
540 sub as_string
541 {
542 128 ▶ return $cust_disp->(@_) if $cust_disp;
Subroutine as_string: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $Set::Object::cust_disp 24 104 128
543 104 my $self = shift;
544 104 ▶ croak "Tried to use as_string on something other than a Set::Object"
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($self, __PACKAGE__) 1 103 104
545 unless (UNIVERSAL::isa($self, __PACKAGE__));
546  
547 103 ref($self).'(' . (join ' ', sort { $a cmp $b }
548 $self->members) . ')'
549 }
550  
551 sub equal
552 {
553 42 ▶ my ($s1, $s2) = @_;
Subroutine equal: called CC=3 SCAR=11.0
Pod documented
554 42 ▶ return undef unless (UNIVERSAL::isa($s2, __PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($s2, __PACKAGE__) 4 38 42
555  
556 38 ▶ $s1->size() == $s2->size() && $s1->includes($s2->members);
Branch: 1 branch
BranchTrueFalseTotal
$s1->size == $s2->size and $s1->includes($s2->members) 35 3 38
557 }
558  
559 sub not_equal
560 {
561 5 ▶ !shift->equal(shift);
Subroutine not_equal: called CC=1 SCAR=0.0
Pod documented
562 }
563  
564 sub union
565 {
566 $_[0]->set
567 87 ( map { $_->members() }
568 44 ▶ grep { UNIVERSAL::isa($_, __PACKAGE__) }
Subroutine union: called CC=1 SCAR=0.0
Pod documented
569 @_ );
570 }
571  
572 sub op_union
573 {
574 19 ▶ my $self = shift;
Subroutine op_union: called CC=4 SCAR=14.2
Pod undocumented
575 19 my $other;
576 19 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 11 8 19
577 11 $other = shift;
578 } else {
579 8 $other = $self->set(shift);
580 }
581  
582 19 ▶ croak("Tried to form union between Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
if ref $other and not UNIVERSAL::isa($other, __PACKAGE__) 0 19 19
Condition33%1/3
ref $other and not UNIVERSAL::isa($other, __PACKAGE__)
!ll&&!rl&&r
0190
MC/DC0%0/2
ref $other and not UNIVERSAL::isa($other, __PACKAGE__)
ref $other not UNIVERSAL::isa($other, __PACKAGE__)
Truth table33%1/3
A and not(B)
A= ref $otherB= not UNIVERSAL::isa($other, __PACKAGE__)
ABresult
0X0
100
111
583 ."`$other'")
584 if ref $other and not UNIVERSAL::isa($other, __PACKAGE__);
585  
586 19 $self->union($other);
587  
588 }
589  
590 sub intersection
591 {
592 24 ▶ my $s = shift;
Subroutine intersection: called CC=5 SCAR=16.6
Pod documented
593 24 my $rem = $s->set($s->members);
594  
595 24 ▶ while ($s = shift)
Branch: 1 branch
BranchTrueFalseTotal
if ($s = shift()) 25 22 47
596 {
597 25 ▶ if (!ref $s) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $s) 0 25 25
598 0 $s = $rem->new($s);
599 }
600  
601 25 ▶ croak("Tried to form intersection between Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($s, __PACKAGE__) 2 23 25
Condition33%1/3
ref $s || $s
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $s || $s
ref $s $s
Truth table33%1/3
A || B
A= ref $sB= $s
ABresult
1X1
011
000
602 .(ref($s)||$s)) unless UNIVERSAL::isa($s, __PACKAGE__);
603  
604 23 $rem->remove(grep { !$s->includes($_) } $rem->members);
605 }
606  
607 22 $rem;
608 }
609  
610 sub op_intersection
611 {
612 17 ▶ my $s1 = shift;
Subroutine op_intersection: called CC=3 SCAR=11.0
Pod undocumented
613 17 my $s2;
614 17 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 13 4 17
615 13 $s2 = shift;
616 } else {
617 4 $s2 = $s1->set(shift);
618 }
619 17 my $r = shift;
620 17 ▶ if ( $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 2 15 17
621 2 return intersection($s2, $s1);
622 } else {
623 15 return intersection($s1, $s2);
624 }
625  
626 }
627  
628 sub difference
629 {
630 62 ▶ my ($s1, $s2, $r) = @_;
Subroutine difference: called CC=8 SCAR=22.1
Pod documented
631 62 ▶ if ( ! ref $s2 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $s2) 6 56 62
632 6 ▶ if ( is_int($s2) and !is_string($s2) and $s2 == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_int($s2) and not &is_string($s2) and $s2 == 0) { } 0 6 6
Condition33%2/6
&is_int($s2) and not &is_string($s2) and $s2 == 0
!ll&&!rl&&r
600
&is_int($s2) and not &is_string($s2)
!ll&&!rl&&r
600
MC/DC0%0/3
&is_int($s2) and not &is_string($s2) and $s2 == 0
&is_int($s2) not &is_string($s2) $s2 == 0
Truth table25%1/4
A and not(B) and C
A= &is_int($s2)B= not &is_string($s2)C= $s2 == 0
ABCresult
0XX0
10X0
1100
1111
633 0 return __PACKAGE__->new();
634 } else {
635 6 my $set = __PACKAGE__->new($s2);
636 6 $s2 = $set;
637 }
638 }
639 62 ▶ croak("Tried to find difference between Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($s2, __PACKAGE__) 2 60 62
Condition33%1/3
ref $s2 || $s2
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $s2 || $s2
ref $s2 $s2
Truth table33%1/3
A || B
A= ref $s2B= $s2
ABresult
1X1
011
000
640 .(ref($s2)||$s2)) unless UNIVERSAL::isa($s2, __PACKAGE__);
641  
642 60 my $s;
643 60 ▶ if ( $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 2 58 60
644 2 $s = $s2->set( grep { !$s1->includes($_) } $s2->members );
645 } else {
646 58 $s = $s1->set( grep { !$s2->includes($_) } $s1->members );
647 }
648 60 $s;
649 }
650  
651 sub op_invert
652 {
653 4 ▶ my $self = shift;
Subroutine op_invert: called CC=4 SCAR=14.1
Pod undocumented
654 4 my $other;
655 4 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 1 3 4
656 1 $other = shift;
657 } else {
658 3 $other = __PACKAGE__->new(shift);
659 }
660  
661 4 ▶ croak("Tried to form union between Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
if ref $other and not UNIVERSAL::isa($other, __PACKAGE__) 0 4 4
Condition33%1/3
ref $other and not UNIVERSAL::isa($other, __PACKAGE__)
!ll&&!rl&&r
040
MC/DC0%0/2
ref $other and not UNIVERSAL::isa($other, __PACKAGE__)
ref $other not UNIVERSAL::isa($other, __PACKAGE__)
Truth table33%1/3
A and not(B)
A= ref $otherB= not UNIVERSAL::isa($other, __PACKAGE__)
ABresult
0X0
100
111
662 ."`$other'")
663 if ref $other and not UNIVERSAL::isa($other, __PACKAGE__);
664  
665 4 my $result = $self->set( $self->members() );
666 4 $result->invert( $other->members() );
667 4 return $result;
668  
669 }
670  
671 sub op_symm_diff
672 {
673 11 ▶ my $self = shift;
Subroutine op_symm_diff: called CC=2 SCAR=6.9
Pod undocumented
674 11 my $other;
675 11 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 7 4 11
676 7 $other = shift;
677 } else {
678 4 $other = __PACKAGE__->new(shift);
679 }
680 11 return $self->symmetric_difference($other);
681 }
682  
683 sub unique {
684 4 ▶ my $self = shift;
Subroutine unique: called CC=1 SCAR=0.0
Pod documented
685 4 $self->symmetric_difference(@_);
686 }
687  
688 sub symmetric_difference
689 {
690 19 ▶ my ($s1, $s2) = @_;
Subroutine symmetric_difference: called CC=3 SCAR=11.4
Pod documented
691 19 ▶ croak("Tried to find symmetric difference between Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($s2, __PACKAGE__) 2 17 19
Condition33%1/3
ref $s2 || $s2
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $s2 || $s2
ref $s2 $s2
Truth table33%1/3
A || B
A= ref $s2B= $s2
ABresult
1X1
011
000
692 .(ref($s2)||$s2)) unless UNIVERSAL::isa($s2, __PACKAGE__);
693  
694 17 $s1->difference( $s2 )->union( $s2->difference( $s1 ) );
695 }
696  
697 sub proper_subset
698 {
699 16 ▶ my ($s1, $s2) = @_;
Subroutine proper_subset: called CC=4 SCAR=14.2
Pod documented
700 16 ▶ croak("Tried to find proper subset of Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($s2, __PACKAGE__) 2 14 16
Condition33%1/3
ref $s2 || $s2
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $s2 || $s2
ref $s2 $s2
Truth table33%1/3
A || B
A= ref $s2B= $s2
ABresult
1X1
011
000
701 .(ref($s2)||$s2)) unless UNIVERSAL::isa($s2, __PACKAGE__);
702 14 ▶ $s1->size < $s2->size && $s1->subset( $s2 );
Branch: 1 branch
BranchTrueFalseTotal
$s1->size < $s2->size and $s1->subset($s2) 8 6 14
703 }
704  
705 sub subset
706 {
707 22 ▶ my ($s1, $s2, $r) = @_;
Subroutine subset: called CC=3 SCAR=11.4
Pod documented
708 22 ▶ croak("Tried to find subset of Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($s2, __PACKAGE__) 2 20 22
Condition33%1/3
ref $s2 || $s2
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $s2 || $s2
ref $s2 $s2
Truth table33%1/3
A || B
A= ref $s2B= $s2
ABresult
1X1
011
000
709 .(ref($s2)||$s2)) unless UNIVERSAL::isa($s2, __PACKAGE__);
710 20 $s2->includes($s1->members);
711 }
712  
713 sub proper_superset
714 {
715 9 ▶ my ($s1, $s2, $r) = @_;
Subroutine proper_superset: called CC=3 SCAR=11.4
Pod documented
716 9 ▶ croak("Tried to find proper superset of Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($s2, __PACKAGE__) 2 7 9
Condition33%1/3
ref $s2 || $s2
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $s2 || $s2
ref $s2 $s2
Truth table33%1/3
A || B
A= ref $s2B= $s2
ABresult
1X1
011
000
717 .(ref($s2)||$s2)) unless UNIVERSAL::isa($s2, __PACKAGE__);
718 7 proper_subset( $s2, $s1 );
719 }
720  
721 sub superset
722 {
723 8 ▶ my ($s1, $s2) = @_;
Subroutine superset: called CC=3 SCAR=11.4
Pod documented
724 8 ▶ croak("Tried to find superset of Set::Object & "
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($s2, __PACKAGE__) 2 6 8
Condition33%1/3
ref $s2 || $s2
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $s2 || $s2
ref $s2 $s2
Truth table33%1/3
A || B
A= ref $s2B= $s2
ABresult
1X1
011
000
725 .(ref($s2)||$s2)) unless UNIVERSAL::isa($s2, __PACKAGE__);
726 6 subset( $s2, $s1 );
727 }
728  
729 # following code pasted from Set::Scalar; thanks Jarkko Hietaniemi
730  
731 use overload
732 '""' => \&as_string,
733 '+' => \&op_union,
734 '*' => \&op_intersection,
735 '%' => \&op_symm_diff,
736 '/' => \&op_invert,
737 '-' => \&difference,
738 '==' => \&equal,
739 '!=' => \&not_equal,
740 '<' => \&proper_subset,
741 '>' => \&proper_superset,
742 '<=' => \&subset,
743 '>=' => \&superset,
744 0 ▶ '%{}' => sub { my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
745 0 my %h = {};
746 0 tie %h, $self->tie_hash_pkg, [], $self;
747 0 \%h },
748 14 ▶ '@{}' => sub { my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
749 14 my @h = {};
750 14 tie @h, $self->tie_array_pkg, [], $self;
751 14 \@h },
752 47 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
753 42 fallback => 1,
754 42 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
755  
756 0 ▶sub tie_hash_pkg { "Set::Object::TieHash" };
Subroutine tie_hash_pkg: not called CC=1 SCAR=6.9
Pod documented
757 14 ▶sub tie_array_pkg { "Set::Object::TieArray" };
Subroutine tie_array_pkg: called CC=1 SCAR=0.0
Pod documented
758  
759 { package Set::Object::TieArray;
760 sub TIEARRAY {
761 14 ▶ my $p = shift;
Subroutine TIEARRAY: called CC=1 SCAR=0.0
762 14 my $tie = bless [ @_ ], $p;
763 14 require Scalar::Util;
764 14 Scalar::Util::weaken($tie->[0]);
765 14 Scalar::Util::weaken($tie->[1]);
766 14 return $tie;
767 }
768 # note the sort here
769 sub promote {
770 16 ▶ my $self = shift;
Subroutine promote: called CC=1 SCAR=0.0
771 16 @{$self->[0]} = sort $self->[1]->members;
772 16 return $self->[0];
773 }
774 sub commit {
775 6 ▶ my $self = shift;
Subroutine commit: called CC=1 SCAR=0.0
776 6 $self->[1]->clear;
777 6 $self->[1]->insert(@{$self->[0]});
778 }
779 sub FETCH {
780 10 ▶ my $self = shift;
Subroutine FETCH: called CC=1 SCAR=0.0
781 10 my $index = shift;
782 10 $self->promote->[$index];
783 }
784 sub STORE {
785 1 ▶ my $self = shift;
Subroutine STORE: called CC=1 SCAR=0.0
786 1 my $index = shift;
787 1 $self->promote->[$index] = shift;
788 1 $self->commit;
789 }
790 sub FETCHSIZE {
791 5 ▶ my $self = shift;
Subroutine FETCHSIZE: called CC=1 SCAR=0.0
792 5 return $self->[1]->size;
793 }
794 sub STORESIZE {
795 1 ▶ my $self = shift;
Subroutine STORESIZE: called CC=1 SCAR=0.0
796 1 my $count = shift;
797 1 $#{$self->promote}=$count-1;
798 1 $self->commit;
799 }
800 ▶ sub EXTEND {
Subroutine EXTEND: not called CC=1 SCAR=0.0
801 }
802 sub EXISTS {
803 1 ▶ my $self = shift;
Subroutine EXISTS: called CC=2 SCAR=7.4
804 1 my $index = shift;
805 1 ▶ if ( $index+1 > $self->[1]->size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index + 1 > $self->[1]->size) { } 1 0 1
806 1 return undef;
807 } else {
808 0 return 1;
809 }
810 }
811 sub DELETE {
812 1 ▶ my $self = shift;
Subroutine DELETE: called CC=1 SCAR=0.0
813 1 delete $self->promote->[(shift)];
814 1 $self->commit;
815 }
816 sub PUSH {
817 1 ▶ my $self = shift;
Subroutine PUSH: called CC=1 SCAR=0.0
818 1 $self->[1]->insert(@_);
819 }
820 sub POP {
821 1 ▶ my $self = shift;
Subroutine POP: called CC=1 SCAR=0.0
822 1 my $rv = pop @{$self->promote};
823 1 $self->commit;
824 1 return $rv;
825 }
826 sub CLEAR {
827 0 ▶ my $self = shift;
Subroutine CLEAR: not called CC=1 SCAR=6.9
828 0 $self->[1]->clear;
829 }
830 sub SHIFT {
831 1 ▶ my $self = shift;
Subroutine SHIFT: called CC=1 SCAR=0.0
832 1 my $rv = shift @{$self->promote};
833 1 $self->commit;
834 1 return $rv;
835 }
836 sub UNSHIFT {
837 1 ▶ my $self = shift;
Subroutine UNSHIFT: called CC=1 SCAR=0.0
838 1 $self->[1]->insert(@_);
839 }
840 sub SPLICE {
841 1 ▶ my $self = shift;
Subroutine SPLICE: called CC=3 SCAR=12.7
842 1 my @rv;
843 # perl5--
844 1 ▶ if ( @_ == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 1 1
elsif (@_ == 2) { } 1 0 1
845 0 splice @{$self->promote}, $_[0];
846 }
847 elsif ( @_ == 2 ) {
848 1 splice @{$self->promote}, $_[0], $_[1];
849 }
850 else {
851 0 splice @{$self->promote}, $_[0], $_[1], @_;
852 }
853 1 $self->commit;
854 1 @rv;
855 }
856 }
857  
858 42 { package Set::Object::TieHash;
859 sub TIEHASH {
860 0 ▶ my $p = shift;
Subroutine TIEHASH: not called CC=1 SCAR=6.9
861 0 my $tie = bless [ @_ ], $p;
862 0 require Scalar::Util;
863 0 Scalar::Util::weaken($tie->[0]);
864 0 Scalar::Util::weaken($tie->[1]);
865 0 return $tie;
866 }
867 sub FETCH {
868 0 ▶ my $self = shift;
Subroutine FETCH: not called CC=1 SCAR=6.9
869 0 return $self->[1]->includes(shift);
870 }
871 sub STORE {
872 0 ▶ my $self = shift;
Subroutine STORE: not called CC=2 SCAR=17.9
873 0 my $item = shift;
874 0 ▶ if ( shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift()) { } 0 0 0
875 0 $self->[1]->insert($item);
876 } else {
877 0 $self->[1]->remove($item);
878 }
879 }
880 sub DELETE {
881 0 ▶ my $self = shift;
Subroutine DELETE: not called CC=1 SCAR=6.9
882 0 my $item = shift;
883 0 $self->[1]->remove($item);
884 }
885 sub CLEAR {
886 0 ▶ my $self = shift;
Subroutine CLEAR: not called CC=1 SCAR=6.9
887 0 $self->[1]->clear;
888 }
889 sub EXISTS {
890 0 ▶ my $self = shift;
Subroutine EXISTS: not called CC=1 SCAR=6.9
891 0 $self->[1]->includes(shift);
892 }
893 sub FIRSTKEY {
894 0 ▶ my $self = shift;
Subroutine FIRSTKEY: not called CC=1 SCAR=6.9
895 0 @{$self->[0]} = $self->[1]->members;
896 0 $self->NEXTKEY;
897 }
898 sub NEXTKEY {
899 0 ▶ my $self = shift;
Subroutine NEXTKEY: not called CC=2 SCAR=17.9
900 0 ▶ if ( @{$self->[0]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[0];}) { } 0 0 0
901 0 return (shift @{$self->[0]});
902 } else {
903 0 return ();
904 }
905 }
906 sub SCALAR {
907 0 ▶ my $self = shift;
Subroutine SCALAR: not called CC=1 SCAR=6.9
908 0 $self->[1]->size;
909 }
910 }
911  
912 # Autoload methods go after =cut, and are processed by the autosplit program.
913 # This function is used to differentiate between an integer and a
914 # string for use by the hash container types
915  
916  
917 # This function is not from Scalar::Util; it is a DWIMy function to
918 # decide whether the passed thingy could reasonably be considered
919 # to be an array index, and if so returns the index
920 42 sub ish_int {
921 26 ▶ my $i;
Subroutine ish_int: called CC=5 SCAR=16.1
Pod documented
922 26 local $@;
923 26 eval { $i = _ish_int($_[0]) };
924  
925 26 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 4 22 26
926 4 ▶ if ($@ =~ /overload/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@ =~ /overload/i) { } 3 1 4
elsif ($@ =~ /tie/i) { } 1 0 1
927 3 ▶ if (my $sub = UNIVERSAL::can($_[0], "(0+")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = UNIVERSAL::can($_[0], '(0+')) { } 1 2 3
928 1 return ish_int(&$sub($_[0]));
929 } else {
930 2 return undef;
931 }
932 } elsif ($@ =~ /tie/i) {
933 1 my $x = $_[0];
934 1 return ish_int($x);
935 }
936 } else {
937 22 return $i;
938 }
939 }
940  
941 # returns true if the value looks like a key, not an object or a
942 # collection
943 sub is_key {
944 15 ▶ if (my $class = tied $_[0]) {
Subroutine is_key: called CC=10 SCAR=23.2
Pod documented
Branch: 3 branches
BranchTrueFalseTotal
if (my $class = tied $_[0]) { } 1 14 15
elsif (&is_overloaded($_[0])) { } 5 9 14
elsif (&is_int($_[0]) or &is_string($_[0]) or &is_double($_[0])) { } 7 2 9
945 1 ▶ if ($class =~ m/^Tangram::/) { # hack for Tangram RefOnDemands
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /^Tangram::/) { } 0 1 1
946 0 return undef;
947 } else {
948 1 my $x = $_[0];
949 1 return is_key($x);
950 }
951 } elsif (is_overloaded($_[0])) {
952 # this is a bit of a hack - intrude into the overload internal
953 # space
954 5 ▶ if (my $sub = UNIVERSAL::can($_[0], "(0+")) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $sub = UNIVERSAL::can($_[0], '(0+')) { } 1 4 5
elsif ($sub = UNIVERSAL::can($_[0], '(""')) { } 2 2 4
elsif ($sub = UNIVERSAL::can($_[0], '(nomethod')) { } 0 2 2
955 1 return is_key(&$sub($_[0]));
956 } elsif ($sub = UNIVERSAL::can($_[0], '(""')) {
957 2 return is_key(&$sub($_[0]));
958 } elsif ($sub = UNIVERSAL::can($_[0], '(nomethod')) {
959 0 return is_key(&$sub($_[0]));
960 } else {
961 2 return undef;
962 }
963 ▶ } elsif (is_int($_[0]) || is_string($_[0]) || is_double($_[0])) {
Condition100%6/6
&is_int($_[0]) or &is_string($_[0]) or &is_double($_[0])
l!l&&r!l&&!r
612
&is_int($_[0]) or &is_string($_[0])
l!l&&r!l&&!r
333
MC/DC100%3/3
&is_int($_[0]) or &is_string($_[0]) or &is_double($_[0])
&is_int($_[0]) &is_string($_[0]) &is_double($_[0])
Truth table100%4/4
A or B or C
A= &is_int($_[0])B= &is_string($_[0])C= &is_double($_[0])
ABCresult
1XX1
01X1
0011
0000
964 7 return 1;
965 } else {
966 2 return undef;
967 }
968 }
969  
970 # interface so that Storable may still work
971 sub STORABLE_freeze {
972 2005 ▶ my $obj = shift;
Subroutine STORABLE_freeze: called CC=2 SCAR=6.9
Pod undocumented
973 2005 my $am_cloning = shift;
974 2005 ▶ return ("v3-" . ($obj->is_weak ? "w" : "s"), [ $obj->members ]);
Branch: 1 branch
BranchTrueFalseTotal
$obj->is_weak ? : 1 2004 2005
975 }
976  
977 #use Devel::Peek qw(Dump);
978  
979 sub STORABLE_thaw {
980 #print Dump $_ foreach (@_);
981  
982 2005 ▶ if ( $_[2] ) {
Subroutine STORABLE_thaw: called CC=5 SCAR=17.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) 2005 0 2005
983 2005 ▶ if ( $_[2] eq "v2" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[2] eq 'v2') { } 0 2005 2005
elsif ($_[2] =~ /^v3-(w|s)/) { } 2005 0 2005
984 0 @_ = (@_[0,1], "", @{ $_[3] });
985 }
986 elsif ( $_[2] =~ m/^v3-(w|s)/ ) {
987 2005 @_ = (@_[0,1], "", @{ $_[3] });
988 2005 ▶ if ( $1 eq "w" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "w") 1 2004 2005
989 1 my $self = shift;
990 1 $self->_STORABLE_thaw(@_);
991 1 $self->weaken();
992 1 return;
993 }
994 } else {
995 0 croak("Unrecognised Set::Object Storable version $_[2]");
996 }
997 }
998  
999 2004 goto &_STORABLE_thaw;
1000 #print "Got here\n";
1001 }
1002  
1003 sub delete {
1004 2 ▶ my $self = shift;
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
1005 2 return $self->remove(@_);
1006 }
1007  
1008 42 our $AUTOLOAD;
1009 sub AUTOLOAD {
1010 0 ▶ croak "No such method $AUTOLOAD";
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
1011 }
1012  
1013 sub invert {
1014 6 ▶ my $self = shift;
Subroutine invert: called CC=4 SCAR=13.9
Pod documented
1015 6 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 13 6 19
1016 13 my $sv = shift;
1017 13 ▶ defined $sv or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $sv or next 0 13 13
1018 13 ▶ if ( $self->includes($sv) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->includes($sv)) { } 4 9 13
1019 4 $self->remove($sv);
1020 } else {
1021 9 $self->insert($sv);
1022 }
1023 }
1024 }
1025  
1026 sub compare {
1027 3 ▶ my $self = shift;
Subroutine compare: called CC=8 SCAR=23.0
Pod documented
1028 3 my $other = shift;
1029  
1030 3 ▶ return "apples, oranges" unless UNIVERSAL::isa($other, __PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($other, __PACKAGE__) 0 3 3
1031  
1032 3 my $only_self = $self - $other;
1033 3 my $only_other = $other - $self;
1034 3 my $intersect = $self * $other;
1035  
1036 3 ▶ if ( $intersect->size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($intersect->size) { } 1 2 3
1037 1 ▶ if ( $only_self->size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($only_self->size) { } 1 0 1
1038 1 ▶ if ( $only_other->size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($only_other->size) { } 1 0 1
1039 1 return "proper intersect";
1040 } else {
1041 0 return "proper subset";
1042 }
1043 } else {
1044 0 ▶ if ( $only_other->size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($only_other->size) { } 0 0 0
1045 0 return "proper superset";
1046 } else {
1047 0 return "equal";
1048 }
1049 }
1050 } else {
1051 2 ▶ if ($self->size || $other->size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->size or $other->size) { } 1 1 2
Condition66%2/3
$self->size or $other->size
l!l&&r!l&&!r
101
MC/DC50%1/2
$self->size or $other->size
$self->size $other->size
Truth table66%2/3
A or B
A= $self->sizeB= $other->size
ABresult
1X1
011
000
1052 1 return "disjoint";
1053 } else {
1054 # both sets are empty
1055 1 return "equal";
1056 }
1057 }
1058 }
1059  
1060 sub is_disjoint {
1061 1 ▶ my $self = shift;
Subroutine is_disjoint: called CC=2 SCAR=7.0
Pod documented
1062 1 my $other = shift;
1063  
1064 1 ▶ return "apples, oranges" unless UNIVERSAL::isa($other, __PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($other, __PACKAGE__) 0 1 1
1065 1 return !($self*$other)->size;
1066 }
1067  
1068 #use Data::Dumper;
1069 sub as_string_callback {
1070 6 ▶ shift;
Subroutine as_string_callback: called CC=4 SCAR=13.9
Pod documented
1071 6 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 1 6
1072 5 $cust_disp = shift;
1073 5 ▶ if ( $cust_disp &&
Branch: 1 branch
BranchTrueFalseTotal
if ($Set::Object::cust_disp and $Set::Object::cust_disp == \&Set::Object::as_string) 1 4 5
Condition100%3/3
$Set::Object::cust_disp and $Set::Object::cust_disp == \&Set::Object::as_string
!ll&&!rl&&r
131
MC/DC100%2/2
$Set::Object::cust_disp and $Set::Object::cust_disp == \&Set::Object::as_string
$Set::Object::cust_disp $Set::Object::cust_disp == \&Set::Object::as_string
Truth table100%3/3
A and B
A= $Set::Object::cust_dispB= $Set::Object::cust_disp == \&Set::Object::as_string
ABresult
0X0
100
111
1074 $cust_disp == \&as_string ) {
1075 1 undef($cust_disp);
1076 }
1077 } else {
1078 1 \&as_string;
1079 }
1080 }
1081  
1082 sub elements {
1083 4 ▶ my $self = shift;
Subroutine elements: called CC=1 SCAR=0.0
Pod documented
1084 4 return $self->members(@_);
1085 }
1086  
1087 2 ▶sub has { (shift)->includes(@_) }
Subroutine has: called CC=1 SCAR=0.0
Pod documented
1088 1 ▶sub contains { (shift)->includes(@_) }
Subroutine contains: called CC=1 SCAR=0.0
Pod documented
1089 1 ▶sub element { (shift)->member(@_) }
Subroutine element: called CC=1 SCAR=0.0
Pod documented
1090 sub member {
1091 3 ▶ my $self = shift;
Subroutine member: called CC=2 SCAR=6.9
Pod documented
1092 3 my $item = shift;
1093 3 ▶ return ( $self->includes($item) ?
Branch: 1 branch
BranchTrueFalseTotal
$self->includes($item) ? : 2 1 3
1094 $item : undef );
1095 }
1096  
1097 sub set {
1098 147 ▶ local $@;
Subroutine set: called CC=2 SCAR=6.9
Pod documented
1099 147 ▶ if (eval { $_[0]->isa(__PACKAGE__) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $_[0]->isa(__PACKAGE__) } }) 134 13 147
1100 134 shift;
1101 }
1102 147 __PACKAGE__->new(@_);
1103 }
1104 sub weak_set {
1105 4 ▶ my $self = __PACKAGE__->new();
Subroutine weak_set: called CC=1 SCAR=0.0
Pod documented
1106 4 $self->weaken;
1107 4 $self->insert(@_);
1108 4 return $self;
1109 }
1110  
1111 42 require Set::Object::Weak;
1112 sub weaken {
1113 19 ▶ my $self = shift;
Subroutine weaken: called CC=1 SCAR=0.0
Pod documented
1114 19 $self->_weaken;
1115 19 bless $self, $self->weak_pkg;
1116 }
1117  
1118 sub strengthen {
1119 1 ▶ my $self = shift;
Subroutine strengthen: called CC=1 SCAR=0.0
Pod documented
1120 1 $self->_strengthen;
1121 1 bless $self, $self->strong_pkg;
1122 }
1123  
1124 sub weak_pkg {
1125 19 ▶ "Set::Object::Weak";
Subroutine weak_pkg: called CC=1 SCAR=0.0
Pod documented
1126 }
1127 sub strong_pkg {
1128 7 ▶ "Set::Object";
Subroutine strong_pkg: called CC=1 SCAR=0.0
Pod documented
1129 }
1130 42 1;
1131  
1132 __END__
↑ Summary blib/lib/Set/Object/Weak.pm »