line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MFor; |
2
|
3
|
|
|
3
|
|
120864
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
144
|
|
3
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
4909
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
6
|
|
|
|
|
|
|
our @EXPORT = qw(&mfor); |
7
|
|
|
|
|
|
|
our $VERSION = '0.052'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub mfor(&@); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub mfor(&@) { |
12
|
35
|
|
|
35
|
1
|
35633
|
my $cr = shift; |
13
|
35
|
|
|
|
|
38
|
my $h_arrs; |
14
|
|
|
|
|
|
|
|
15
|
35
|
100
|
66
|
|
|
351
|
if ( ref( $_[0] ) eq 'ARRAY' and ref( $_[1] ) eq 'ARRAY' ) { |
16
|
14
|
|
|
|
|
19
|
$h_arrs = shift; # array |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
35
|
|
|
|
|
45
|
my $arrs = shift; |
20
|
|
|
|
|
|
|
|
21
|
35
|
|
|
|
|
37
|
my ( $arr_lev, $arr_idx ); |
22
|
35
|
100
|
|
|
|
86
|
( $arr_lev, $arr_idx ) = @_ if (@_); |
23
|
|
|
|
|
|
|
|
24
|
35
|
|
100
|
|
|
84
|
$arr_lev ||= 0; |
25
|
35
|
|
|
|
|
59
|
my $arr_sz = scalar(@$arrs); |
26
|
|
|
|
|
|
|
|
27
|
35
|
100
|
|
|
|
66
|
unless ($arr_idx) { |
28
|
11
|
|
|
|
|
57
|
push @$arr_idx, 0 for ( 1 .. $arr_sz ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
35
|
|
|
|
|
51
|
my $cur_arr = $arrs->[$arr_lev]; |
32
|
35
|
|
|
|
|
49
|
my $idx = scalar(@$cur_arr); |
33
|
35
|
100
|
|
|
|
71
|
if ( $arr_sz == $arr_lev + 1 ) { |
34
|
27
|
|
|
|
|
40
|
my @args = (); |
35
|
27
|
|
|
|
|
30
|
my $tlev = 0; |
36
|
|
|
|
|
|
|
|
37
|
27
|
|
|
|
|
48
|
for (@$arr_idx) { |
38
|
54
|
50
|
|
|
|
107
|
last if ( !$arrs->[$tlev]->[$_] ); |
39
|
54
|
|
|
|
|
78
|
push @args, $arrs->[$tlev]->[$_]; |
40
|
54
|
|
|
|
|
81
|
$tlev++; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
27
|
|
|
|
|
70
|
for my $i ( 0 .. $idx - 1 ) { |
44
|
153
|
|
|
|
|
42551
|
$args[ $tlev - 1 ] = $arrs->[ $tlev - 1 ]->[$i]; |
45
|
153
|
100
|
|
|
|
309
|
if ($h_arrs) { |
46
|
|
|
|
|
|
|
# merge args and hash key to a hash |
47
|
54
|
|
|
|
|
73
|
my $index = 0; |
48
|
54
|
|
|
|
|
78
|
my $hash_args = {}; |
49
|
54
|
|
|
|
|
149
|
map { $hash_args->{ $_ } = $args[$index++]; } @$h_arrs; |
|
86
|
|
|
|
|
272
|
|
50
|
54
|
|
|
|
|
113
|
$cr->( $hash_args ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
99
|
|
|
|
|
152
|
$cr->(@args); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
|
|
|
|
|
|
|
59
|
8
|
100
|
|
|
|
16
|
if ($h_arrs) { |
60
|
2
|
|
|
|
|
6
|
for my $i ( 0 .. $idx - 1 ) { |
61
|
8
|
|
|
|
|
9746
|
$arr_idx->[$arr_lev] = $i; |
62
|
8
|
|
|
32
|
|
82
|
mfor {&$cr} $h_arrs, $arrs, $arr_lev + 1, $arr_idx; |
|
32
|
|
|
|
|
52
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
6
|
|
|
|
|
18
|
for my $i ( 0 .. $idx - 1 ) { |
67
|
16
|
|
|
|
|
2739
|
$arr_idx->[$arr_lev] = $i; |
68
|
16
|
|
|
145
|
|
94
|
mfor {&$cr} $arrs, $arr_lev + 1, $arr_idx; |
|
145
|
|
|
|
|
197
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
8
|
|
|
|
|
2718
|
$arr_idx->[$arr_lev] = 0; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub it (@); |
78
|
|
|
|
|
|
|
sub it (@) { |
79
|
10
|
100
|
|
10
|
1
|
51
|
if( ref $_[0] ) { # blessed |
80
|
3
|
|
|
|
|
7
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
3
|
100
|
66
|
|
|
19
|
if( @_ and ref($_[0]) eq 'HASH' ) { |
83
|
2
|
|
|
|
|
3
|
my %arr_hash = %{+ shift }; |
|
2
|
|
|
|
|
6
|
|
84
|
2
|
|
|
|
|
5
|
my ($key) = keys %arr_hash; |
85
|
2
|
|
|
|
|
4
|
my @values = values %arr_hash; |
86
|
2
|
|
|
|
|
5
|
$self->_sub_it_hash( $key , @values ); |
87
|
|
|
|
|
|
|
} else { |
88
|
1
|
|
|
|
|
4
|
$self->_sub_it( @_ ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
|
|
17
|
return $self; |
93
|
|
|
|
|
|
|
} else { # unblessed |
94
|
|
|
|
|
|
|
# do bless |
95
|
7
|
|
|
|
|
12
|
my $class = shift; |
96
|
7
|
|
|
|
|
14
|
my $self = {}; |
97
|
7
|
|
|
|
|
20
|
$self = bless $self , $class; |
98
|
|
|
|
|
|
|
|
99
|
7
|
|
|
|
|
25
|
$self->{ARRAY} = []; |
100
|
7
|
100
|
66
|
|
|
57
|
if( @_ and ref($_[0]) eq 'HASH' ) { |
101
|
5
|
|
|
|
|
8
|
my %arr_hash = %{+ shift }; |
|
5
|
|
|
|
|
26
|
|
102
|
5
|
|
|
|
|
13
|
$self->{HASH_NAME} = []; |
103
|
5
|
|
|
|
|
12
|
my ($key) = keys %arr_hash; |
104
|
5
|
|
|
|
|
13
|
my @values = values %arr_hash; |
105
|
5
|
|
|
|
|
21
|
$self->_sub_it_hash( $key , @values ); |
106
|
|
|
|
|
|
|
} else { |
107
|
2
|
|
|
|
|
7
|
$self->_sub_it( @_ ); |
108
|
|
|
|
|
|
|
} |
109
|
7
|
|
|
|
|
52
|
return $self; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _sub_it_hash { |
114
|
7
|
|
|
7
|
|
23
|
my $self = shift; |
115
|
7
|
|
|
|
|
30
|
my ($key,@values) = @_; |
116
|
7
|
|
|
|
|
11
|
push @{ $self->{HASH_NAME} }, $key; |
|
7
|
|
|
|
|
15
|
|
117
|
7
|
|
|
|
|
9
|
push @{ $self->{ARRAY} }, @values; |
|
7
|
|
|
|
|
14
|
|
118
|
7
|
|
|
|
|
22
|
return $self; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _sub_it { |
122
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
123
|
3
|
|
|
|
|
3
|
push @{ $self->{ARRAY} }, [@_]; |
|
3
|
|
|
|
|
11
|
|
124
|
3
|
|
|
|
|
5
|
return $self; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub when { |
129
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
130
|
3
|
|
|
|
|
6
|
my ($op_and,$op,$op_and2) = @_; |
131
|
3
|
|
|
|
|
16
|
$self->{COND} = { OP1 => $op_and, OPAND => $op, OP2 => $op_and2 }; |
132
|
3
|
|
|
|
|
23
|
return $self; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub do (&) { |
136
|
7
|
|
|
7
|
0
|
11
|
my $self = shift; |
137
|
7
|
|
|
|
|
10
|
my $sub = shift; |
138
|
7
|
|
|
|
|
10
|
my $array = [ @{ $self->{ARRAY} } ] ; |
|
7
|
|
|
|
|
53
|
|
139
|
|
|
|
|
|
|
|
140
|
7
|
100
|
|
|
|
18
|
if ( defined $self->{HASH_NAME} ) { |
141
|
|
|
|
|
|
|
|
142
|
5
|
100
|
|
|
|
13
|
if( defined $self->{COND} ) { |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
mfor { |
145
|
24
|
50
|
|
24
|
|
93
|
if ( defined $_[0]->{ $self->{COND}->{OP1} } ) { |
146
|
24
|
|
|
|
|
105
|
my $ret; |
147
|
24
|
|
|
|
|
183
|
my $eval = sprintf( |
148
|
|
|
|
|
|
|
'$ret = ( %s %s %s ) ? 1 : 0;', |
149
|
|
|
|
|
|
|
$_[0]->{ $self->{COND}->{OP1} }, |
150
|
|
|
|
|
|
|
$self->{COND}->{OPAND}, |
151
|
|
|
|
|
|
|
$self->{COND}->{OP2} |
152
|
|
|
|
|
|
|
); |
153
|
24
|
|
|
|
|
6629
|
eval $eval; |
154
|
24
|
100
|
|
|
|
166
|
$sub->(@_) if $ret; |
155
|
|
|
|
|
|
|
} |
156
|
3
|
|
|
|
|
16
|
} $self->{HASH_NAME}, $array; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
else { |
161
|
2
|
|
|
20
|
|
14
|
mfor { $sub->(@_); } $self->{HASH_NAME}, $array; |
|
20
|
|
|
|
|
59
|
|
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
else{ |
166
|
|
|
|
|
|
|
mfor { |
167
|
20
|
|
|
20
|
|
40
|
$sub->( @_ ); |
168
|
2
|
|
|
|
|
11
|
} $array; |
169
|
|
|
|
|
|
|
} |
170
|
7
|
|
|
|
|
2857
|
delete $self->{ARRAY}; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |