| 1 | # | ||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||
| 3 | # | ||||||||||
| 4 | |||||||||||
| 5 | package Rex::Shared::Var::Array; | ||||||||||
| 6 | |||||||||||
| 7 | 63 | ▶ | use v5.14.4; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 63 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 63 | ▶ | use Rex::Shared::Var::Common qw/__lock __store __retrieve/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 63 | our $VERSION = '1.16.1'; # VERSION | |||||||||
| 13 | |||||||||||
| 14 | 64 | ▶ | sub TIEARRAY { | ||||||||
|
Subroutine
TIEARRAY: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 64 | my $self = { varname => $_[1], }; | |||||||||
| 16 | 64 | bless $self, $_[0]; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 35 | ▶ | sub STORE { | ||||||||
|
Subroutine
STORE: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 35 | my $self = shift; | |||||||||
| 21 | 35 | my $index = shift; | |||||||||
| 22 | 35 | my $value = shift; | |||||||||
| 23 | |||||||||||
| 24 | 35 | ▶ | return __lock sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 35 | my $ref = __retrieve; | |||||||||
| 26 | 35 | my $ret = $ref->{ $self->{varname} }->{data}->[$index] = $value; | |||||||||
| 27 | 35 | __store $ref; | |||||||||
| 28 | |||||||||||
| 29 | 35 | return $ret; | |||||||||
| 30 | 35 | }; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 241 | ▶ | sub FETCH { | ||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 241 | my $self = shift; | |||||||||
| 35 | 241 | my $index = shift; | |||||||||
| 36 | |||||||||||
| 37 | 241 | ▶ | return __lock sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 241 | my $ref = __retrieve; | |||||||||
| 39 | 241 | my $ret = $ref->{ $self->{varname} }->{data}->[$index]; | |||||||||
| 40 | |||||||||||
| 41 | 241 | return $ret; | |||||||||
| 42 | 241 | }; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 20 | ▶ | sub CLEAR { | ||||||||
|
Subroutine
CLEAR: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 20 | my $self = shift; | |||||||||
| 47 | |||||||||||
| 48 | 20 | ▶ | __lock sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 20 | my $ref = __retrieve; | |||||||||
| 50 | 20 | $ref->{ $self->{varname} } = { data => [] }; | |||||||||
| 51 | 20 | __store $ref; | |||||||||
| 52 | 20 | }; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub DELETE { | ||||||||
|
Subroutine
DELETE: not called CC=1 SCAR=6.9
| |||||||||||
| 56 | 0 | my $self = shift; | |||||||||
| 57 | 0 | my $index = shift; | |||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | __lock sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 60 | 0 | my $ref = __retrieve; | |||||||||
| 61 | 0 | delete $ref->{ $self->{varname} }->{data}->[$index]; | |||||||||
| 62 | 0 | __store $ref; | |||||||||
| 63 | 0 | }; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub EXISTS { | ||||||||
|
Subroutine
EXISTS: not called CC=1 SCAR=6.9
| |||||||||||
| 67 | 0 | my $self = shift; | |||||||||
| 68 | 0 | my $index = shift; | |||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | return __lock sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | 0 | my $ref = __retrieve; | |||||||||
| 72 | 0 | return exists $ref->{ $self->{varname} }->{data}->[$index]; | |||||||||
| 73 | 0 | }; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 49 | ▶ | sub PUSH { | ||||||||
|
Subroutine
PUSH: called CC=1 SCAR=0.0
| |||||||||||
| 77 | 49 | my $self = shift; | |||||||||
| 78 | 49 | my @data = @_; | |||||||||
| 79 | |||||||||||
| 80 | 49 | ▶ | __lock sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 81 | 49 | my $ref = __retrieve; | |||||||||
| 82 | |||||||||||
| 83 | 49 | ▶ | if ( ref( $ref->{ $self->{varname} }->{data} ) ne "ARRAY" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 8 | $ref->{ $self->{varname} }->{data} = []; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 49 | push( @{ $ref->{ $self->{varname} }->{data} }, @data ); | |||||||||
| 88 | |||||||||||
| 89 | 49 | __store $ref; | |||||||||
| 90 | 49 | }; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 14 | ▶ | sub UNSHIFT { | ||||||||
|
Subroutine
UNSHIFT: called CC=1 SCAR=0.1
| |||||||||||
| 94 | 14 | my $self = shift; | |||||||||
| 95 | 14 | my @data = @_; | |||||||||
| 96 | |||||||||||
| 97 | 14 | ▶ | __lock sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||
| 98 | 14 | my $ref = __retrieve; | |||||||||
| 99 | |||||||||||
| 100 | 14 | ▶ | if ( ref( $ref->{ $self->{varname} }->{data} ) ne "ARRAY" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 0 | $ref->{ $self->{varname} }->{data} = []; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 14 | unshift( @{ $ref->{ $self->{varname} }->{data} }, @data ); | |||||||||
| 105 | |||||||||||
| 106 | 14 | __store $ref; | |||||||||
| 107 | 14 | }; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 14 | ▶ | sub SHIFT { | ||||||||
|
Subroutine
SHIFT: called CC=1 SCAR=0.0
| |||||||||||
| 111 | 14 | my $self = shift; | |||||||||
| 112 | 14 | my @data = @_; | |||||||||
| 113 | 14 | my $result; | |||||||||
| 114 | |||||||||||
| 115 | 14 | ▶ | __lock sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 116 | 14 | my $ref = __retrieve; | |||||||||
| 117 | |||||||||||
| 118 | 14 | $result = shift( @{ $ref->{ $self->{varname} }->{data} } ); | |||||||||
| 119 | |||||||||||
| 120 | 14 | __store $ref; | |||||||||
| 121 | 14 | }; | |||||||||
| 122 | |||||||||||
| 123 | 14 | return $result; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 14 | ▶ | sub POP { | ||||||||
|
Subroutine
POP: called CC=1 SCAR=0.0
| |||||||||||
| 127 | 14 | my $self = shift; | |||||||||
| 128 | 14 | my @data = @_; | |||||||||
| 129 | 14 | my $result; | |||||||||
| 130 | |||||||||||
| 131 | 14 | ▶ | __lock sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 132 | 14 | my $ref = __retrieve; | |||||||||
| 133 | |||||||||||
| 134 | 14 | $result = pop( @{ $ref->{ $self->{varname} }->{data} } ); | |||||||||
| 135 | |||||||||||
| 136 | 14 | __store $ref; | |||||||||
| 137 | 14 | }; | |||||||||
| 138 | |||||||||||
| 139 | 14 | return $result; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 14 | ▶ | sub EXTEND { | ||||||||
|
Subroutine
EXTEND: called CC=1 SCAR=0.0
| |||||||||||
| 143 | 14 | my $self = shift; | |||||||||
| 144 | 14 | my $count = shift; | |||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | 0 | ▶ | sub STORESIZE { | ||||||||
|
Subroutine
STORESIZE: not called CC=1 SCAR=6.9
| |||||||||||
| 148 | 0 | my $self = shift; | |||||||||
| 149 | 0 | my $newsize = shift; | |||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | 143 | ▶ | sub FETCHSIZE { | ||||||||
|
Subroutine
FETCHSIZE: called CC=1 SCAR=0.1
| |||||||||||
| 153 | 143 | my $self = shift; | |||||||||
| 154 | |||||||||||
| 155 | 143 | ▶ | return __lock sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||
| 156 | 143 | my $ref = __retrieve; | |||||||||
| 157 | 143 | ▶ | if ( !exists $ref->{ $self->{varname} } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | 0 | return 0; | |||||||||
| 159 | } | ||||||||||
| 160 | 143 | return scalar( @{ $ref->{ $self->{varname} }->{data} } ); | |||||||||
| 161 | 143 | }; | |||||||||
| 162 | } | ||||||||||
| 163 | |||||||||||
| 164 | 63 | 1; | |||||||||