blib/lib/Tie/Tk/Listbox.pm

filter: Statementstmt 14.9% 16 / 107 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 25.0% 5 / 20 Podpod n/a totaltotal 10.2% 21 / 204 CC 32 SCAR 42.2
CC
32
Cov
9%
SPLICE
210.0
TIEARRAY
30.0
STORE
30.0
CRAP 68.2
↑ Summary
1  
2 # See the POD documentation at the end of this
3 # document for detailed copyright information.
4 # (c) 2003-2006 Steffen Mueller, all rights reserved.
5  
6 package Tie::Tk::Listbox;
7  
8 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 $VERSION = '1.02';
15  
16  
17 0 ▶sub TIEARRAY {
Subroutine TIEARRAY: not called CC=5 SCAR=34.0
18 0 my $proto = shift;
19 0 ▶ my $class = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
20 0 my $listbox = shift;
21 0 ▶ unless (defined $listbox) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $listbox) 0 0 0
22 0 croak "Missing listbox argument.";
23 }
24 0 ▶ unless (ref $listbox eq 'Tk::Listbox') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $listbox eq "Tk::Listbox") 0 0 0
25 0 $listbox = $listbox->Subwidget('listbox');
26 0 ▶ croak "Trouble finding listbox." if not defined $listbox;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $listbox 0 0 0
27 }
28  
29 0 bless \$listbox, $class;
30 }
31  
32 0 ▶sub STORE {
Subroutine STORE: not called CC=5 SCAR=34.0
33 0 my $self = shift;
34 0 my $index = shift;
35 # value is $_[0] now.
36  
37 0 ▶ my $len = $_[1] || $self->FETCHSIZE();
Condition0%0/3
$_[1] || $self->FETCHSIZE
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[1] || $self->FETCHSIZE
$_[1] $self->FETCHSIZE
Truth table0%0/3
A || B
A= $_[1]B= $self->FETCHSIZE
ABresult
1X1
011
000
38 0 ▶ if ($index > $len - 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($index > $len - 1) { } 0 0 0
elsif ($index < 0) { } 0 0 0
39 0 $self->EXTEND($index+1, $len);
40 } elsif ($index < 0) {
41 0 $index += $len;
42 0 ▶ croak "Index out of range." if $index < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $index < 0 0 0 0
43 }
44 0 ${$self}->delete($index);
45 0 ${$self}->insert($index, $_[0]);
46 }
47  
48 0 ▶sub FETCHSIZE {
Subroutine FETCHSIZE: not called CC=1 SCAR=6.9
49 0 my $self = shift;
50 0 return ${$self}->index('end');
51 }
52  
53 0 ▶sub STORESIZE {
Subroutine STORESIZE: not called CC=4 SCAR=30.0
54 0 my $self = shift;
55 0 my $tolen = shift;
56 0 ▶ my $len = shift || $self->FETCHSIZE();
Condition0%0/3
shift() || $self->FETCHSIZE
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->FETCHSIZE
shift() $self->FETCHSIZE
Truth table0%0/3
A || B
A= shift()B= $self->FETCHSIZE
ABresult
1X1
011
000
57 0 ▶ if ($tolen > $len) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tolen > $len) { } 0 0 0
elsif ($tolen < $len) { } 0 0 0
58 0 $self->EXTEND($tolen, $len);
59 } elsif ($tolen < $len) {
60 0 ${$self}->delete($tolen, $len-1);
61 }
62 }
63  
64 0 ▶sub FETCH {
Subroutine FETCH: not called CC=4 SCAR=30.0
65 0 my $self = shift;
66 0 my $ind = shift;
67 0 ▶ my $len = shift || $self->FETCHSIZE();
Condition0%0/3
shift() || $self->FETCHSIZE
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->FETCHSIZE
shift() $self->FETCHSIZE
Truth table0%0/3
A || B
A= shift()B= $self->FETCHSIZE
ABresult
1X1
011
000
68 0 ▶ if ($ind < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ind < 0) 0 0 0
69 0 $ind += $len;
70 }
71 0 ▶ if ($ind >= $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ind >= $len) 0 0 0
72 0 return undef;
73 }
74 0 return ${$self}->get($ind);
75 }
76  
77 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
78 0 my $self = shift;
79 0 $self->STORESIZE(0);
80 }
81  
82 0 ▶sub EXTEND {
Subroutine EXTEND: not called CC=3 SCAR=24.8
83 0 my $self = shift;
84 0 my $tolen = shift;
85 0 ▶ my $len = shift || $self->FETCHSIZE();
Condition0%0/3
shift() || $self->FETCHSIZE
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->FETCHSIZE
shift() $self->FETCHSIZE
Truth table0%0/3
A || B
A= shift()B= $self->FETCHSIZE
ABresult
1X1
011
000
86 0 ▶ if ($tolen > $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tolen > $len) 0 0 0
87 0 my $diff = $tolen - $len;
88 0 ${$self}->insert('end', ( (undef) x $diff ));
89 }
90 }
91  
92 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
93  
94 0 ▶sub SPLICE {
Subroutine SPLICE: not called CC=14 SCAR=53.5
95 0 my $self = shift;
96 0 my $len = $self->FETCHSIZE;
97 0 ▶ my $off = (@_) ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
98 0 ▶ $off += $len if ($off < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $off < 0 0 0 0
99 0 ▶ my $diff = (@_) ? shift : $len - $off;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
100 0 ▶ $diff += $len - $off if $diff < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $diff < 0 0 0 0
101 0 my @result;
102 0 ▶ for (my $i = 0; $i < $diff; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $diff) 0 0 0
103 0 push(@result,$self->FETCH($off+$i));
104 }
105 0 ▶ $off = $len if $off > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $off > $len 0 0 0
106 0 ▶ $diff -= $off + $diff - $len if $off + $diff > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $off + $diff > $len 0 0 0
107 0 ▶ if (@_ > $diff) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ > $diff) { } 0 0 0
elsif (@_ < $diff) { } 0 0 0
108 # Move items up to make room
109 0 my $d = @_ - $diff;
110 0 my $e = $off+$diff;
111 0 $self->EXTEND($len+$d);
112 0 ▶ for (my $i=$len-1; $i >= $e; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $e) 0 0 0
113 0 my $val = $self->FETCH($i);
114 0 $self->STORE($i+$d,$val);
115 }
116 }
117 elsif (@_ < $diff) {
118 # Move items down to close the gap
119 0 my $d = $diff - @_;
120 0 my $e = $off+$diff;
121 0 ▶ for (my $i=$off+$diff; $i < $len; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
122 0 my $val = $self->FETCH($i);
123 0 $self->STORE($i-$d,$val);
124 }
125 0 $self->STORESIZE($len-$d);
126 }
127 0 ▶ for (my $i=0; $i < @_; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 0 0 0
128 0 $self->STORE($off+$i,$_[$i]);
129 }
130 0 ▶ return wantarray ? @result : pop @result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
131 }
132  
133 0 ▶sub UNSHIFT { scalar shift->SPLICE(0,0,@_) }
Subroutine UNSHIFT: not called CC=1 SCAR=6.9
134 0 ▶sub SHIFT { shift->SPLICE(0,1) }
Subroutine SHIFT: not called CC=1 SCAR=6.9
135 0 ▶sub PUSH {
Subroutine PUSH: not called CC=2 SCAR=17.9
136 0 my $self = shift;
137 0 my $i = $self->FETCHSIZE;
138 0 ▶ $self->STORE($i++, shift) while (@_);
Branch: 1 branch
BranchTrueFalseTotal
@_ and do { $self->STORE($i++, shift()) } 0 0 0
139 }
140  
141 0 ▶sub POP {
Subroutine POP: not called CC=2 SCAR=17.9
142 0 my $self = shift;
143 0 my $newsize = $self->FETCHSIZE - 1;
144 0 my $val;
145 0 ▶ if ($newsize >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newsize >= 0) 0 0 0
146 0 $val = $self->FETCH($newsize);
147 0 $self->STORESIZE($newsize);
148 }
149 0 $val;
150 }
151  
152 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=1 SCAR=6.9
153 0 my $pkg = ref $_[0];
154 0 croak "$pkg dosn't define an EXISTS method";
155 }
156  
157 0 ▶sub DELETE {
Subroutine DELETE: not called CC=1 SCAR=6.9
158 0 my $pkg = ref $_[0];
159 0 croak "$pkg dosn't define a DELETE method";
160 }
161  
162  
163 2 1;
164  
165 __END__
↑ Summary