| 1 | package JE::Object::Array; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 101 | our $VERSION = '0.066'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 101 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 101 | ▶ | use warnings; no warnings 'utf8'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 101 | ▶ | use overload fallback => 1, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 101 | '@{}'=> \&_get_tie; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 101 | ▶ | use List::Util qw/min max/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 101 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 101 | our @ISA = 'JE::Object'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 101 | require JE::Code; | |||||||||||||||||||||||||||
| 18 | 101 | require JE::Object ; | |||||||||||||||||||||||||||
| 19 | 101 | require JE::Object::Error::TypeError ; | |||||||||||||||||||||||||||
| 20 | 101 | require JE::Object::Function ; | |||||||||||||||||||||||||||
| 21 | 101 | require JE::String ; | |||||||||||||||||||||||||||
| 22 | 101 | require JE::Number ; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 101 | import JE::Code 'add_line_number'; | |||||||||||||||||||||||||||
| 25 | sub add_line_number; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 NAME | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | JE::Object - JavaScript Array object class | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | use JE; | ||||||||||||||||||||||||||||
| 34 | use JE::Object::Array; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | $j = new JE; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | $js_array = new JE::Object::Array $j, 1, 2, 3; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | $perl_arrayref = $js_array->value; # returns [1, 2, 3] | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | $js_array->[1]; # same as $js_array->value->[1] | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | "$js_array"; # returns "1,2,3" | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | This module implements JavaScript Array objects. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | The C<@{}> (array ref) operator is overloaded and returns a tied array that | ||||||||||||||||||||||||||||
| 51 | you can use to modify the array object itself. The limitations and caveats | ||||||||||||||||||||||||||||
| 52 | mentioned in | ||||||||||||||||||||||||||||
| 53 | C<JE::Object/"USING AN OBJECT AS A HASH"> apply here, too. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 METHODS | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | See L<JE::Types> for descriptions of most of the methods. Only what | ||||||||||||||||||||||||||||
| 58 | is specific to JE::Object::Array is explained here. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =over 4 | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =item $a = JE::Object::Array->new($global_obj, \@elements) | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item $a = JE::Object::Array->new($global_obj, $length) | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =item $a = JE::Object::Array->new($global_obj, @elements) | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | This creates a new Array object. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | If the second argument is an unblessed array ref, the elements of that | ||||||||||||||||||||||||||||
| 71 | array become the elements of the new array object. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | If there are two arguments and the second | ||||||||||||||||||||||||||||
| 74 | is a JE::Number, a new array is created with that number as the length. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Otherwise, all arguments starting from the second one become elements of | ||||||||||||||||||||||||||||
| 77 | the new array object. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 5456 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 5456 | my($class,$global) = (shift,shift); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 5456 | my @array; | |||||||||||||||||||||||||||
| 85 | 5456 | ▶ | if (ref $_[0] eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 86 | 154 | @array = $global->upgrade(@{+shift}); | |||||||||||||||||||||||||||
| 87 | ▶ | } elsif (@_ == 1 && UNIVERSAL::isa $_[0], 'JE::Number') { | |||||||||||||||||||||||||||
|
Condition100%3/3
@_ == 1 and UNIVERSAL::isa($_[0], "JE::Number")
MC/DC100%2/2
@_ == 1 and UNIVERSAL::isa($_[0], "JE::Number")
@_ == 1
UNIVERSAL::isa($_[0], "JE::Number")
Truth table100%3/3
A and B
A= @_ == 1B= UNIVERSAL::isa($_[0], "JE::Number")
| |||||||||||||||||||||||||||||
| 88 | 9 | my $num = 0+shift; | |||||||||||||||||||||||||||
| 89 | 9 | ▶ | $num == int($num) % 2**32 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | or require JE::Object::Error::RangeError, | ||||||||||||||||||||||||||||
| 91 | die JE::Object::Error::RangeError->new($global, | ||||||||||||||||||||||||||||
| 92 | add_line_number "$num is not a valid array index"); | ||||||||||||||||||||||||||||
| 93 | 5 | $#array = $num - 1; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||
| 96 | 5293 | @array = $global->upgrade(@_); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 5452 | ▶ | my $self = SUPER::new $class $global, { | ||||||||||||||||||||||||||
|
Condition33%1/3
$global->prototype_for('Array') || $global->prop('Array')->prop('prototype')
MC/DC0%0/2
$global->prototype_for('Array') || $global->prop('Array')->prop('prototype')
$global->prototype_for('Array')
$global->prop('Array')->prop('prototype')
Truth table33%1/3
A || B
A= $global->prototype_for('Array')B= $global->prop('Array')->prop('prototype')
| |||||||||||||||||||||||||||||
| 99 | prototype => $global->prototype_for('Array') || | ||||||||||||||||||||||||||||
| 100 | $global->prop('Array')->prop('prototype') | ||||||||||||||||||||||||||||
| 101 | }; | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 5452 | my $guts = $$self; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 5452 | $$guts{array} = \@array; | |||||||||||||||||||||||||||
| 106 | 5452 | bless $self, $class; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 47882 | ▶ | sub prop { | ||||||||||||||||||||||||||
|
Subroutine
prop: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 47882 | my ($self, $name, $val) = (shift, @_); | |||||||||||||||||||||||||||
| 114 | 47882 | my $guts = $$self; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 47882 | ▶ | if ($name eq 'length') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 117 | 1580 | ▶ | if (@_ > 1) { # assignment | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | $val == int($val) % 2**32 or | ||||||||||||||||||||||||||||
| 119 | require JE::Object::Error::RangeError, | ||||||||||||||||||||||||||||
| 120 | die new JE::Object::Error::RangeError | ||||||||||||||||||||||||||||
| 121 | $$guts{global}, | ||||||||||||||||||||||||||||
| 122 | 51 | ▶ | add_line_number | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | "$val is not a valid value for length"; | ||||||||||||||||||||||||||||
| 124 | 51 | $#{$$guts{array}} = $val - 1; | |||||||||||||||||||||||||||
| 125 | 51 | return JE::Number->new($$guts{global}, $val); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||
| 128 | return JE::Number->new($$guts{global}, | ||||||||||||||||||||||||||||
| 129 | 1529 | $#{$$guts{array}} + 1); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | ▶ | elsif ($name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295) { | |||||||||||||||||||||||||||
|
Condition66%2/3
$name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295
MC/DC50%1/2
$name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295
$name =~ /^(?:0|[1-9]\d*)\z/
$name < 4294967295
Truth table66%2/3
A and B
A= $name =~ /^(?:0|[1-9]\d*)\z/B= $name < 4294967295
| |||||||||||||||||||||||||||||
| 133 | 45212 | ▶ | if (@_ > 1) { # assignment | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | return $$guts{array}[$name] = | ||||||||||||||||||||||||||||
| 135 | 54 | $$guts{global}->upgrade($val); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||
| 138 | return exists $$guts{array}[$name] | ||||||||||||||||||||||||||||
| 139 | 45158 | ▶ | ? $$guts{array}[$name] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 1090 | $self->SUPER::prop(@_); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 6 | ▶ | sub is_enum { | ||||||||||||||||||||||||||
|
Subroutine
is_enum: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 149 | 6 | my ($self,$name) = @_; | |||||||||||||||||||||||||||
| 150 | 6 | ▶ | $name eq 'length' and return !1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 5 | ▶ | if ($name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295
MC/DC50%1/2
$name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295
$name =~ /^(?:0|[1-9]\d*)\z/
$name < 4294967295
Truth table66%2/3
A and B
A= $name =~ /^(?:0|[1-9]\d*)\z/B= $name < 4294967295
| |||||||||||||||||||||||||||||
| 152 | 2 | my $array = $$$self{array}; | |||||||||||||||||||||||||||
| 153 | 2 | ▶ | return $name < @$array && defined $$array[$name]; | ||||||||||||||||||||||||||
|
Condition66%2/3
$name < @$array && defined $array->[$name]
MC/DC50%1/2
$name < @$array && defined $array->[$name]
$name < @$array
defined $array->[$name]
Truth table66%2/3
A && B
A= $name < @$arrayB= defined $array->[$name]
| |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 3 | SUPER::is_enum $self $name; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 28 | ▶ | sub keys { # length is not enumerable | ||||||||||||||||||||||||||
|
Subroutine
keys: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 162 | 28 | my $self = shift; | |||||||||||||||||||||||||||
| 163 | 28 | my $array = $$$self{array}; | |||||||||||||||||||||||||||
| 164 | 28 | grep(defined $$array[$_], 0..$#$array), | |||||||||||||||||||||||||||
| 165 | SUPER::keys $self; | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 53 | ▶ | sub delete { # array indices are deletable; length is not | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | 53 | my($self,$name) = @_; | |||||||||||||||||||||||||||
| 173 | 53 | ▶ | $name eq 'length' and return !1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 52 | ▶ | if($name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295
MC/DC50%1/2
$name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295
$name =~ /^(?:0|[1-9]\d*)\z/
$name < 4294967295
Truth table66%2/3
A and B
A= $name =~ /^(?:0|[1-9]\d*)\z/B= $name < 4294967295
| |||||||||||||||||||||||||||||
| 175 | 49 | my $array = $$$self{array}; | |||||||||||||||||||||||||||
| 176 | 49 | ▶ | $name < @$array and $$array[$name] = undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 49 | return 1; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 3 | SUPER::delete $self $name; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =item $a->value | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | This returns a reference to an array. This is a copy of the Array object's | ||||||||||||||||||||||||||||
| 188 | internal array. If you want an array through which you can modify the | ||||||||||||||||||||||||||||
| 189 | object, use C<@$a>. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 5 | ▶ | sub value { [@{$${+shift}{array}}] }; | ||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 194 | 101 | *TO_JSON=*value; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 13 | ▶ | sub exists { | ||||||||||||||||||||||||||
|
Subroutine
exists: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 198 | 13 | my ($self, $name) = (shift, @_); | |||||||||||||||||||||||||||
| 199 | 13 | my $guts = $$self; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 13 | ▶ | if ($name eq 'length') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 202 | 2 | return 1 | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | ▶ | elsif ($name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295) { | |||||||||||||||||||||||||||
|
Condition66%2/3
$name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295
MC/DC50%1/2
$name =~ /^(?:0|[1-9]\d*)\z/ and $name < 4294967295
$name =~ /^(?:0|[1-9]\d*)\z/
$name < 4294967295
Truth table66%2/3
A and B
A= $name =~ /^(?:0|[1-9]\d*)\z/B= $name < 4294967295
| |||||||||||||||||||||||||||||
| 205 | return exists $$guts{array}[$name] | ||||||||||||||||||||||||||||
| 206 | 6 | ▶ | && defined $$guts{array}[$name]; | ||||||||||||||||||||||||||
|
Condition66%2/3
exists $guts->{'array'}[$name] && defined $guts->{'array'}[$name]
MC/DC50%1/2
exists $guts->{'array'}[$name] && defined $guts->{'array'}[$name]
exists $guts->{'array'}[$name]
defined $guts->{'array'}[$name]
Truth table66%2/3
A && B
A= exists $guts->{'array'}[$name]B= defined $guts->{'array'}[$name]
| |||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | 5 | $self->SUPER::exists(@_); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 197 | ▶ | sub class { 'Array' } | ||||||||||||||||||||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 23 | ▶ | sub _new_constructor { | ||||||||||||||||||||||||||
|
Subroutine
_new_constructor: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 216 | 23 | my $global = shift; | |||||||||||||||||||||||||||
| 217 | 29 | ▶ | my $construct_cref = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 218 | 29 | __PACKAGE__->new(@_); | |||||||||||||||||||||||||||
| 219 | 23 | }; | |||||||||||||||||||||||||||
| 220 | 23 | my $f = JE::Object::Function->new({ | |||||||||||||||||||||||||||
| 221 | name => 'Array', | ||||||||||||||||||||||||||||
| 222 | scope => $global, | ||||||||||||||||||||||||||||
| 223 | function => $construct_cref, | ||||||||||||||||||||||||||||
| 224 | function_args => ['global','args'], | ||||||||||||||||||||||||||||
| 225 | length => 1, | ||||||||||||||||||||||||||||
| 226 | constructor => $construct_cref, | ||||||||||||||||||||||||||||
| 227 | constructor_args => ['global','args'], | ||||||||||||||||||||||||||||
| 228 | }); | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 23 | my $proto = $f->prop({ | |||||||||||||||||||||||||||
| 231 | name => 'prototype', | ||||||||||||||||||||||||||||
| 232 | dontenum => 1, | ||||||||||||||||||||||||||||
| 233 | readonly => 1, | ||||||||||||||||||||||||||||
| 234 | }); | ||||||||||||||||||||||||||||
| 235 | 23 | bless $proto, __PACKAGE__; | |||||||||||||||||||||||||||
| 236 | 23 | $$$proto{array} = []; | |||||||||||||||||||||||||||
| 237 | 23 | $global->prototype_for('Array',$proto); | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 240 | name => 'toString', | ||||||||||||||||||||||||||||
| 241 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 242 | scope => $global, | ||||||||||||||||||||||||||||
| 243 | name => 'toString', | ||||||||||||||||||||||||||||
| 244 | length => 0, | ||||||||||||||||||||||||||||
| 245 | no_proto => 1, | ||||||||||||||||||||||||||||
| 246 | function_args => ['this'], | ||||||||||||||||||||||||||||
| 247 | function => \&_toString, | ||||||||||||||||||||||||||||
| 248 | }), | ||||||||||||||||||||||||||||
| 249 | dontenum => 1, | ||||||||||||||||||||||||||||
| 250 | }); | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 253 | name => 'toLocaleString', | ||||||||||||||||||||||||||||
| 254 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 255 | scope => $global, | ||||||||||||||||||||||||||||
| 256 | name => 'toLocaleString', | ||||||||||||||||||||||||||||
| 257 | length => 0, | ||||||||||||||||||||||||||||
| 258 | no_proto => 1, | ||||||||||||||||||||||||||||
| 259 | function_args => ['this'], | ||||||||||||||||||||||||||||
| 260 | function => \&_toLocaleString, | ||||||||||||||||||||||||||||
| 261 | }), | ||||||||||||||||||||||||||||
| 262 | dontenum => 1, | ||||||||||||||||||||||||||||
| 263 | }); | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 266 | name => 'concat', | ||||||||||||||||||||||||||||
| 267 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 268 | scope => $global, | ||||||||||||||||||||||||||||
| 269 | name => 'concat', | ||||||||||||||||||||||||||||
| 270 | length => 1, | ||||||||||||||||||||||||||||
| 271 | no_proto => 1, | ||||||||||||||||||||||||||||
| 272 | function_args => ['this','args'], | ||||||||||||||||||||||||||||
| 273 | function => \&_concat, | ||||||||||||||||||||||||||||
| 274 | }), | ||||||||||||||||||||||||||||
| 275 | dontenum => 1, | ||||||||||||||||||||||||||||
| 276 | }); | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 279 | name => 'join', | ||||||||||||||||||||||||||||
| 280 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 281 | scope => $global, | ||||||||||||||||||||||||||||
| 282 | name => 'join', | ||||||||||||||||||||||||||||
| 283 | argnames => ['separator'], | ||||||||||||||||||||||||||||
| 284 | no_proto => 1, | ||||||||||||||||||||||||||||
| 285 | function_args => ['this','args'], | ||||||||||||||||||||||||||||
| 286 | function => \&_join, | ||||||||||||||||||||||||||||
| 287 | }), | ||||||||||||||||||||||||||||
| 288 | dontenum => 1, | ||||||||||||||||||||||||||||
| 289 | }); | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 292 | name => 'pop', | ||||||||||||||||||||||||||||
| 293 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 294 | scope => $global, | ||||||||||||||||||||||||||||
| 295 | name => 'pop', | ||||||||||||||||||||||||||||
| 296 | length => 0, | ||||||||||||||||||||||||||||
| 297 | no_proto => 1, | ||||||||||||||||||||||||||||
| 298 | function_args => ['this'], | ||||||||||||||||||||||||||||
| 299 | function => \&_pop, | ||||||||||||||||||||||||||||
| 300 | }), | ||||||||||||||||||||||||||||
| 301 | dontenum => 1, | ||||||||||||||||||||||||||||
| 302 | }); | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 305 | name => 'push', | ||||||||||||||||||||||||||||
| 306 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 307 | scope => $global, | ||||||||||||||||||||||||||||
| 308 | name => 'push', | ||||||||||||||||||||||||||||
| 309 | length => 1, | ||||||||||||||||||||||||||||
| 310 | no_proto => 1, | ||||||||||||||||||||||||||||
| 311 | function_args => ['this','args'], | ||||||||||||||||||||||||||||
| 312 | function => \&_push, | ||||||||||||||||||||||||||||
| 313 | }), | ||||||||||||||||||||||||||||
| 314 | dontenum => 1, | ||||||||||||||||||||||||||||
| 315 | }); | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 318 | name => 'reverse', | ||||||||||||||||||||||||||||
| 319 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 320 | scope => $global, | ||||||||||||||||||||||||||||
| 321 | name => 'reverse', | ||||||||||||||||||||||||||||
| 322 | length => 0, | ||||||||||||||||||||||||||||
| 323 | no_proto => 1, | ||||||||||||||||||||||||||||
| 324 | function_args => ['this'], | ||||||||||||||||||||||||||||
| 325 | function => \&_reverse, | ||||||||||||||||||||||||||||
| 326 | }), | ||||||||||||||||||||||||||||
| 327 | dontenum => 1, | ||||||||||||||||||||||||||||
| 328 | }); | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 331 | name => 'shift', | ||||||||||||||||||||||||||||
| 332 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 333 | scope => $global, | ||||||||||||||||||||||||||||
| 334 | name => 'shift', | ||||||||||||||||||||||||||||
| 335 | length => 0, | ||||||||||||||||||||||||||||
| 336 | no_proto => 1, | ||||||||||||||||||||||||||||
| 337 | function_args => ['this'], | ||||||||||||||||||||||||||||
| 338 | function => \&_shift, | ||||||||||||||||||||||||||||
| 339 | }), | ||||||||||||||||||||||||||||
| 340 | dontenum => 1, | ||||||||||||||||||||||||||||
| 341 | }); | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 344 | name => 'slice', | ||||||||||||||||||||||||||||
| 345 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 346 | scope => $global, | ||||||||||||||||||||||||||||
| 347 | name => 'shift', | ||||||||||||||||||||||||||||
| 348 | argnames => [qw/start end/], | ||||||||||||||||||||||||||||
| 349 | no_proto => 1, | ||||||||||||||||||||||||||||
| 350 | function_args => ['this','args'], | ||||||||||||||||||||||||||||
| 351 | function => \&_slice, | ||||||||||||||||||||||||||||
| 352 | }), | ||||||||||||||||||||||||||||
| 353 | dontenum => 1, | ||||||||||||||||||||||||||||
| 354 | }); | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 357 | name => 'sort', | ||||||||||||||||||||||||||||
| 358 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 359 | scope => $global, | ||||||||||||||||||||||||||||
| 360 | name => 'sort', | ||||||||||||||||||||||||||||
| 361 | argnames => [qw/comparefn/], | ||||||||||||||||||||||||||||
| 362 | no_proto => 1, | ||||||||||||||||||||||||||||
| 363 | function_args => ['this','args'], | ||||||||||||||||||||||||||||
| 364 | function => \&_sort, | ||||||||||||||||||||||||||||
| 365 | }), | ||||||||||||||||||||||||||||
| 366 | dontenum => 1, | ||||||||||||||||||||||||||||
| 367 | }); | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 370 | name => 'splice', | ||||||||||||||||||||||||||||
| 371 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 372 | scope => $global, | ||||||||||||||||||||||||||||
| 373 | name => 'splice', | ||||||||||||||||||||||||||||
| 374 | argnames => [qw/start | ||||||||||||||||||||||||||||
| 375 | deleteCount/], | ||||||||||||||||||||||||||||
| 376 | no_proto => 1, | ||||||||||||||||||||||||||||
| 377 | function_args => ['this','args'], | ||||||||||||||||||||||||||||
| 378 | function => \&_splice, | ||||||||||||||||||||||||||||
| 379 | }), | ||||||||||||||||||||||||||||
| 380 | dontenum => 1, | ||||||||||||||||||||||||||||
| 381 | }); | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 23 | $proto->prop({ | |||||||||||||||||||||||||||
| 384 | name => 'unshift', | ||||||||||||||||||||||||||||
| 385 | value => JE::Object::Function->new({ | ||||||||||||||||||||||||||||
| 386 | scope => $global, | ||||||||||||||||||||||||||||
| 387 | name => 'unshift', | ||||||||||||||||||||||||||||
| 388 | length => 1, | ||||||||||||||||||||||||||||
| 389 | no_proto => 1, | ||||||||||||||||||||||||||||
| 390 | function_args => ['this','args'], | ||||||||||||||||||||||||||||
| 391 | function => \&_unshift, | ||||||||||||||||||||||||||||
| 392 | }), | ||||||||||||||||||||||||||||
| 393 | dontenum => 1, | ||||||||||||||||||||||||||||
| 394 | }); | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 23 | $f | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | # ~~~ I should be able to optimise those methods that are designed to work | ||||||||||||||||||||||||||||
| 400 | # with any JS object by checking first to see whether ref eq __PACKAGE__ | ||||||||||||||||||||||||||||
| 401 | # and then doing a fast Perl-style algorithm (reverse would be a good | ||||||||||||||||||||||||||||
| 402 | # candidate for this) | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 156 | ▶ | sub _toString { | ||||||||||||||||||||||||||
|
Subroutine
_toString: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 405 | 156 | my $self = shift; | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 156 | ▶ | eval{$self->class} eq 'Array' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | or die JE::Object::Error::TypeError->new($self->global, | ||||||||||||||||||||||||||||
| 409 | add_line_number 'Object is not an Array'); | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 156 | my $guts = $$self; | |||||||||||||||||||||||||||
| 412 | JE::String->_new( | ||||||||||||||||||||||||||||
| 413 | $$guts{global}, | ||||||||||||||||||||||||||||
| 414 | join ',', map | ||||||||||||||||||||||||||||
| 415 | defined $_ && ref !~ /^JE::(?:Undefined|Null)\z/ | ||||||||||||||||||||||||||||
| 416 | ? $_->to_string->value : '', | ||||||||||||||||||||||||||||
| 417 | 156 | ▶ | @{ $$guts{array} } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_ and not ref($_) =~ /^JE::(?:Undefined|Null)\z/
MC/DC100%2/2
defined $_ and not ref($_) =~ /^JE::(?:Undefined|Null)\z/
defined $_
not ref($_) =~ /^JE::(?:Undefined|Null)\z/
Truth table100%3/3
A and not(B)
A= defined $_B= not ref($_) =~ /^JE::(?:Undefined|Null)\z/
| |||||||||||||||||||||||||||||
| 418 | ); | ||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 0 | ▶ | sub _toLocaleString { | ||||||||||||||||||||||||||
|
Subroutine
_toLocaleString: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 422 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 0 | ▶ | eval{$self->class} eq 'Array' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | or die JE::Object::Error::TypeError->new($self->global, | ||||||||||||||||||||||||||||
| 426 | 'Object is not an Array'); | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 0 | my $guts = $$self; | |||||||||||||||||||||||||||
| 429 | JE::String->_new( | ||||||||||||||||||||||||||||
| 430 | $$guts{global}, | ||||||||||||||||||||||||||||
| 431 | join ',', map | ||||||||||||||||||||||||||||
| 432 | defined $_ && defined $_->value | ||||||||||||||||||||||||||||
| 433 | ? $_->method('toLocaleString')->value : '', | ||||||||||||||||||||||||||||
| 434 | 0 | ▶ | @{ $$guts{array} } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_ and defined $_->value
MC/DC0%0/2
defined $_ and defined $_->value
defined $_
defined $_->value
Truth table0%0/3
A and B
A= defined $_B= defined $_->value
| |||||||||||||||||||||||||||||
| 435 | ); | ||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 0 | ▶ | sub _concat { | ||||||||||||||||||||||||||
|
Subroutine
_concat: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 439 | 0 | unshift @_, shift->to_object; | |||||||||||||||||||||||||||
| 440 | 0 | my $thing; | |||||||||||||||||||||||||||
| 441 | 0 | my $new = __PACKAGE__->new(my $global = $_[0]->global); | |||||||||||||||||||||||||||
| 442 | 0 | my @new; | |||||||||||||||||||||||||||
| 443 | 0 | ▶ | while(@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | 0 | $thing = shift; | |||||||||||||||||||||||||||
| 445 | 0 | ▶ | if(eval{$thing->class} eq 'Array') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | 0 | push @new, @{ $$$thing{array} }; | |||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | else { | ||||||||||||||||||||||||||||
| 449 | 0 | push @new, $thing; | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 0 | $$$new{array} = \@new; | |||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 0 | $new; | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 6 | ▶ | sub _join { | ||||||||||||||||||||||||||
|
Subroutine
_join: called CC=7 SCAR=22.3
| |||||||||||||||||||||||||||||
| 459 | 6 | my( $self,$sep) = @_; | |||||||||||||||||||||||||||
| 460 | 6 | ▶ | !defined $sep || $sep->id eq 'undef' and $sep = ','; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $sep or $sep->id eq "undef"
MC/DC0%0/2
not defined $sep or $sep->id eq "undef"
not defined $sep
$sep->id eq "undef"
Truth table33%1/3
not(A) or B
A= not defined $sepB= $sep->id eq "undef"
| |||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 6 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 463 | 6 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | 6 | $length = $length->to_number->value % 2**32; | |||||||||||||||||||||||||||
| 465 | 6 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | 0 | } else { $length = 0 } | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 6 | my $val; | |||||||||||||||||||||||||||
| 470 | JE::String->_new( | ||||||||||||||||||||||||||||
| 471 | $self->global, | ||||||||||||||||||||||||||||
| 472 | join $sep, | ||||||||||||||||||||||||||||
| 473 | map { | ||||||||||||||||||||||||||||
| 474 | 6 | my $val = $self->prop($_); | |||||||||||||||||||||||||||
| 475 | 27 | ▶ | defined $val && defined $val->value | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $val and defined $val->value
MC/DC0%0/2
defined $val and defined $val->value
defined $val
defined $val->value
Truth table33%1/3
A and B
A= defined $valB= defined $val->value
| |||||||||||||||||||||||||||||
| 476 | ? $val->to_string->value : '' | ||||||||||||||||||||||||||||
| 477 | } 0..$length-1 | ||||||||||||||||||||||||||||
| 478 | ); | ||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 34 | ▶ | sub _pop { | ||||||||||||||||||||||||||
|
Subroutine
_pop: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 482 | 34 | my( $self) = @_; | |||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 34 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 485 | 34 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | 34 | $length = (int $length->to_number->value) % 2**32; | |||||||||||||||||||||||||||
| 487 | 34 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 488 | 0 | } else { $length = 0 } | |||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 34 | my $global = $self->global; | |||||||||||||||||||||||||||
| 491 | 34 | ▶ | $length or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | $self->prop('length', JE::Number->new($global,0)), | ||||||||||||||||||||||||||||
| 493 | return $global->undefined; | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 33 | $length--; | |||||||||||||||||||||||||||
| 497 | 33 | my $val = $self->prop($length); | |||||||||||||||||||||||||||
| 498 | 33 | $self->delete($length); | |||||||||||||||||||||||||||
| 499 | 33 | $self->prop(length => JE::Number->new($global,$length)); | |||||||||||||||||||||||||||
| 500 | 33 | $val; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 13 | ▶ | sub _push { | ||||||||||||||||||||||||||
|
Subroutine
_push: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||
| 504 | 13 | my( $self) = shift; | |||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 13 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 507 | 13 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 508 | 13 | $length = (int $length->to_number->value) % 2**32; | |||||||||||||||||||||||||||
| 509 | 13 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | 0 | } else { $length = 0 } | |||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | 13 | ▶ | while(@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 13 | $self->prop($length++, shift); | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | 13 | $self->prop(length => JE::Number->new($self->global,$length)); | |||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 0 | ▶ | sub _reverse { | ||||||||||||||||||||||||||
|
Subroutine
_reverse: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 520 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 0 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 523 | 0 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 524 | 0 | $length = (int $length->to_number->value) % 2**32; | |||||||||||||||||||||||||||
| 525 | 0 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 526 | 0 | } else { $length = 0 } | |||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | 0 | my($elem1,$elem2,$indx2); | |||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 0 | for (0..int $length/2-1) { | |||||||||||||||||||||||||||
| 531 | 0 | $elem1 = $self->prop($_); | |||||||||||||||||||||||||||
| 532 | 0 | $elem2 = $self->prop($indx2 = $length - $_ - 1); | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 0 | ▶ | defined $elem2 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 535 | ? $self->prop($_ => $elem2) | ||||||||||||||||||||||||||||
| 536 | : $self->delete($_); | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | 0 | ▶ | defined $elem1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 539 | ? $self->prop($indx2 => $elem1) | ||||||||||||||||||||||||||||
| 540 | : $self->delete($indx2); | ||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | 0 | $self; | |||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 1 | ▶ | sub _shift { | ||||||||||||||||||||||||||
|
Subroutine
_shift: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 547 | 1 | my( $self) = @_; | |||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | 1 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 550 | 1 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 551 | 1 | $length = (int $length->to_number->value) % 2**32; | |||||||||||||||||||||||||||
| 552 | 1 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 553 | 0 | } else { $length = 0 } | |||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | 1 | ▶ | $length or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 556 | $self->prop('length', 0), | ||||||||||||||||||||||||||||
| 557 | return $self->global->undefined; | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 1 | my $ret = $self->prop(0); | |||||||||||||||||||||||||||
| 560 | 1 | my $val; | |||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | 1 | for (0..$length-2) { | |||||||||||||||||||||||||||
| 563 | 3 | $val = $self->prop($_+1); | |||||||||||||||||||||||||||
| 564 | 3 | ▶ | defined $val | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 565 | ? $self-> prop($_ => $val) | ||||||||||||||||||||||||||||
| 566 | : $self->delete($_); | ||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | 1 | $self->delete(--$length); | |||||||||||||||||||||||||||
| 569 | 1 | $self->prop(length => $length); | |||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | 1 | $ret; | |||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | 0 | ▶ | sub _slice { | ||||||||||||||||||||||||||
|
Subroutine
_slice: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 575 | 0 | my( $self,$start,$end) = @_; | |||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | 0 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 578 | 0 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 579 | 0 | $length = (int $length->to_number->value) % 2**32; | |||||||||||||||||||||||||||
| 580 | 0 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 581 | 0 | } else { $length = 0 } | |||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 0 | my $new = __PACKAGE__->new(my $global = $self->global); | |||||||||||||||||||||||||||
| 584 | 0 | my @new; | |||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if (defined $start) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 587 | 0 | $start = int $start->to_number->value; | |||||||||||||||||||||||||||
| 588 | 0 | ▶ | $start = $start == $start | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 589 | ? $start < 0 | ||||||||||||||||||||||||||||
| 590 | ? max($start + $length,0) | ||||||||||||||||||||||||||||
| 591 | : min($start, $length) | ||||||||||||||||||||||||||||
| 592 | : 0; | ||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||
| 594 | else { | ||||||||||||||||||||||||||||
| 595 | 0 | $start = 0 | |||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if (defined $end and $end->id ne 'undef') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $end and $end->id ne "undef"
MC/DC0%0/2
defined $end and $end->id ne "undef"
defined $end
$end->id ne "undef"
Truth table0%0/3
A and B
A= defined $endB= $end->id ne "undef"
| |||||||||||||||||||||||||||||
| 599 | 0 | $end = $end->to_number->value; | |||||||||||||||||||||||||||
| 600 | 0 | ▶ | $end = $end == $end | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 601 | ? $end < 0 | ||||||||||||||||||||||||||||
| 602 | ? max($end + $length,0) | ||||||||||||||||||||||||||||
| 603 | : min($end, $length) | ||||||||||||||||||||||||||||
| 604 | : 0; | ||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||
| 606 | else { | ||||||||||||||||||||||||||||
| 607 | 0 | $end = $length | |||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | 0 | for ($start..$end-1) { | |||||||||||||||||||||||||||
| 612 | 0 | push @new, $self->prop($_); | |||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | 0 | $$$new{array} = \@new; | |||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | 0 | $new; | |||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | 0 | ▶ | sub _sort { | ||||||||||||||||||||||||||
|
Subroutine
_sort: not called CC=10 SCAR=44.5
| |||||||||||||||||||||||||||||
| 621 | 0 | my($self, $comp) = @_; | |||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | 0 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 624 | 0 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 625 | 0 | $length = (int $length->to_number->value) % 2**32; | |||||||||||||||||||||||||||
| 626 | 0 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 627 | 0 | } else { $length = 0 } | |||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | 0 | my(@sortable, @undef, $nonexistent, $val); | |||||||||||||||||||||||||||
| 630 | 0 | for(0..$length-1) { | |||||||||||||||||||||||||||
| 631 | 0 | ▶ | defined($val = $self->prop($_)) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 632 | ? $val->id eq 'undef' | ||||||||||||||||||||||||||||
| 633 | ? (push @undef, $val) | ||||||||||||||||||||||||||||
| 634 | : (push @sortable, $val) | ||||||||||||||||||||||||||||
| 635 | : ++$nonexistent; | ||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | my $comp_sub = defined $comp && $comp->can('call') | ||||||||||||||||||||||||||||
| 639 | 0 | ▶ | ? sub { 0+$comp->call($a,$b) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 640 | 0 | ▶ | : sub { $a->to_string->value16 cmp $b->to_string->value16}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
defined $comp and $comp->can("call")
MC/DC0%0/2
defined $comp and $comp->can("call")
defined $comp
$comp->can("call")
Truth table0%0/3
A and B
A= defined $compB= $comp->can("call")
| |||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | 0 | my @sorted = ((sort $comp_sub @sortable),@undef); | |||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | 0 | for (0..$#sorted) { | |||||||||||||||||||||||||||
| 645 | 0 | $self->prop($_ => $sorted[$_]); | |||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | 101 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 649 | 0 | for (@sorted .. $#sorted + $nonexistent) { | |||||||||||||||||||||||||||
| 650 | 0 | $self->delete($_); | |||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | 0 | $self; | |||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | 1 | ▶ | sub _splice { | ||||||||||||||||||||||||||
|
Subroutine
_splice: called CC=15 SCAR=34.1
| |||||||||||||||||||||||||||||
| 657 | 1 | my ($self, $start, $del_count) = (shift, shift, shift); | |||||||||||||||||||||||||||
| 658 | 1 | my $global = $self->global; | |||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | 1 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 661 | 1 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 662 | 1 | $length = ($length->to_number->value) % 2**32; | |||||||||||||||||||||||||||
| 663 | 1 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 664 | 0 | } else { $length = 0 }; | |||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | 1 | ▶ | if (defined $start) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 667 | 1 | $start = int $start->to_number->value; | |||||||||||||||||||||||||||
| 668 | 1 | ▶ | $start = $start == $start | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 669 | ? $start < 0 | ||||||||||||||||||||||||||||
| 670 | ? max($start + $length,0) | ||||||||||||||||||||||||||||
| 671 | : min($start, $length) | ||||||||||||||||||||||||||||
| 672 | : 0; | ||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||
| 674 | else { | ||||||||||||||||||||||||||||
| 675 | 0 | $start = 0 | |||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||
| 678 | 1 | ▶ | if(defined $del_count) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 679 | 1 | $del_count = int $del_count->to_number->value; | |||||||||||||||||||||||||||
| 680 | 1 | ▶ | $del_count = $del_count >= 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 681 | ? min($del_count, $length-$start) | ||||||||||||||||||||||||||||
| 682 | : 0; | ||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||
| 684 | else { | ||||||||||||||||||||||||||||
| 685 | 0 | $del_count = 0 | |||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | 1 | my @new = map $self->prop($_), | |||||||||||||||||||||||||||
| 689 | $start..(my $end = $start+$del_count-1); | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | 1 | my $val; | |||||||||||||||||||||||||||
| 692 | 1 | ▶ | if (@_ < $del_count) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 693 | 0 | my $diff = $del_count - @_; | |||||||||||||||||||||||||||
| 694 | 0 | for ($end+1..$length-1) { | |||||||||||||||||||||||||||
| 695 | 0 | ▶ | defined ($val = $self->prop($_)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 696 | ? $self->prop ($_ - $diff => $val) | ||||||||||||||||||||||||||||
| 697 | : $self->delete($_ - $diff); | ||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||
| 699 | 0 | $self->prop(length => | |||||||||||||||||||||||||||
| 700 | JE::Number->new($global, $length - $diff) | ||||||||||||||||||||||||||||
| 701 | ); | ||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||
| 703 | elsif (@_ > $del_count) { | ||||||||||||||||||||||||||||
| 704 | 1 | my $diff = @_ - $del_count; | |||||||||||||||||||||||||||
| 705 | 1 | for (reverse $end+1..$length-1) { | |||||||||||||||||||||||||||
| 706 | 0 | ▶ | defined ($val = $self->prop($_)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 707 | ? $self->prop ($_ + $diff => $val) | ||||||||||||||||||||||||||||
| 708 | : $self->delete($_ + $diff); | ||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||
| 710 | 1 | $self->prop(length => | |||||||||||||||||||||||||||
| 711 | JE::Number->new($global, $length + $diff) | ||||||||||||||||||||||||||||
| 712 | ); | ||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||
| 714 | else { | ||||||||||||||||||||||||||||
| 715 | 0 | $self->prop(length => JE::Number->new($global,$length)); | |||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | 1 | for (0..$#_) { | |||||||||||||||||||||||||||
| 719 | 3 | $self->prop($_+$start => $_[$_]); | |||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||
| 722 | 1 | my $new = __PACKAGE__->new($self->global); | |||||||||||||||||||||||||||
| 723 | 1 | $$new->{array} = \@new; | |||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||
| 725 | 1 | $new; | |||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | 1 | ▶ | sub _unshift { | ||||||||||||||||||||||||||
|
Subroutine
_unshift: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 729 | 1 | my ($self) = (shift,); | |||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | 1 | my $length = $self->prop('length'); | |||||||||||||||||||||||||||
| 732 | 1 | ▶ | if(defined $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 733 | 1 | $length = (int $length->to_number->value) % 2**32; | |||||||||||||||||||||||||||
| 734 | 1 | ▶ | $length == $length or $length = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 735 | 0 | } else { $length = 0 } | |||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | 1 | my $val; | |||||||||||||||||||||||||||
| 738 | 1 | for (reverse 0..$length-1) { | |||||||||||||||||||||||||||
| 739 | 3 | ▶ | defined ($val = $self->prop($_)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 740 | ? $self->prop ($_ + @_ => $val) | ||||||||||||||||||||||||||||
| 741 | : $self->delete($_ + @_); | ||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||
| 744 | 1 | for (0..$#_) { | |||||||||||||||||||||||||||
| 745 | 1 | $self->prop($_ => $_[$_]); | |||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||
| 747 | 1 | $self->prop(length => $length += @_); | |||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||
| 749 | 1 | return JE::Number->new($self->global, $length); | |||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | #----------- TYING MAGIC ---------------# | ||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||
| 755 | 11 | ▶ | sub _get_tie { | ||||||||||||||||||||||||||
|
Subroutine
_get_tie: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 756 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 757 | 11 | my $guts = $$self; | |||||||||||||||||||||||||||
| 758 | 11 | ▶ | $$guts{array_tie} or tie @{ $$guts{array_tie} }, __PACKAGE__, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 759 | $self; | ||||||||||||||||||||||||||||
| 760 | 11 | $$guts{array_tie}; | |||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | # The qw/FETCH EXISTS DELETE/ methods are inherited from JE::Object. | ||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||
| 765 | 11 | ▶ | sub TIEARRAY { $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
TIEARRAY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 766 | 13 | ▶ | sub FETCHSIZE { $_[0]->prop('length') } | ||||||||||||||||||||||||||
|
Subroutine
FETCHSIZE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 767 | 1 | ▶ | sub STORESIZE { $_[0]->prop('length' => $_[1]) } | ||||||||||||||||||||||||||
|
Subroutine
STORESIZE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 768 | 1 | ▶ | sub PUSH { shift->method(push => @_) } | ||||||||||||||||||||||||||
|
Subroutine
PUSH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 769 | 1 | ▶ | sub POP { $_[0]->method('pop') } | ||||||||||||||||||||||||||
|
Subroutine
POP: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 770 | 1 | ▶ | sub SHIFT { $_[0]->method('shift') } | ||||||||||||||||||||||||||
|
Subroutine
SHIFT: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 771 | 1 | ▶ | sub UNSHIFT { shift->method(unshift => @_) } | ||||||||||||||||||||||||||
|
Subroutine
UNSHIFT: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 772 | 1 | ▶ | sub SPLICE { @{ shift->method(splice => @_)->value } } | ||||||||||||||||||||||||||
|
Subroutine
SPLICE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 773 | 0 | ▶ | sub DDS_freeze { | ||||||||||||||||||||||||||
|
Subroutine
DDS_freeze: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 774 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 775 | 0 | delete $$$self{array_tie}; | |||||||||||||||||||||||||||
| 776 | 0 | SUPER::DDS_freeze $self; | |||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||
| 779 | =back | ||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||
| 781 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||
| 783 | L<JE> | ||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | L<JE::Types> | ||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||
| 787 | L<JE::Object> | ||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||
| 789 | =cut | ||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||
| 791 | 101 | 1; | |||||||||||||||||||||||||||