blib/lib/Gnuplot/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 SCAR 29.2
CC
18
Cov
88%
delete
5.0
each
4.4
get_at
3.5
CRAP 18.6
« blib/lib/Gnuplot/Builder/PrototypedData.pm ↑ Summary blib/lib/Gnuplot/Builder/JoinDict.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 sub new {
7 2248 ▶ my ($class) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
8 2248 my $self = bless {
9 index_for => {},
10 keys => [],
11 values => [],
12 }, $class;
13 2248 return $self;
14 }
15  
16 sub set {
17 6074 ▶ my ($self, $key, $value) = @_;
Subroutine set: called CC=3 SCAR=11.0
Pod documented
18 6074 ▶ croak "key must be defined" if not defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 6074 6074
19 6074 my $index = $self->{index_for}{$key};
20 6074 ▶ if(defined($index)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) { } 515 5559 6074
21 515 $self->{values}[$index] = $value;
22 }else {
23 5559 push(@{$self->{keys}}, $key);
24 5559 push(@{$self->{values}}, $value);
25 5559 $self->{index_for}{$key} = $#{$self->{keys}};
26 }
27 }
28  
29 sub get {
30 211 ▶ my ($self, $key) = @_;
Subroutine get: called CC=3 SCAR=11.0
Pod documented
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 sub get_at {
37 71 ▶ my ($self, $index) = @_;
Subroutine get_at: called CC=3 SCAR=12.5
Pod documented
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 sub get_all_keys {
43 172 ▶ my ($self) = @_;
Subroutine get_all_keys: called CC=1 SCAR=0.0
Pod documented
44 172 return @{$self->{keys}};
45 }
46  
47 sub get_all_values {
48 276 ▶ my ($self) = @_;
Subroutine get_all_values: called CC=1 SCAR=0.0
Pod documented
49 276 return @{$self->{values}};
50 }
51  
52 sub exists {
53 1539 ▶ my ($self, $key) = @_;
Subroutine exists: called CC=2 SCAR=7.1
Pod documented
54 1539 ▶ croak "key must be defined" if not defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 1539 1539
55 1539 return defined($self->{index_for}{$key});
56 }
57  
58 sub delete {
59 33 ▶ my ($self, $key) = @_;
Subroutine delete: called CC=5 SCAR=16.1
Pod documented
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 sub add {
73 100 ▶ my ($self, $entry) = @_;
Subroutine add: called CC=1 SCAR=0.0
Pod documented
74 100 push(@{$self->{keys}}, undef);
75 100 push(@{$self->{values}}, $entry);
76 }
77  
78 sub each {
79 2127 ▶ my ($self, $code) = @_;
Subroutine each: called CC=4 SCAR=14.9
Pod documented
80 2127 ▶ 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 2127 2127
Condition33%1/3
not defined $code or ref $code ne "CODE"
l!l&&r!l&&!r
002127
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 2127 foreach my $index (0 .. $#{$self->{keys}}) {
82 5554 $code->($self->{keys}[$index], $self->{values}[$index]);
83 }
84 }
85  
86 sub merge {
87 1535 ▶ my ($self, $another) = @_;
Subroutine merge: called CC=3 SCAR=11.3
Pod documented
88 1535 ▶ croak "another_pkl must be an object" if !defined($another) || !ref($another);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $another and ref $another 0 1535 1535
Condition33%1/3
defined $another and ref $another
!ll&&!rl&&r
001535
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 $another->each(sub {
90 4723 ▶ my ($key, $value) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
91 4723 ▶ if(defined($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 4676 47 4723
92 4676 $self->set($key, $value);
93 }else {
94 47 $self->add($value);
95 }
96 1535 });
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__
« blib/lib/Gnuplot/Builder/PrototypedData.pm ↑ Summary blib/lib/Gnuplot/Builder/JoinDict.pm »