| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 20 | 0 | my $listbox = shift; | |||||||||||||||||||
| 21 | 0 | ▶ | unless (defined $listbox) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | 0 | croak "Missing listbox argument."; | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | 0 | ▶ | unless (ref $listbox eq 'Tk::Listbox') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 0 | $listbox = $listbox->Subwidget('listbox'); | |||||||||||||||||||
| 26 | 0 | ▶ | croak "Trouble finding listbox." if not defined $listbox; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
MC/DC0%0/2
$_[1] || $self->FETCHSIZE
$_[1]
$self->FETCHSIZE
Truth table0%0/3
A || B
A= $_[1]B= $self->FETCHSIZE
| |||||||||||||||||||||
| 38 | 0 | ▶ | if ($index > $len - 1) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
MC/DC0%0/2
shift() || $self->FETCHSIZE
shift()
$self->FETCHSIZE
Truth table0%0/3
A || B
A= shift()B= $self->FETCHSIZE
| |||||||||||||||||||||
| 57 | 0 | ▶ | if ($tolen > $len) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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
MC/DC0%0/2
shift() || $self->FETCHSIZE
shift()
$self->FETCHSIZE
Truth table0%0/3
A || B
A= shift()B= $self->FETCHSIZE
| |||||||||||||||||||||
| 68 | 0 | ▶ | if ($ind < 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 0 | $ind += $len; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | 0 | ▶ | if ($ind >= $len) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
MC/DC0%0/2
shift() || $self->FETCHSIZE
shift()
$self->FETCHSIZE
Truth table0%0/3
A || B
A= shift()B= $self->FETCHSIZE
| |||||||||||||||||||||
| 86 | 0 | ▶ | if ($tolen > $len) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 98 | 0 | ▶ | $off += $len if ($off < 0); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | 0 | ▶ | my $diff = (@_) ? shift : $len - $off; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 0 | ▶ | $diff += $len - $off if $diff < 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 0 | my @result; | |||||||||||||||||||
| 102 | 0 | ▶ | for (my $i = 0; $i < $diff; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | 0 | push(@result,$self->FETCH($off+$i)); | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | 0 | ▶ | $off = $len if $off > $len; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 0 | ▶ | $diff -= $off + $diff - $len if $off + $diff > $len; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | 0 | ▶ | if (@_ > $diff) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 128 | 0 | $self->STORE($off+$i,$_[$i]); | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | 0 | ▶ | return wantarray ? @result : pop @result; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||