| 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
| |||||||||||||||||||||||||||||
| 19 | 6085 | my $index = $self->{index_for}{$key}; | |||||||||||||||||||||||||||
| 20 | 6085 | ▶ | if(defined($index)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 32 | 211 | my $index = $self->{index_for}{$key}; | |||||||||||||||||||||||||||
| 33 | 211 | ▶ | return defined($index) ? $self->{values}[$index] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$index < 0 or $index >= $self->size
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 61 | 33 | my $index = delete $self->{index_for}{$key}; | |||||||||||||||||||||||||||
| 62 | 33 | ▶ | return undef if not defined $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
not defined $code or ref $code ne "CODE"
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"
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $another and ref $another
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||