ListBrowser/HashList.pm

filter: Statementstmt 76.7% 56 / 73 Branchbran 50.0% 7 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 12 totaltotal 65.8% 79 / 120 CC 11 SCAR 13.0
CC
11
Cov
71%
delete
12.0
getIndex
5.3
add
4.2
CRAP 3.7
« ListBrowser/Row.pm ↑ Summary ListBrowser/Column.pm »
1 package Tk::ListBrowser::HashList;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 $VERSION = 0.17;
9  
10 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 1 my $class = shift;
12 1 my $self = {
13 INDEX => {},
14 LIST => [],
15 };
16 1 bless($self, $class);
17 1 return $self
18 }
19  
20 4 ▶sub add {
Subroutine add: called CC=4 SCAR=14.2
Pod undocumented
21 4 my ($self, $entry, $index) = @_;
22 4 ▶ if ($self->exist($entry->name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->exist($entry->name)) 0 4 4
23 0 croak "Entry '$entry' already exists";
24 return
25 0 }
26 4 my $l = $self->{LIST};
27 4 my $i = $self->{INDEX};
28 4 ▶ $index = @$l unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 3 1 4
29
30 4 $i->{$entry->name} = $index;
31 4 splice(@$l, $index, 0, $entry);
32 4 $i->{$l->[$_]->name} = $_ for $index .. @$l - 1; #rebuild the index
33 }
34  
35 0 ▶sub delete {
Subroutine delete: not called CC=3 SCAR=24.8
Pod undocumented
36 0 my ($self, $name) = @_;
37 0 my $l = $self->{LIST};
38 0 my $index = $self->index($name);
39 0 ▶ if (defined $index) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) 0 0 0
40 0 my ($del) = splice(@$l, $index, 1);
41 0 $del->clear;
42 0 my $i = $self->{INDEX};
43 0 delete $i->{$name};
44 0 $i->{$l->[$_]->name} = $_ for $index .. @$l - 1; #rebuild the index
45 0 return $del
46 }
47 0 croak "Entry '$name' not found";
48 return undef
49 0 }
50  
51 5 ▶sub exist {
Subroutine exist: called CC=1 SCAR=0.0
Pod undocumented
52 5 my ($self, $name) = @_;
53 # croak "name not defined" unless defined $name;
54 5 my $i = $self->{INDEX};
55 5 return exists $i->{$name};
56 }
57  
58 1 ▶sub first {
Subroutine first: called CC=1 SCAR=0.0
Pod undocumented
59 1 my $self = shift;
60 1 return $self->{LIST}->[0]
61 }
62  
63 1 ▶sub get {
Subroutine get: called CC=3 SCAR=11.8
Pod undocumented
64 1 my ($self, $name) = @_;
65 1 ▶ return undef unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1 1
66 1 my $l = $self->{LIST};
67 1 my $i = $self->{INDEX}->{$name};
68 1 ▶ return $l->[$i] if defined $i;
Branch: 1 branch
BranchTrueFalseTotal
if defined $i 1 0 1
69 return undef
70 0 }
71  
72 2 ▶sub getAll {
Subroutine getAll: called CC=1 SCAR=0.0
Pod undocumented
73 2 my $self = shift;
74 2 my $l = $self->{LIST};
75 2 return @$l
76 }
77  
78 1 ▶sub getIndex {
Subroutine getIndex: called CC=4 SCAR=16.6
Pod undocumented
79 1 my ($self, $index) = @_;
80 1 ▶ return undef unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 1 1
81 1 my $l = $self->{LIST};
82 1 ▶ if (($index < 0) or ($index > @$l - 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < 0 or $index > @$l - 1) 0 1 1
Condition33%1/3
$index < 0 or $index > @$l - 1
l!l&&r!l&&!r
001
MC/DC0%0/2
$index < 0 or $index > @$l - 1
$index < 0 $index > @$l - 1
Truth table33%1/3
A or B
A= $index < 0B= $index > @$l - 1
ABresult
1X1
011
000
83 0 croak "Index '$index' out of range";
84 0 return undef ;
85 }
86 1 return $l->[$index];
87 }
88  
89 1 ▶sub index {
Subroutine index: called CC=1 SCAR=0.0
Pod undocumented
90 1 my ($self, $name) = @_;
91 1 my $h = $self->{INDEX};
92 1 return $h->{$name};
93 }
94  
95 2 ▶sub indexLast {
Subroutine indexLast: called CC=1 SCAR=0.0
Pod undocumented
96 2 my $self = shift;
97 2 my $l = $self->{LIST};
98 2 my $last = $self->size - 1;
99 2 return $last
100 }
101  
102 1 ▶sub last {
Subroutine last: called CC=1 SCAR=0.0
Pod undocumented
103 1 my $self = shift;
104 1 return $self->{LIST}->[$self->indexLast]
105 }
106  
107 3 ▶sub size {
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
108 3 my $l = $_[0]->{LIST};
109 3 my $s = @$l;
110 3 return $s
111 }
112  
113 1 1;
« ListBrowser/Row.pm ↑ Summary ListBrowser/Column.pm »