| 1 | package JQ::Lite::Builtin::Array; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 182 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 182 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 182 | ▶ | use JQ::Lite::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 182 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 136 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 136 | my ($class, $register) = @_; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 136 | ▶ | $register->('first', sub { my ($o, $i) = @_; return [ map { ref($_) eq 'ARRAY' && @{$_} ? $_->[0] : undef } @{$i} ] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.6
Branch: 1 branch
Condition33%1/3
ref $_ eq "ARRAY" and @{$_;}
MC/DC0%0/2
ref $_ eq "ARRAY" and @{$_;}
ref $_ eq "ARRAY"
@{$_;}
Truth table33%1/3
A and B
A= ref $_ eq "ARRAY"B= @{$_;}
| |||||||||||||||||||||||||||||
| 13 | 136 | ▶ | $register->('last', sub { my ($o, $i) = @_; return [ map { ref($_) eq 'ARRAY' && @{$_} ? $_->[-1] : undef } @{$i} ] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.6
Branch: 1 branch
Condition33%1/3
ref $_ eq "ARRAY" and @{$_;}
MC/DC0%0/2
ref $_ eq "ARRAY" and @{$_;}
ref $_ eq "ARRAY"
@{$_;}
Truth table33%1/3
A and B
A= ref $_ eq "ARRAY"B= @{$_;}
| |||||||||||||||||||||||||||||
| 14 | 136 | ▶ | $register->('rest', sub { my ($o, $i) = @_; return [ map { ref($_) eq 'ARRAY' ? (@{$_} ? [ @{$_}[1 .. $#{$_}] ] : []) : $_ } @{$i} ] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 15 | 136 | ▶ | $register->('reverse', sub { my ($o, $i) = @_; return [ map { ref($_) eq 'ARRAY' ? [ reverse @{$_} ] : JQ::Lite::Util::_is_string_scalar($_) ? scalar(reverse $_) : $_ } @{$i} ] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | $register->(['flatten', 'flatten()'], sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 17 | 5 | my ($owner, $inputs) = @_; | |||||||||||||||||||||||||||
| 18 | 5 | ▶ | return [ map { ref($_) eq 'ARRAY' ? JQ::Lite::Util::_flatten_depth($_, 1) : $_ } @{$inputs} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 136 | }); | |||||||||||||||||||||||||||
| 20 | 2 | ▶ | $register->(['flatten_all', 'flatten_all()'], sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 21 | 2 | my ($owner, $inputs) = @_; | |||||||||||||||||||||||||||
| 22 | 2 | ▶ | return [ map { ref($_) eq 'ARRAY' ? JQ::Lite::Util::_flatten_all($_) : $_ } @{$inputs} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 136 | }); | |||||||||||||||||||||||||||
| 24 | 3 | ▶ | $register->(['compact', 'compact()'], sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | 3 | my ($owner, $inputs) = @_; | |||||||||||||||||||||||||||
| 26 | 3 | ▶ | return [ map { ref($_) eq 'ARRAY' ? [ grep { defined $_ } @{$_} ] : $_ } @{$inputs} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 136 | }); | |||||||||||||||||||||||||||
| 28 | 6 | ▶ | $register->(qr/^flatten_depth(?:\((.*)\))?$/, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||
| 29 | 6 | my ($owner, $inputs, $arguments) = @_; | |||||||||||||||||||||||||||
| 30 | 6 | ▶ | $arguments = '' unless defined $arguments; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 6 | ▶ | my @args = length($arguments) ? JQ::Lite::Util::_parse_arguments($arguments) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | my $depth = @args ? $args[0] : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | $depth = 1 unless defined($depth) && looks_like_number($depth); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $depth and &looks_like_number($depth)
MC/DC0%0/2
defined $depth and &looks_like_number($depth)
defined $depth
&looks_like_number($depth)
Truth table33%1/3
A and B
A= defined $depthB= &looks_like_number($depth)
| |||||||||||||||||||||||||||||
| 34 | 6 | $depth = int($depth); | |||||||||||||||||||||||||||
| 35 | 6 | ▶ | $depth = 0 if $depth < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 6 | ▶ | return [ map { ref($_) eq 'ARRAY' ? JQ::Lite::Util::_flatten_depth($_, $depth) : $_ } @{$inputs} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 136 | }); | |||||||||||||||||||||||||||
| 38 | 4 | ▶ | $register->(qr/^nth\((\d+)\)$/, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 39 | 4 | my ($owner, $inputs, $index) = @_; | |||||||||||||||||||||||||||
| 40 | 4 | ▶ | return [ map { ref($_) eq 'ARRAY' && $index < @{$_} ? $_->[$index] : undef } @{$inputs} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_ eq "ARRAY" and $index < @{$_;}
MC/DC50%1/2
ref $_ eq "ARRAY" and $index < @{$_;}
ref $_ eq "ARRAY"
$index < @{$_;}
Truth table66%2/3
A and B
A= ref $_ eq "ARRAY"B= $index < @{$_;}
| |||||||||||||||||||||||||||||
| 41 | 136 | }); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 182 | 1; | |||||||||||||||||||||||||||