Builder/PartiallyKeyedList.pm

filter: Statementstmt 100% 71 / 71 Branchbran 70.8% 17 / 24 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 16 / 16 Podpod 100% 12 / 12 totaltotal 86.2% 119 / 138 CC 18 SCAR 10.7
CC
18
Cov
88%
delete
5.0
each
4.4
get_at
3.5
CRAP 2.9
« Builder/JoinDict.pm ↑ Summary Builder/Lens.pm »
1 package Gnuplot::Builder::PartiallyKeyedList;
2 72 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 72 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 72 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2256 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
7 2256 my ($class) = @_;
8 2256 my $self = bless {
9 index_for => {},
10 keys => [],
11 values => [],
12 }, $class;
13 2256 return $self;
14 }
15  
16 6085 ▶sub set {
Subroutine set: called CC=3 SCAR=11.0
Pod documented
17 6085 my ($self, $key, $value) = @_;
18 6085 ▶ croak "key must be defined" if not defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 6085 6085
19 6085 my $index = $self->{index_for}{$key};
20 6085 ▶ if(defined($index)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) { } 516 5569 6085
21 516 $self->{values}[$index] = $value;
22 }else {
23 5569 push(@{$self->{keys}}, $key);
24 5569 push(@{$self->{values}}, $value);
25 5569 $self->{index_for}{$key} = $#{$self->{keys}};
26 }
27 }
28  
29 211 ▶sub get {
Subroutine get: called CC=3 SCAR=11.0
Pod documented
30 211 my ($self, $key) = @_;
31 211 ▶ croak "key must be defined" if not defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 211 211
32 211 my $index = $self->{index_for}{$key};
33 211 ▶ return defined($index) ? $self->{values}[$index] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $index ? : 202 9 211
34 }
35  
36 71 ▶sub get_at {
Subroutine get_at: called CC=3 SCAR=12.5
Pod documented
37 71 my ($self, $index) = @_;
38 71 ▶ croak "index out of bounds" if $index < 0 || $index >= $self->size;
Branch: 1 branch
BranchTrueFalseTotal
if $index < 0 or $index >= $self->size 0 71 71
Condition33%1/3
$index < 0 or $index >= $self->size
l!l&&r!l&&!r
0071
MC/DC0%0/2
$index < 0 or $index >= $self->size
$index < 0 $index >= $self->size
Truth table33%1/3
A or B
A= $index < 0B= $index >= $self->size
ABresult
1X1
011
000
39 71 return ($self->{keys}[$index], $self->{values}[$index]);
40 }
41  
42 172 ▶sub get_all_keys {
Subroutine get_all_keys: called CC=1 SCAR=0.0
Pod documented
43 172 my ($self) = @_;
44 172 return @{$self->{keys}};
45 }
46  
47 276 ▶sub get_all_values {
Subroutine get_all_values: called CC=1 SCAR=0.0
Pod documented
48 276 my ($self) = @_;
49 276 return @{$self->{values}};
50 }
51  
52 1542 ▶sub exists {
Subroutine exists: called CC=2 SCAR=7.1
Pod documented
53 1542 my ($self, $key) = @_;
54 1542 ▶ croak "key must be defined" if not defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 1542 1542
55 1542 return defined($self->{index_for}{$key});
56 }
57  
58 33 ▶sub delete {
Subroutine delete: called CC=5 SCAR=16.1
Pod documented
59 33 my ($self, $key) = @_;
60 33 ▶ croak "key must be defined" if not defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 33 33
61 33 my $index = delete $self->{index_for}{$key};
62 33 ▶ return undef if not defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 7 26 33
63 26 splice(@{$self->{keys}}, $index, 1);
64 26 my $value = splice(@{$self->{values}}, $index, 1);
65
66 26 foreach my $existing_index (values %{$self->{index_for}}) {
67 66 ▶ $existing_index-- if $existing_index > $index;
Branch: 1 branch
BranchTrueFalseTotal
if $existing_index > $index 36 30 66
68 }
69 26 return $value;
70 }
71  
72 100 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod documented
73 100 my ($self, $entry) = @_;
74 100 push(@{$self->{keys}}, undef);
75 100 push(@{$self->{values}}, $entry);
76 }
77  
78 2136 ▶sub each {
Subroutine each: called CC=4 SCAR=14.9
Pod documented
79 2136 my ($self, $code) = @_;
80 2136 ▶ croak "code must be a code-ref" if !defined($code) || ref($code) ne "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $code or ref $code ne "CODE" 0 2136 2136
Condition33%1/3
not defined $code or ref $code ne "CODE"
l!l&&r!l&&!r
002136
MC/DC0%0/2
not defined $code or ref $code ne "CODE"
not defined $code ref $code ne "CODE"
Truth table33%1/3
not(A) or B
A= not defined $codeB= ref $code ne "CODE"
ABresult
1X1
011
000
81 2136 foreach my $index (0 .. $#{$self->{keys}}) {
82 5566 $code->($self->{keys}[$index], $self->{values}[$index]);
83 }
84 }
85  
86 1539 ▶sub merge {
Subroutine merge: called CC=3 SCAR=11.3
Pod documented
87 1539 my ($self, $another) = @_;
88 1539 ▶ croak "another_pkl must be an object" if !defined($another) || !ref($another);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $another and ref $another 0 1539 1539
Condition33%1/3
defined $another and ref $another
!ll&&!rl&&r
001539
MC/DC0%0/2
defined $another and ref $another
defined $another ref $another
Truth table33%1/3
A and B
A= defined $anotherB= ref $another
ABresult
0X0
100
111
89 4728 ▶ $another->each(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
90 4728 my ($key, $value) = @_;
91 4728 ▶ if(defined($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 4681 47 4728
92 4681 $self->set($key, $value);
93 }else {
94 47 $self->add($value);
95 }
96 1539 });
97 }
98  
99 103 ▶sub size { scalar(@{ $_[0]->{keys} }) }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
100  
101 72 1;
102  
103 __END__
« Builder/JoinDict.pm ↑ Summary Builder/Lens.pm »