line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Range; |
2
|
5
|
|
|
5
|
|
63990
|
use 5.008001; |
|
5
|
|
|
|
|
15
|
|
3
|
5
|
|
|
5
|
|
21
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
95
|
|
4
|
5
|
|
|
5
|
|
21
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
233
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
2346
|
use Class::Accessor::Lite ro => [qw/name lower upper/]; |
|
5
|
|
|
|
|
4864
|
|
|
5
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
357
|
use overload '@{}' => sub { [shift->all] }, |
10
|
5
|
|
|
5
|
|
4732
|
fallback => 1; |
|
5
|
|
|
|
|
3558
|
|
|
5
|
|
|
|
|
40
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
296
|
use Carp qw/croak/; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
1749
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
28
|
|
|
28
|
1
|
2551
|
my ($class, %args) = @_; |
16
|
28
|
|
|
|
|
98
|
my $self = bless { |
17
|
|
|
|
|
|
|
lower => '-Inf', |
18
|
|
|
|
|
|
|
upper => '+Inf', |
19
|
|
|
|
|
|
|
name => '', |
20
|
|
|
|
|
|
|
%args, |
21
|
|
|
|
|
|
|
} => $class; |
22
|
|
|
|
|
|
|
$self->{lower} <= $self->{upper} |
23
|
28
|
100
|
|
|
|
380
|
or croak "Cannot make a range by $self->{lower}..$self->{upper}"; |
24
|
27
|
|
|
|
|
84
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub includes { |
28
|
32
|
|
|
32
|
1
|
35
|
my $self = shift; |
29
|
32
|
100
|
|
|
|
73
|
if (ref $_[0] eq 'CODE') { |
30
|
6
|
|
|
|
|
5
|
my $code = shift; |
31
|
|
|
|
|
|
|
|
32
|
6
|
|
|
|
|
4
|
my $tmp; # for preformance |
33
|
|
|
|
|
|
|
return grep { |
34
|
6
|
|
|
|
|
7
|
$tmp = $code->($_); |
|
17
|
|
|
|
|
17
|
|
35
|
|
|
|
|
|
|
$self->{lower} <= $tmp && $tmp <= $self->{upper} |
36
|
17
|
50
|
|
|
|
80
|
} @_; |
37
|
|
|
|
|
|
|
} |
38
|
26
|
100
|
|
|
|
33
|
return grep { $self->{lower} <= $_ && $_ <= $self->{upper} } @_; |
|
37
|
|
|
|
|
247
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub excludes { |
42
|
12
|
|
|
12
|
1
|
13
|
my $self = shift; |
43
|
12
|
100
|
|
|
|
24
|
if (ref $_[0] eq 'CODE') { |
44
|
6
|
|
|
|
|
4
|
my $code = shift; |
45
|
6
|
|
|
|
|
3
|
my $tmp; # for preformance |
46
|
|
|
|
|
|
|
return grep { |
47
|
6
|
|
|
|
|
7
|
$tmp = $code->($_); |
|
17
|
|
|
|
|
20
|
|
48
|
17
|
50
|
|
|
|
95
|
$tmp < $self->{lower} || $self->{upper} < $tmp |
49
|
|
|
|
|
|
|
} @_; |
50
|
|
|
|
|
|
|
} |
51
|
6
|
100
|
|
|
|
7
|
return grep { $_ < $self->{lower} || $self->{upper} < $_ } @_; |
|
17
|
|
|
|
|
60
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# for duck typing |
55
|
1
|
|
|
1
|
0
|
4
|
sub ranges { [shift] } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub all { |
58
|
4
|
|
|
4
|
1
|
384
|
my $self = shift; |
59
|
4
|
100
|
|
|
|
7
|
croak 'lower is infinit' if $self->lower == '-Inf'; |
60
|
3
|
100
|
|
|
|
21
|
croak 'upper is infinit' if $self->upper == '+Inf'; |
61
|
2
|
|
|
|
|
11
|
return ($self->lower..$self->upper); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |