line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::splice; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-10-26'; # DATE |
4
|
|
|
|
|
|
|
our $DIST = 'Data-Unixish'; # DIST |
5
|
|
|
|
|
|
|
our $VERSION = '1.571'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
557
|
use 5.010001; |
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
9
|
1
|
|
|
1
|
|
481
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
1
|
|
|
|
|
24917
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
3750
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
11
|
|
|
|
|
|
|
#use Log::Any '$log'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
488
|
use Data::Unixish::Util qw(%common_args); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
410
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %SPEC; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$SPEC{splice} = { |
18
|
|
|
|
|
|
|
v => 1.1, |
19
|
|
|
|
|
|
|
summary => 'Perform Perl splice() on array', |
20
|
|
|
|
|
|
|
description => <<'_', |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
_ |
23
|
|
|
|
|
|
|
args => { |
24
|
|
|
|
|
|
|
%common_args, |
25
|
|
|
|
|
|
|
offset => { |
26
|
|
|
|
|
|
|
schema => 'uint*', |
27
|
|
|
|
|
|
|
req => 1, |
28
|
|
|
|
|
|
|
pos => 0, |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
length => { |
31
|
|
|
|
|
|
|
schema => 'uint*', |
32
|
|
|
|
|
|
|
pos => 1, |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
list => { |
35
|
|
|
|
|
|
|
schema => ['array*', of=>'str*'], # actually it does not have to be array of str, we just want ease of specifying on the cmdline for now |
36
|
|
|
|
|
|
|
pos => 2, |
37
|
|
|
|
|
|
|
slurpy => 1, |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
tags => [qw/datatype-in:array itemfunc/], |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
sub splice { |
43
|
3
|
|
|
3
|
1
|
11
|
my %args = @_; |
44
|
3
|
|
|
|
|
8
|
my ($in, $out) = ($args{in}, $args{out}); |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
15
|
while (my ($index, $item) = each @$in) { |
47
|
9
|
100
|
|
|
|
30
|
my @ary = ref $item eq 'ARRAY' ? @$item : ($item); |
48
|
9
|
100
|
|
|
|
39
|
if (defined $args{list}) { |
|
|
100
|
|
|
|
|
|
49
|
3
|
|
|
|
|
16
|
CORE::splice(@ary, $args{offset}, $args{length}, @{ $args{list} }); |
|
3
|
|
|
|
|
10
|
|
50
|
|
|
|
|
|
|
} elsif (defined $args{length}) { |
51
|
3
|
|
|
|
|
6
|
CORE::splice(@ary, $args{offset}, $args{length}); |
52
|
|
|
|
|
|
|
} else { |
53
|
3
|
|
|
|
|
6
|
CORE::splice(@ary, $args{offset}); |
54
|
|
|
|
|
|
|
} |
55
|
9
|
|
|
|
|
34
|
push @$out, \@ary; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
|
|
36
|
[200, "OK"]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _splice_item { |
62
|
9
|
|
|
9
|
|
18
|
my ($item, $args) = @_; |
63
|
|
|
|
|
|
|
|
64
|
9
|
100
|
|
|
|
36
|
my @ary = ref $item eq 'ARRAY' ? @$item : ($item); |
65
|
9
|
100
|
|
|
|
23
|
if (defined $args->{list}) { |
|
|
100
|
|
|
|
|
|
66
|
3
|
|
|
|
|
5
|
CORE::splice(@ary, $args->{offset}, $args->{length}, @{ $args->{list} }); |
|
3
|
|
|
|
|
8
|
|
67
|
|
|
|
|
|
|
} elsif (defined $args->{length}) { |
68
|
3
|
|
|
|
|
4
|
CORE::splice(@ary, $args->{offset}, $args->{length}); |
69
|
|
|
|
|
|
|
} else { |
70
|
3
|
|
|
|
|
5
|
CORE::splice(@ary, $args->{offset}); |
71
|
|
|
|
|
|
|
} |
72
|
9
|
|
|
|
|
29
|
\@ary; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
# ABSTRACT: Perform Perl splice() on array |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |