line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PerlX::Range; |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
14557
|
use strict; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
414
|
|
4
|
12
|
|
|
12
|
|
138
|
use warnings; |
|
12
|
|
|
|
|
52
|
|
|
12
|
|
|
|
|
297
|
|
5
|
12
|
|
|
12
|
|
241
|
use 5.010; |
|
12
|
|
|
|
|
42
|
|
|
12
|
|
|
|
|
477
|
|
6
|
12
|
|
|
12
|
|
10115
|
use B::Hooks::OP::Check; |
|
12
|
|
|
|
|
29633
|
|
|
12
|
|
|
|
|
346
|
|
7
|
12
|
|
|
12
|
|
10057
|
use B::Hooks::EndOfScope; |
|
12
|
|
|
|
|
179294
|
|
|
12
|
|
|
|
|
90
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use overload |
12
|
|
|
|
|
|
|
'@{}' => sub { |
13
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
14
|
0
|
|
|
|
|
0
|
my @a = $self->to_a; |
15
|
0
|
|
|
|
|
0
|
return \@a; |
16
|
|
|
|
|
|
|
}, |
17
|
|
|
|
|
|
|
'""' => sub { |
18
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
19
|
0
|
|
|
|
|
0
|
return $self->{first} . ".." . $self->{last}; |
20
|
12
|
|
|
12
|
|
24908
|
}; |
|
12
|
|
|
|
|
13824
|
|
|
12
|
|
|
|
|
150
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
|
|
my ($class, %args) = @_; |
24
|
0
|
|
|
|
|
|
my $self = bless {%args}, $class; |
25
|
0
|
|
|
|
|
|
$self->{current} = $self->min; |
26
|
0
|
|
|
|
|
|
$self->{by} = 1; |
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub xrange { |
31
|
0
|
|
|
0
|
|
|
my ($first, $last) = @_; |
32
|
0
|
|
|
|
|
|
return __PACKAGE__->new(first => $first, last => $last); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub items { |
36
|
0
|
|
|
0
|
|
|
my $self = shift; |
37
|
12
|
|
|
12
|
|
13198
|
use integer; |
|
12
|
|
|
|
|
118
|
|
|
12
|
|
|
|
|
63
|
|
38
|
0
|
|
|
|
|
|
return ($self->{last} - $self->{first})/($self->{by}) + 1 |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub first { |
42
|
0
|
|
|
0
|
|
|
$_[0]->{first} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub last { |
46
|
0
|
|
|
0
|
|
|
$_[0]->{last} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
*min = *from = \&first; |
50
|
|
|
|
|
|
|
*max = *to = \&last; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub to_a { |
53
|
0
|
|
|
0
|
|
|
my $self = shift; |
54
|
0
|
|
|
|
|
|
my @r = (); |
55
|
0
|
|
|
0
|
|
|
$self->each(sub { push @r, $_ }); |
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return @r; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub by { |
60
|
0
|
|
|
0
|
|
|
my ($self, $n) = @_; |
61
|
0
|
0
|
|
|
|
|
$self->{by} = $n if $n; |
62
|
0
|
|
|
|
|
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub each { |
66
|
0
|
|
|
0
|
|
|
my $cb = pop; |
67
|
0
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $current = $self->min; |
70
|
0
|
|
0
|
|
|
|
while('*' eq $self->max || $current <= $self->max) { |
71
|
0
|
|
|
|
|
|
local $_ = $current; |
72
|
0
|
|
|
|
|
|
my $ret = $cb->($self, $_); |
73
|
0
|
0
|
0
|
|
|
|
last if (defined($ret) && !$ret); |
74
|
0
|
0
|
|
|
|
|
$current += $self->{by} ? $self->{by} : 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub next { |
79
|
0
|
|
|
0
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ($self->{current} > $self->max) { |
82
|
0
|
|
|
|
|
|
$self->{current} = $self->min; |
83
|
0
|
|
|
|
|
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
$self->{current} += 1; |
86
|
0
|
|
|
|
|
|
return $self->{current}-1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
require XSLoader; |
90
|
|
|
|
|
|
|
XSLoader::load('PerlX::Range', $VERSION); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub import { |
93
|
0
|
0
|
|
0
|
|
|
return if $^H{PerlXRange}; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
feature->import(':5.10'); |
96
|
0
|
|
|
|
|
|
$^H &= 0x00020000; |
97
|
0
|
|
|
|
|
|
$^H{PerlXRange} = 1; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
add_flop_hook(); |
100
|
|
|
|
|
|
|
on_scope_end { |
101
|
0
|
|
|
0
|
|
|
remove_flop_hook(); |
102
|
0
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub unimport { |
106
|
0
|
|
|
0
|
|
|
remove_flop_hook(); |
107
|
0
|
|
|
|
|
|
$^H &= ~0x00020000; |
108
|
0
|
|
|
|
|
|
delete $^H{PerlXRange}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
__END__ |