blib/lib/Set/Tiny.pm

filter: Statementstmt 100% 83 / 83 Branchbran 95.0% 19 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 28 / 28 Podpod 100% 25 / 25 totaltotal 99.3% 160 / 161 CC 14 SCAR 6.0
CC
14
Cov
99%
set
3.0
contains
3.0
invert
3.0
CRAP 1.8
↑ Summary
1 package Set::Tiny;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our $VERSION = '0.06';
6  
7 3 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 our @EXPORT_OK = qw(set);
9  
10 26 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 26 my $class = shift;
12 26 my %self;
13 26 @self{@_} = ();
14 26 return bless \%self, $class;
15 }
16  
17 4 ▶sub set { ## no critic (NamingConventions::ProhibitAmbiguousNames)
Subroutine set: called CC=3 SCAR=11.0
Pod documented
18 4 ▶ if ( ref( $_[0] ) eq 'Set::Tiny' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'Set::Tiny') { } 1 3 4
elsif (ref $_[0] eq 'ARRAY') { } 1 2 3
19 1 return $_[0]->clone();
20 }
21 elsif ( ref( $_[0] ) eq 'ARRAY' ) {
22 1 return Set::Tiny->new( @{ $_[0] } );
23 }
24 else {
25 2 return Set::Tiny->new(@_);
26 }
27 }
28  
29 98 ▶sub as_string { '(' . join( ' ', sort keys %{ $_[0] } ) . ')' }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
30  
31 30 ▶sub size { scalar keys %{ $_[0] } }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
32  
33 3 ▶sub element { exists $_[0]->{ $_[1] } ? $_[1] : () }
Subroutine element: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{$_[1]} ? : 2 1 3
34  
35 3 ▶sub elements { keys %{ $_[0] } }
Subroutine elements: called CC=1 SCAR=0.0
Pod documented
36  
37 20 ▶sub contains {
Subroutine contains: called CC=3 SCAR=11.0
Pod documented
38 20 my $self = shift;
39 20 ▶ exists $self->{$_} or return !!0 for @_;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$_} or 16 5 21
40 15 return !!1;
41 }
42  
43 10 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
44 10 my $class = ref $_[0];
45 10 return $class->new( keys %{ $_[0] } );
46 }
47  
48 2 ▶sub clear {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
49 2 %{ $_[0] } = ();
50 2 return $_[0];
51 }
52  
53 1 ▶sub insert {
Subroutine insert: called CC=1 SCAR=0.0
Pod documented
54 1 my $self = shift;
55 1 @{$self}{@_} = ();
56 1 return $self;
57 }
58  
59 7 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
60 7 my $self = shift;
61 7 delete @{$self}{@_};
62 7 return $self;
63 }
64  
65 3 ▶sub invert {
Subroutine invert: called CC=3 SCAR=11.0
Pod documented
66 3 my $self = shift;
67 3 ▶ exists $self->{$_} ? delete $self->{$_} : ( $self->{$_} = undef ) for @_;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$_} ? : 3 5 8
68 3 return $self;
69 }
70  
71 3 ▶sub is_null { !%{ $_[0] } }
Subroutine is_null: called CC=1 SCAR=0.0
Pod documented
72  
73 15 ▶sub is_subset { $_[1]->contains( keys %{ $_[0] } ) }
Subroutine is_subset: called CC=1 SCAR=0.0
Pod documented
74  
75 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
BranchTrueFalseTotal
$_[0]->size < $_[1]->size and $_[0]->is_subset($_[1]) 1 3 4
76  
77 4 ▶sub is_superset { $_[1]->is_subset( $_[0] ) }
Subroutine is_superset: called CC=1 SCAR=0.0
Pod documented
78  
79 4 ▶sub is_proper_superset {
Subroutine is_proper_superset: called CC=2 SCAR=6.9
Pod documented
80 4 ▶ $_[0]->size > $_[1]->size && $_[1]->is_subset( $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->size > $_[1]->size and $_[1]->is_subset($_[0]) 1 3 4
81 }
82  
83 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
BranchTrueFalseTotal
$_[1]->is_subset($_[0]) and $_[0]->is_subset($_[1]) 2 1 3
84  
85 7 ▶sub is_disjoint { !$_[0]->intersection( $_[1] )->size }
Subroutine is_disjoint: called CC=1 SCAR=0.0
Pod documented
86  
87 4 ▶sub is_properly_intersecting {
Subroutine is_properly_intersecting: called CC=3 SCAR=11.0
Pod documented
88 4 ▶ !$_[0]->is_disjoint( $_[1] )
Branch: 1 branch
BranchTrueFalseTotal
not $_[0]->is_disjoint($_[1]) and $_[0]->difference($_[1])->size and $_[1]->difference($_[0])->size 1 3 4
Condition100%3/3
not $_[0]->is_disjoint($_[1]) and $_[0]->difference($_[1])->size
!ll&&!rl&&r
211
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
ABresult
0X0
100
111
89 && $_[0]->difference( $_[1] )->size
90 && $_[1]->difference( $_[0] )->size;
91 }
92  
93 5 ▶sub difference { $_[0]->clone->remove( keys %{ $_[1] } ) }
Subroutine difference: called CC=1 SCAR=0.0
Pod documented
94  
95 1 ▶sub union {
Subroutine union: called CC=1 SCAR=0.0
Pod documented
96 1 my $class = ref $_[0];
97 1 return $class->new( keys %{ $_[0] }, keys %{ $_[1] } );
98 }
99  
100 8 ▶sub intersection {
Subroutine intersection: called CC=1 SCAR=0.0
Pod documented
101 8 my $class = ref $_[0];
102 8 return $class->new( grep { exists( $_[0]->{$_} ) } keys %{ $_[1] } );
103 }
104  
105 1 ▶sub intersection2 {
Subroutine intersection2: called CC=2 SCAR=7.0
Pod documented
106 1 my $class = ref $_[0];
107 1 ▶ my ( $a, $b ) =
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->size > $_[1]->size ? : 0 1 1
108 $_[0]->size > $_[1]->size ? ( $_[0], $_[1] ) : ( $_[1], $_[0] );
109 1 return $class->new( grep { exists( $a->{$_} ) } keys %{$b} );
110 }
111  
112 2 ▶sub symmetric_difference { $_[0]->clone->invert( keys %{ $_[1] } ) }
Subroutine symmetric_difference: called CC=1 SCAR=0.0
Pod documented
113  
114 {
115 3 *copy = \&clone;
116 3 *has = \&contains;
117 3 *member = \&element;
118 3 *members = \&elements;
119 3 *delete = \&remove;
120 3 *is_empty = \&is_null;
121 3 *unique = \&symmetric_difference;
122 }
123  
124 3 1;
125  
126 __END__
↑ Summary