| 1 | package TUI::Objects::NSCollection; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: defines the class TNSCollection | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 36 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 36 | our $VERSION = '2.000002'; | |||||||||||||||||||||||||||
| 9 | 36 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 36 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 36 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 36 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | TNSCollection | ||||||||||||||||||||||||||||
| 15 | new_TNSCollection | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 36 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 36 | ▶ | use Errno qw( EFAULT EINVAL ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 36 | ▶ | use Hash::Util::FieldHash qw( id ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 36 | ▶ | use TUI::toolkit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 36 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | is_Object | ||||||||||||||||||||||||||||
| 24 | :types | ||||||||||||||||||||||||||||
| 25 | 36 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 36 | ▶ | use TUI::Objects::Const qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | ccNotFound | ||||||||||||||||||||||||||||
| 29 | maxCollectionSize | ||||||||||||||||||||||||||||
| 30 | 36 | ); | |||||||||||||||||||||||||||
| 31 | 36 | ▶ | use TUI::Objects::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub TNSCollection() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub new_TNSCollection { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TNSCollection: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 36 | extends TObject; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # predeclare global variable | ||||||||||||||||||||||||||||
| 39 | 36 | our %ITEMS = (); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # protected attributes | ||||||||||||||||||||||||||||
| 42 | 19 | ▶ | has items => ( is => 'ro', default => sub { [] } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 36 | has count => ( is => 'ro', default => 0 ); | |||||||||||||||||||||||||||
| 44 | 36 | has limit => ( is => 'ro', default => 0 ); | |||||||||||||||||||||||||||
| 45 | 36 | has delta => ( is => 'ro', default => 0 ); | |||||||||||||||||||||||||||
| 46 | 36 | has shouldDelete => ( is => 'ro', default => false ); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # predeclare private methods | ||||||||||||||||||||||||||||
| 49 | my ( | ||||||||||||||||||||||||||||
| 50 | 36 | $freeItem, | |||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 11 | ▶ | sub BUILDARGS { # \%args (|%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 11 | state $sig = signature( | |||||||||||||||||||||||||||
| 55 | method => 1, | ||||||||||||||||||||||||||||
| 56 | named => [ | ||||||||||||||||||||||||||||
| 57 | limit => Int, { alias => 'aLimit', optional => 1 }, | ||||||||||||||||||||||||||||
| 58 | delta => Int, { alias => 'aDelta', optional => 1 }, | ||||||||||||||||||||||||||||
| 59 | ], | ||||||||||||||||||||||||||||
| 60 | caller_level => +1, | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | 11 | my ( $class, $args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 63 | 11 | return { %$args }; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 19 | ▶ | sub BUILD { # void (\%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 19 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 68 | 19 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 19 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 19 | $self->setLimit( $self->{limit} ); | |||||||||||||||||||||||||||
| 71 | 19 | return; | |||||||||||||||||||||||||||
| 72 | } #/ sub BUILD | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | ▶ | sub from { # $obj (|$aLimit, $aDelta) | ||||||||||||||||||||||||||
|
Subroutine
from: called CC=4 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 76 | method => 1, | ||||||||||||||||||||||||||||
| 77 | pos => [ | ||||||||||||||||||||||||||||
| 78 | Int, { optional => 1 }, | ||||||||||||||||||||||||||||
| 79 | Int, { optional => 1 }, | ||||||||||||||||||||||||||||
| 80 | ], | ||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||
| 82 | 4 | my ( $class, @args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 83 | 4 | SWITCH: for ( scalar @args ) { | |||||||||||||||||||||||||||
| 84 | 4 | ▶ | $_ == 0 and return $class->new(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $_ == 2 and return $class->new( limit => $args[0], delta => $args[1] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | return; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 19 | ▶ | sub DEMOLISH { # void ($in_global_destruction) | ||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 19 | my ( $self, $in_global_destruction ) = @_; | |||||||||||||||||||||||||||
| 92 | 19 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 19 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 19 | $self->shutDown(); | |||||||||||||||||||||||||||
| 95 | 19 | return; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 20 | ▶ | sub shutDown { # void () | ||||||||||||||||||||||||||
|
Subroutine
shutDown: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 20 | state $sig = signature( | |||||||||||||||||||||||||||
| 100 | method => Object, | ||||||||||||||||||||||||||||
| 101 | pos => [], | ||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||
| 103 | 20 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 104 | 20 | ▶ | if ( $self->{shouldDelete} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | $self->freeAll(); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||
| 108 | 20 | $self->removeAll(); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 20 | $self->setLimit( 0 ); | |||||||||||||||||||||||||||
| 111 | 20 | $self->SUPER::shutDown(); | |||||||||||||||||||||||||||
| 112 | 20 | return; | |||||||||||||||||||||||||||
| 113 | } #/ sub shutDown | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 14 | ▶ | sub at { # $item ($index) | ||||||||||||||||||||||||||
|
Subroutine
at: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 14 | state $sig = signature( | |||||||||||||||||||||||||||
| 117 | method => Object, | ||||||||||||||||||||||||||||
| 118 | pos => [Int], | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | 14 | my ( $self, $index ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 121 | $self->error( EINVAL, "Index out of bounds" ) | ||||||||||||||||||||||||||||
| 122 | 14 | ▶ | if $index < 0 || $index >= $self->{count}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index < 0 or $index >= $self->{"count"}
MC/DC0%0/2
$index < 0 or $index >= $self->{"count"}
$index < 0
$index >= $self->{"count"}
Truth table33%1/3
A or B
A= $index < 0B= $index >= $self->{"count"}
| |||||||||||||||||||||||||||||
| 123 | 14 | return $ITEMS{ $self->{items}->[$index] }; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 5 | ▶ | sub atRemove { # void ($index) | ||||||||||||||||||||||||||
|
Subroutine
atRemove: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 5 | state $sig = signature( | |||||||||||||||||||||||||||
| 128 | method => Object, | ||||||||||||||||||||||||||||
| 129 | pos => [Int], | ||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||
| 131 | 5 | my ( $self, $index ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 132 | $self->error( EINVAL, "Index out of bounds" ) | ||||||||||||||||||||||||||||
| 133 | 5 | ▶ | if $index < 0 || $index >= $self->{count}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index < 0 or $index >= $self->{"count"}
MC/DC0%0/2
$index < 0 or $index >= $self->{"count"}
$index < 0
$index >= $self->{"count"}
Truth table33%1/3
A or B
A= $index < 0B= $index >= $self->{"count"}
| |||||||||||||||||||||||||||||
| 134 | 5 | $self->{count}--; | |||||||||||||||||||||||||||
| 135 | 5 | splice( @{ $self->{items} }, $index, 1 ); | |||||||||||||||||||||||||||
| 136 | 5 | return; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | ▶ | sub atFree { # void ($index) | ||||||||||||||||||||||||||
|
Subroutine
atFree: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 140 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 141 | method => Object, | ||||||||||||||||||||||||||||
| 142 | pos => [Int], | ||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||
| 144 | 1 | my ( $self, $index ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 145 | 1 | my $item = $self->at( $index ); | |||||||||||||||||||||||||||
| 146 | 1 | $self->atRemove( $index ); | |||||||||||||||||||||||||||
| 147 | 1 | $self->$freeItem( $item ); | |||||||||||||||||||||||||||
| 148 | 1 | return; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 16 | ▶ | sub atInsert { # void ($index, $item|undef) | ||||||||||||||||||||||||||
|
Subroutine
atInsert: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | 16 | state $sig = signature( | |||||||||||||||||||||||||||
| 153 | method => Object, | ||||||||||||||||||||||||||||
| 154 | pos => [Int, Item], | ||||||||||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||||||||||
| 156 | 16 | my ( $self, $index, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 157 | 16 | ▶ | $self->error( EINVAL, "Index out of bounds" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | if $index < 0; | ||||||||||||||||||||||||||||
| 159 | $self->setLimit( $self->{count} + $self->{delta} ) | ||||||||||||||||||||||||||||
| 160 | 16 | ▶ | if $self->{count} == $self->{limit}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 16 | ▶ | my $id = id($item) || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
&id($item) || 0
MC/DC100%1/1
&id($item) || 0
&id($item)
Truth table100%2/2
A
A= &id($item)
| |||||||||||||||||||||||||||||
| 163 | 16 | $ITEMS{ $id } = $item; | |||||||||||||||||||||||||||
| 164 | 16 | $self->{count}++; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 16 | splice( @{ $self->{items} }, $index, 0, $id ); | |||||||||||||||||||||||||||
| 167 | 16 | return; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | ▶ | sub atPut { # void ($index, $item|undef) | ||||||||||||||||||||||||||
|
Subroutine
atPut: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 171 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 172 | method => Object, | ||||||||||||||||||||||||||||
| 173 | pos => [Int, Item], | ||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||
| 175 | 1 | my ( $self, $index, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 176 | $self->error( EINVAL, "Index out of bounds" ) | ||||||||||||||||||||||||||||
| 177 | 1 | ▶ | if $index >= $self->{count}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | ▶ | my $id = id($item) || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
&id($item) || 0
MC/DC0%0/1
&id($item) || 0
&id($item)
Truth table50%1/2
A
A= &id($item)
| |||||||||||||||||||||||||||||
| 180 | 1 | $ITEMS{ $id } = $item; | |||||||||||||||||||||||||||
| 181 | 1 | $self->{items}->[$index] = $id; | |||||||||||||||||||||||||||
| 182 | 1 | return; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 3 | ▶ | sub remove { # void ($item) | ||||||||||||||||||||||||||
|
Subroutine
remove: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 186 | 3 | state $sig = signature( | |||||||||||||||||||||||||||
| 187 | method => Object, | ||||||||||||||||||||||||||||
| 188 | pos => [Item], | ||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||
| 190 | 3 | my ( $self, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 191 | 3 | $self->atRemove( $self->indexOf( $item ) ); | |||||||||||||||||||||||||||
| 192 | 3 | return; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 21 | ▶ | sub removeAll { # void () | ||||||||||||||||||||||||||
|
Subroutine
removeAll: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 196 | 21 | state $sig = signature( | |||||||||||||||||||||||||||
| 197 | method => Object, | ||||||||||||||||||||||||||||
| 198 | pos => [], | ||||||||||||||||||||||||||||
| 199 | ); | ||||||||||||||||||||||||||||
| 200 | 21 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 201 | 21 | $self->{count} = 0; | |||||||||||||||||||||||||||
| 202 | 21 | $self->{items} = []; | |||||||||||||||||||||||||||
| 203 | 21 | return; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 1 | ▶ | sub free { # void ($item) | ||||||||||||||||||||||||||
|
Subroutine
free: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 207 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 208 | method => Object, | ||||||||||||||||||||||||||||
| 209 | pos => [Item], | ||||||||||||||||||||||||||||
| 210 | ); | ||||||||||||||||||||||||||||
| 211 | 1 | my ( $self, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 212 | 1 | $self->remove( $item ); | |||||||||||||||||||||||||||
| 213 | 1 | $self->$freeItem( $item ); | |||||||||||||||||||||||||||
| 214 | 1 | return; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 1 | ▶ | sub freeAll { # void () | ||||||||||||||||||||||||||
|
Subroutine
freeAll: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 218 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 219 | method => Object, | ||||||||||||||||||||||||||||
| 220 | pos => [], | ||||||||||||||||||||||||||||
| 221 | ); | ||||||||||||||||||||||||||||
| 222 | 1 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 223 | $self->$freeItem( $self->at( $_ ) ) | ||||||||||||||||||||||||||||
| 224 | 1 | for 0 .. $self->{count} - 1; | |||||||||||||||||||||||||||
| 225 | 1 | $self->{count} = 0; | |||||||||||||||||||||||||||
| 226 | 1 | return; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 6 | ▶ | sub indexOf { # $index ($item|undef) | ||||||||||||||||||||||||||
|
Subroutine
indexOf: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 230 | 6 | state $sig = signature( | |||||||||||||||||||||||||||
| 231 | method => Object, | ||||||||||||||||||||||||||||
| 232 | pos => [Item], | ||||||||||||||||||||||||||||
| 233 | ); | ||||||||||||||||||||||||||||
| 234 | 6 | my ( $self, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 235 | 6 | for my $i ( 0 .. $self->{count} - 1 ) { | |||||||||||||||||||||||||||
| 236 | 7 | ▶ | my $id = id($item) || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
&id($item) || 0
MC/DC0%0/1
&id($item) || 0
&id($item)
Truth table50%1/2
A
A= &id($item)
| |||||||||||||||||||||||||||||
| 237 | 7 | ▶ | return $i if $self->{items}->[$i] eq $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | 1 | $self->error( EFAULT, "Item not found" ); | |||||||||||||||||||||||||||
| 240 | 0 | return ccNotFound; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 3 | ▶ | sub insert { # $index ($item|undef) | ||||||||||||||||||||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 244 | 3 | state $sig = signature( | |||||||||||||||||||||||||||
| 245 | method => Object, | ||||||||||||||||||||||||||||
| 246 | pos => [Item], | ||||||||||||||||||||||||||||
| 247 | ); | ||||||||||||||||||||||||||||
| 248 | 3 | my ( $self, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 249 | 3 | my $loc = $self->{count}; | |||||||||||||||||||||||||||
| 250 | 3 | $self->atInsert( $self->{count}, $item ); | |||||||||||||||||||||||||||
| 251 | 3 | return $loc; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 2 | ▶ | sub error { # void ($code, $info) | ||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 255 | 2 | state $sig = signature( | |||||||||||||||||||||||||||
| 256 | method => Object, | ||||||||||||||||||||||||||||
| 257 | pos => [Int, Str], | ||||||||||||||||||||||||||||
| 258 | ); | ||||||||||||||||||||||||||||
| 259 | 2 | my ( $self, $code, $info ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 260 | 2 | Carp::croak sprintf("Error code: %d, Info: %s\n", $code, $info); | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 1 | ▶ | sub firstThat { # $item|undef (\&Test, $arg|undef) | ||||||||||||||||||||||||||
|
Subroutine
firstThat: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 264 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 265 | method => Object, | ||||||||||||||||||||||||||||
| 266 | pos => [CodeRef, Any], | ||||||||||||||||||||||||||||
| 267 | ); | ||||||||||||||||||||||||||||
| 268 | 1 | my ( $self, $Test, $arg ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 269 | 1 | my $that; | |||||||||||||||||||||||||||
| 270 | 1 | for my $i ( 0 .. $self->{count} - 1 ) { | |||||||||||||||||||||||||||
| 271 | 1 | local $_ = $ITEMS{ $self->{items}->[$i] }; | |||||||||||||||||||||||||||
| 272 | 1 | ▶ | return $_ if $Test->( $_, $arg ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | 0 | return undef; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 1 | ▶ | sub lastThat { # $item|undef (\&Test, $arg|undef) | ||||||||||||||||||||||||||
|
Subroutine
lastThat: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 278 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 279 | method => Object, | ||||||||||||||||||||||||||||
| 280 | pos => [CodeRef, Any], | ||||||||||||||||||||||||||||
| 281 | ); | ||||||||||||||||||||||||||||
| 282 | 1 | my ( $self, $Test, $arg ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 283 | 1 | my $that; | |||||||||||||||||||||||||||
| 284 | 1 | for my $i ( reverse 0 .. $self->{count} - 1 ) { | |||||||||||||||||||||||||||
| 285 | 1 | local $_ = $ITEMS{ $self->{items}->[$i] }; | |||||||||||||||||||||||||||
| 286 | 1 | ▶ | return $_ if $Test->( $_, $arg ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | 0 | return undef; | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 1 | ▶ | sub forEach { # void (\&action, $arg|undef) | ||||||||||||||||||||||||||
|
Subroutine
forEach: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 292 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 293 | method => Object, | ||||||||||||||||||||||||||||
| 294 | pos => [CodeRef, Any], | ||||||||||||||||||||||||||||
| 295 | ); | ||||||||||||||||||||||||||||
| 296 | 1 | my ( $self, $action, $arg ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 297 | 1 | for my $i ( 0 .. $self->{count} - 1 ) { | |||||||||||||||||||||||||||
| 298 | 2 | local $_ = $ITEMS{ $self->{items}->[$i] }; | |||||||||||||||||||||||||||
| 299 | 2 | $action->( $_, $arg ); | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | 1 | return; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 1 | ▶ | sub pack { # void () | ||||||||||||||||||||||||||
|
Subroutine
pack: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 305 | 1 | state $sig = signature( | |||||||||||||||||||||||||||
| 306 | method => Object, | ||||||||||||||||||||||||||||
| 307 | pos => [], | ||||||||||||||||||||||||||||
| 308 | ); | ||||||||||||||||||||||||||||
| 309 | 1 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 310 | 1 | my $count = 0; | |||||||||||||||||||||||||||
| 311 | 1 | for my $i ( 0 .. $self->{count} - 1 ) { | |||||||||||||||||||||||||||
| 312 | 3 | ▶ | if ( $ITEMS{ $self->{items}->[$i] } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 2 | $count++; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | else { | ||||||||||||||||||||||||||||
| 316 | 1 | splice( @{ $self->{items} }, $i, 1 ); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | 1 | ▶ | if ( $self->{count} != $count ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 320 | 1 | my $n = $self->{count} - $count; | |||||||||||||||||||||||||||
| 321 | 1 | push( @{ $self->{items} }, ( 0 ) x $n ); | |||||||||||||||||||||||||||
| 322 | 1 | $self->{count} = $count; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | 1 | return; | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 41 | ▶ | sub setLimit { # void ($aLimit) | ||||||||||||||||||||||||||
|
Subroutine
setLimit: called CC=6 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 328 | 41 | state $sig = signature( | |||||||||||||||||||||||||||
| 329 | method => Object, | ||||||||||||||||||||||||||||
| 330 | pos => [Int], | ||||||||||||||||||||||||||||
| 331 | ); | ||||||||||||||||||||||||||||
| 332 | 41 | my ( $self, $aLimit ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 333 | 41 | ▶ | $aLimit = $self->{count} if $aLimit < $self->{count}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 41 | ▶ | $aLimit = maxCollectionSize if $aLimit > maxCollectionSize; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 41 | ▶ | if ( $aLimit != $self->{limit} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 6 | my $size = @{ $self->{items} }; | |||||||||||||||||||||||||||
| 337 | 6 | ▶ | if ( $aLimit > $size ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 338 | 0 | my $n = $aLimit - $size; | |||||||||||||||||||||||||||
| 339 | 0 | push( @{ $self->{items} }, ( 0 ) x $n ); | |||||||||||||||||||||||||||
| 340 | } elsif ( $aLimit < $size ) { | ||||||||||||||||||||||||||||
| 341 | 0 | splice( @{ $self->{items} }, $aLimit ); | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | 6 | $self->{limit} = $aLimit; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | 41 | return; | |||||||||||||||||||||||||||
| 346 | } #/ sub setLimit | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub getCount { # $count () | ||||||||||||||||||||||||||
|
Subroutine
getCount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 349 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 350 | method => Object, | ||||||||||||||||||||||||||||
| 351 | pos => [], | ||||||||||||||||||||||||||||
| 352 | ); | ||||||||||||||||||||||||||||
| 353 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 354 | 0 | return $self->{count}; | |||||||||||||||||||||||||||
| 355 | }; | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 4 | ▶ | $freeItem = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||
| 358 | 4 | my ( $self, $item ) = @_; | |||||||||||||||||||||||||||
| 359 | 4 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | 4 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 4 | ▶ | my $id = id($item) || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
&id($item) || 0
MC/DC0%0/1
&id($item) || 0
&id($item)
Truth table50%1/2
A
A= &id($item)
| |||||||||||||||||||||||||||||
| 362 | 4 | ▶ | delete $ITEMS{ $id } if $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 4 | return; | |||||||||||||||||||||||||||
| 364 | 36 | }; | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 36 | 1 | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | __END__ | ||||||||||||||||||||||||||||