line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Reverse::Util; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Utils |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Exporter; |
6
|
|
|
|
|
|
|
our @ISA='Exporter'; |
7
|
|
|
|
|
|
|
our @EXPORT = qw(partition partition_by); |
8
|
|
|
|
|
|
|
our $VERSION = '0.202'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# port from Clojure |
11
|
|
|
|
|
|
|
sub partition{ |
12
|
31
|
|
|
31
|
0
|
1814
|
my($len, $step, @list) = @_; |
13
|
31
|
|
|
|
|
55
|
my @ret; |
14
|
31
|
|
|
|
|
114
|
for(my $i=0; $i<@list-$len+1; $i+=$step){ |
15
|
50
|
|
|
|
|
177
|
my @sublist = @list[$i..$i+$len-1]; |
16
|
50
|
|
|
|
|
165
|
push(@ret, \@sublist); |
17
|
|
|
|
|
|
|
} |
18
|
31
|
|
|
|
|
110
|
return @ret; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# port from Clojure |
22
|
|
|
|
|
|
|
sub partition_by{ |
23
|
32
|
|
|
32
|
0
|
6441
|
my($funcref, @list) = @_; |
24
|
32
|
|
|
|
|
76
|
my @ret; |
25
|
|
|
|
|
|
|
my $curarr; |
26
|
32
|
|
|
|
|
102
|
foreach my $item (@list){ |
27
|
275
|
100
|
|
|
|
610
|
if( $funcref->($item) ){ |
28
|
50
|
100
|
|
|
|
379
|
if($curarr){ |
29
|
49
|
|
|
|
|
92
|
push(@ret, $curarr); |
30
|
|
|
|
|
|
|
} |
31
|
50
|
|
|
|
|
116
|
push(@ret, [$item]); |
32
|
50
|
|
|
|
|
105
|
$curarr = []; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else{ |
35
|
225
|
|
|
|
|
1153
|
push(@{$curarr}, $item); |
|
225
|
|
|
|
|
494
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
32
|
100
|
|
|
|
56
|
push(@ret, $curarr) if @{$curarr} > 0; |
|
32
|
|
|
|
|
105
|
|
39
|
32
|
|
|
|
|
122
|
return @ret; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |