| 1 | package Set::Tiny; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | require Exporter; | |||||||||||||||||||||||||||
| 7 | 2 | @Set::Tiny::ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 8 | 2 | @Set::Tiny::EXPORT_OK = qw(set); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | $Set::Tiny::VERSION = '0.03'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||||||||||
| 13 | 25 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 25 | my %self; | |||||||||||||||||||||||||||
| 15 | 25 | @self{@_} = (); | |||||||||||||||||||||||||||
| 16 | 25 | return bless \%self, $class; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub set { | ||||||||||||||||||||||||||||
| 20 | 3 | ▶ | if ( ref( $_[ 0 ] ) ne '' ) { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 1 | return Set::Tiny->new( @{ $_[ 0 ] } ); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||
| 24 | 2 | return Set::Tiny->new(@_); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 97 | ▶ | sub as_string { "(" . join(" ", sort keys %{$_[0]}) . ")" } | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 30 | ▶ | sub size { scalar keys %{$_[0]} } | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | ▶ | sub element { exists $_[0]->{$_[1]} ? $_[1] : () } | ||||||||||||||||||||||||||
|
Subroutine
element: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | sub elements { keys %{$_[0]} } | ||||||||||||||||||||||||||
|
Subroutine
elements: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub contains { | ||||||||||||||||||||||||||||
| 37 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
contains: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 19 | ▶ | exists $self->{$_} or return for @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 15 | return 1; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub clone { | ||||||||||||||||||||||||||||
| 43 | 9 | ▶ | my $class = ref $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 9 | return $class->new( keys %{$_[0]} ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub clear { | ||||||||||||||||||||||||||||
| 48 | 2 | ▶ | %{$_[0]} = (); | ||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 2 | return $_[0]; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | sub insert { | ||||||||||||||||||||||||||||
| 53 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 1 | @{$self}{@_} = (); | |||||||||||||||||||||||||||
| 55 | 1 | return $self; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub remove { | ||||||||||||||||||||||||||||
| 59 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
remove: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 7 | delete @{$self}{@_}; | |||||||||||||||||||||||||||
| 61 | 7 | return $self; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub invert { | ||||||||||||||||||||||||||||
| 65 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
invert: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 3 | ▶ | exists $self->{$_} ? delete $self->{$_} : ($self->{$_} = undef) for @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 3 | return $self; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | sub is_null { ! %{$_[0]} } | ||||||||||||||||||||||||||
|
Subroutine
is_null: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 15 | ▶ | sub is_subset { $_[1]->contains( keys %{$_[0]} ) } | ||||||||||||||||||||||||||
|
Subroutine
is_subset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | ▶ | sub is_proper_subset { $_[0]->size < $_[1]->size && $_[0]->is_subset($_[1]) } | ||||||||||||||||||||||||||
|
Subroutine
is_proper_subset: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | sub is_superset { $_[1]->is_subset($_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
is_superset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 4 | ▶ | sub is_proper_superset { $_[0]->size > $_[1]->size && $_[1]->is_subset($_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
is_proper_superset: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | ▶ | sub is_equal { $_[1]->is_subset($_[0]) && $_[0]->is_subset($_[1]) } | ||||||||||||||||||||||||||
|
Subroutine
is_equal: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 7 | ▶ | sub is_disjoint { ! $_[0]->intersection($_[1])->size } | ||||||||||||||||||||||||||
|
Subroutine
is_disjoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub is_properly_intersecting { | ||||||||||||||||||||||||||||
| 85 | 4 | ▶ | ! $_[0]->is_disjoint($_[1]) | ||||||||||||||||||||||||||
|
Subroutine
is_properly_intersecting: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
Condition100%3/3
not $_[0]->is_disjoint($_[1]) and $_[0]->difference($_[1])->size
MC/DC100%2/2
not $_[0]->is_disjoint($_[1]) and $_[0]->difference($_[1])->size
not $_[0]->is_disjoint($_[1])
$_[0]->difference($_[1])->size
Truth table100%3/3
not(A) and B
A= not $_[0]->is_disjoint($_[1])B= $_[0]->difference($_[1])->size
| |||||||||||||||||||||||||||||
| 86 | && $_[0]->difference($_[1])->size | ||||||||||||||||||||||||||||
| 87 | && $_[1]->difference($_[0])->size | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 5 | ▶ | sub difference { $_[0]->clone->remove(keys %{$_[1]}) } | ||||||||||||||||||||||||||
|
Subroutine
difference: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub union { | ||||||||||||||||||||||||||||
| 93 | 1 | ▶ | my $class = ref $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
union: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 1 | return $class->new( keys %{$_[0]}, keys %{$_[1]} ); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub intersection { | ||||||||||||||||||||||||||||
| 98 | 8 | ▶ | my $class = ref $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
intersection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 8 | return $class->new( grep { exists($_[0]->{$_}) } keys %{$_[1]} ); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub intersection2 { | ||||||||||||||||||||||||||||
| 103 | 1 | ▶ | my $class = ref $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
intersection2: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 1 | ▶ | my ($a, $b) = $_[0]->size > $_[1]->size ? ($_[0], $_[1]) : ($_[1], $_[0]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 1 | return $class->new( grep { exists($a->{$_}) } keys %{$b} ); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | ▶ | sub symmetric_difference { $_[0]->clone->invert(keys %{$_[1]}) } | ||||||||||||||||||||||||||
|
Subroutine
symmetric_difference: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 2 | *copy = \&clone; | |||||||||||||||||||||||||||
| 112 | 2 | *has = \&contains; | |||||||||||||||||||||||||||
| 113 | 2 | *member = \&element; | |||||||||||||||||||||||||||
| 114 | 2 | *members = \&elements; | |||||||||||||||||||||||||||
| 115 | 2 | *delete = \&remove; | |||||||||||||||||||||||||||
| 116 | 2 | *is_empty = \&is_null; | |||||||||||||||||||||||||||
| 117 | 2 | *unique = \&symmetric_difference; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | 1; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||