line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sub::Sequence; |
2
|
3
|
|
|
3
|
|
75291
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
120
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
100
|
|
4
|
3
|
|
|
3
|
|
2806
|
use parent qw/Exporter/; |
|
3
|
|
|
|
|
1115
|
|
|
3
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw/ |
9
|
|
|
|
|
|
|
seq |
10
|
|
|
|
|
|
|
/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub seq { |
13
|
16
|
|
|
16
|
1
|
11133
|
my ($list, $every, $code) = @_; |
14
|
|
|
|
|
|
|
|
15
|
16
|
100
|
|
|
|
56
|
_croak("First arg must ARRAY REF: $list") if ref($list) ne 'ARRAY'; |
16
|
15
|
100
|
|
|
|
45
|
_croak("Second arg is wrong: $every") if $every < 1; |
17
|
14
|
100
|
|
|
|
44
|
_croak("Third arg must CODE REF: $code") if ref($code) ne 'CODE'; |
18
|
|
|
|
|
|
|
|
19
|
13
|
|
|
|
|
16
|
my $loop = 0; |
20
|
13
|
|
|
|
|
15
|
my @result; |
21
|
|
|
|
|
|
|
|
22
|
13
|
|
|
|
|
14
|
my $last = $#{$list}; |
|
13
|
|
|
|
|
23
|
|
23
|
|
|
|
|
|
|
|
24
|
13
|
|
|
|
|
23
|
while (1) { |
25
|
42
|
|
|
|
|
70
|
my $start = $loop * $every; |
26
|
42
|
100
|
|
|
|
87
|
last if $start > $last; |
27
|
29
|
|
|
|
|
37
|
my $end = $start + $every - 1; |
28
|
29
|
100
|
|
|
|
54
|
if ($end > $last) { $end = $last; } |
|
10
|
|
|
|
|
14
|
|
29
|
29
|
|
|
|
|
31
|
$loop++; |
30
|
29
|
|
|
|
|
117
|
my $ret = $code->( |
31
|
29
|
|
|
|
|
42
|
+[ @{$list}[$start .. $end] ], |
32
|
|
|
|
|
|
|
$loop, |
33
|
|
|
|
|
|
|
($loop - 1) * $every |
34
|
|
|
|
|
|
|
); |
35
|
29
|
100
|
66
|
|
|
184
|
if (wantarray && ref($ret) eq 'ARRAY') { |
36
|
2
|
|
|
|
|
4
|
push @result, @{$ret}; |
|
2
|
|
|
|
|
7
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
27
|
|
|
|
|
51
|
push @result, $ret; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
13
|
100
|
|
|
|
45
|
return wantarray ? @result : \@result; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _croak { |
47
|
3
|
|
|
3
|
|
27
|
require Carp; |
48
|
3
|
|
|
|
|
60
|
Carp::croak($_[0]); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |