line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Range::Iter; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-04-16'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
79365
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
276
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(range_iter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $re_num = qr/\A[+-]?[0-9]+(\.[0-9]+)?\z/; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub range_iter($$;$) { |
15
|
7
|
|
|
7
|
1
|
3401
|
my ($start, $end, $step) = @_; |
16
|
7
|
|
100
|
|
|
31
|
$step //= 1; |
17
|
|
|
|
|
|
|
|
18
|
7
|
|
|
|
|
12
|
my $value = $start; |
19
|
7
|
|
|
|
|
10
|
my $ended; |
20
|
|
|
|
|
|
|
|
21
|
7
|
100
|
66
|
|
|
73
|
if ($start =~ $re_num && $end =~ $re_num) { |
22
|
|
|
|
|
|
|
# numeric version |
23
|
4
|
100
|
|
|
|
12
|
$ended++ if $value > $end; |
24
|
|
|
|
|
|
|
sub { |
25
|
13
|
100
|
|
13
|
|
68
|
$ended++ if $value > $end; |
26
|
13
|
100
|
|
|
|
25
|
return undef if $ended; |
27
|
9
|
|
|
|
|
14
|
my $old = $value; |
28
|
9
|
|
|
|
|
11
|
$value+=$step; |
29
|
9
|
|
|
|
|
14
|
return $old; |
30
|
4
|
|
|
|
|
29
|
}; |
31
|
|
|
|
|
|
|
} else { |
32
|
3
|
50
|
|
|
|
9
|
die "Cannot specify step != 1 for non-numeric range" if $step != 1; |
33
|
3
|
100
|
|
|
|
10
|
$ended++ if $value gt $end; |
34
|
|
|
|
|
|
|
sub { |
35
|
30
|
100
|
|
30
|
|
100
|
return undef if $ended; |
36
|
27
|
100
|
|
|
|
48
|
$ended++ if $value ge $end; |
37
|
27
|
|
|
|
|
45
|
$value++; |
38
|
3
|
|
|
|
|
22
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
# ABSTRACT: Generate a coderef iterator for range |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |