| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Array::Assign; |
|
2
|
2
|
|
|
2
|
|
2565
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
71
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
53
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use base qw(Exporter); |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
2360
|
|
|
5
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
6
|
|
|
|
|
|
|
arry_assign_i arry_assign_s |
|
7
|
|
|
|
|
|
|
arry_extract_i arry_extract_s |
|
8
|
|
|
|
|
|
|
); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $IDX_MAX = 1000; |
|
11
|
|
|
|
|
|
|
our $VERSION = 0.01; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
|
14
|
2
|
|
|
2
|
1
|
305
|
my ($cls,$idx_map) = @_; |
|
15
|
2
|
|
|
|
|
5
|
my $self = {}; |
|
16
|
2
|
50
|
|
|
|
9
|
if(ref $idx_map eq 'HASH') { |
|
17
|
0
|
|
|
|
|
0
|
%$self = %$idx_map; |
|
18
|
|
|
|
|
|
|
} else { |
|
19
|
2
|
|
|
|
|
4
|
my @idx_arry; |
|
20
|
2
|
50
|
|
|
|
8
|
if(ref $idx_map eq 'ARRAY') { |
|
21
|
0
|
|
|
|
|
0
|
@idx_arry = @$idx_map; |
|
22
|
|
|
|
|
|
|
} else { |
|
23
|
2
|
|
|
|
|
10
|
@idx_arry = @_[1..$#_]; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
2
|
|
|
|
|
4
|
@{$self}{@idx_arry} = (0..$#idx_arry); |
|
|
2
|
|
|
|
|
12
|
|
|
26
|
|
|
|
|
|
|
} |
|
27
|
2
|
|
|
|
|
6
|
bless $self, $cls; |
|
28
|
2
|
|
|
|
|
7
|
return $self; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub assign_s { |
|
32
|
3
|
|
|
3
|
1
|
584
|
my ($self,$target,%fields) = @_; |
|
33
|
3
|
|
|
|
|
21
|
&arry_assign_s($target, $self, %fields); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub assign_i { |
|
37
|
2
|
|
|
2
|
1
|
996
|
shift; |
|
38
|
2
|
|
|
|
|
8
|
goto &arry_assign_i; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub extract_s { |
|
42
|
2
|
|
|
2
|
1
|
282
|
my ($self,$source,%fields) = @_; |
|
43
|
2
|
|
|
|
|
27
|
&arry_extract_s($source, $self, %fields); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub extract_i { |
|
47
|
2
|
|
|
2
|
1
|
875
|
shift; |
|
48
|
2
|
|
|
|
|
8
|
goto &arry_extract_i; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub arry_assign_s(\@$%) { |
|
53
|
5
|
|
|
5
|
1
|
941
|
my ($target,$mapping,%assignments) = @_; |
|
54
|
5
|
|
|
|
|
25
|
while (my ($name,$value) = each %assignments) { |
|
55
|
11
|
|
|
|
|
27
|
my $idx = $mapping->{$name}; |
|
56
|
11
|
50
|
|
|
|
28
|
die("Unknown name '$name'") unless defined $idx; |
|
57
|
11
|
|
|
|
|
45
|
$target->[$idx] = $value; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
5
|
|
|
|
|
17
|
$target; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub arry_assign_i(\@%) |
|
63
|
|
|
|
|
|
|
{ |
|
64
|
4
|
|
|
4
|
1
|
795
|
my ($target,%mappings) = @_; |
|
65
|
4
|
|
|
|
|
25
|
_idx_sanity_check(%mappings); |
|
66
|
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
12
|
@{$target}[keys %mappings] = values %mappings; |
|
|
4
|
|
|
|
|
20
|
|
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub arry_extract_i(\@%) |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
4
|
|
|
4
|
1
|
854
|
my ($source,%targets) = @_; |
|
74
|
4
|
|
|
|
|
15
|
_idx_sanity_check(%targets); |
|
75
|
4
|
|
|
|
|
19
|
while ( my ($idx,$ref) = each %targets) { |
|
76
|
8
|
|
|
|
|
40
|
$$ref = $source->[$idx]; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub arry_extract_s(\@$%) { |
|
81
|
4
|
|
|
4
|
1
|
798
|
my ($source,$mappings,%targets) = @_; |
|
82
|
4
|
|
|
|
|
18
|
while (my ($name,$ref) = each %targets) { |
|
83
|
9
|
|
|
|
|
16
|
my $idx = $mappings->{$name}; |
|
84
|
9
|
50
|
|
|
|
21
|
if(!defined $idx) { |
|
85
|
0
|
|
|
|
|
0
|
die("unknown parameter '$name'"); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
9
|
|
|
|
|
43
|
$$ref = $source->[$idx]; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _idx_sanity_check { |
|
92
|
8
|
|
|
8
|
|
22
|
my %mappings = @_; |
|
93
|
8
|
50
|
|
|
|
53
|
if(scalar (grep $_ > $IDX_MAX, keys %mappings) > 0) { |
|
94
|
0
|
|
|
|
|
|
die("Abnormally large index found. ". |
|
95
|
|
|
|
|
|
|
"Bump up \$IDX_MAX if this is not a mistake"); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |