line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Array::RealSpan; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENE'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Map real number ranges to labels or objects |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
803
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
10
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
814
|
use Moo; |
|
1
|
|
|
|
|
15225
|
|
|
1
|
|
|
|
|
6
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _ranges => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
default => sub { [] }, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub set_range { |
22
|
2
|
|
|
2
|
1
|
404
|
my ( $self, $start, $end, $label ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
2
|
50
|
33
|
|
|
25
|
croak('set_range() should be called with 3 values.') |
|
|
|
33
|
|
|
|
|
25
|
|
|
|
|
|
|
unless defined $start && defined $end && defined $label; |
26
|
2
|
50
|
|
|
|
7
|
croak("set_range() called with bad indices: $start, $end") |
27
|
|
|
|
|
|
|
if $end <= $start; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
4
|
push @{ $self->_ranges }, [ $start, $end, $label ]; |
|
2
|
|
|
|
|
18
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_range { |
34
|
1
|
|
|
1
|
1
|
3
|
my ( $self, $label ) = @_; |
35
|
1
|
|
|
|
|
2
|
my $get_range; |
36
|
1
|
|
|
|
|
2
|
for my $range ( @{ $self->_ranges } ) { |
|
1
|
|
|
|
|
5
|
|
37
|
1
|
50
|
|
|
|
4
|
if ( $label eq $range->[2] ) { |
38
|
1
|
|
|
|
|
5
|
$get_range = [ $range->[0], $range->[1] ]; |
39
|
1
|
|
|
|
|
2
|
last; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
6
|
return $get_range; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub lookup { |
47
|
3
|
|
|
3
|
1
|
332
|
my ( $self, $number ) = @_; |
48
|
3
|
|
|
|
|
34
|
my $lookup; |
49
|
3
|
|
|
|
|
4
|
for my $range ( @{ $self->_ranges } ) { |
|
3
|
|
|
|
|
10
|
|
50
|
4
|
100
|
66
|
|
|
24
|
if ( $number >= $range->[0] && $number < $range->[1] ) { |
51
|
2
|
|
|
|
|
3
|
$lookup = $range->[2]; |
52
|
2
|
|
|
|
|
5
|
last; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
3
|
|
|
|
|
15
|
return $lookup; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |