line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Set::IntSpan::Util; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
55359
|
use 5.010001; |
|
1
|
|
|
|
|
11
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
260
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
10
|
|
|
|
|
|
|
our $DATE = '2022-01-10'; # DATE |
11
|
|
|
|
|
|
|
our $DIST = 'Set-IntSpan-Util'; # DIST |
12
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(intspans2str); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub intspans2str { |
17
|
5
|
|
|
5
|
1
|
3109
|
require Set::IntSpan; |
18
|
|
|
|
|
|
|
|
19
|
5
|
100
|
|
|
|
8350
|
my $opts = ref($_[0]) eq 'HASH' ? shift : {}; |
20
|
5
|
|
100
|
|
|
24
|
$opts->{dash} //= "-"; |
21
|
5
|
|
100
|
|
|
19
|
$opts->{comma} //= ", "; |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
|
|
16
|
my @sets = Set::IntSpan->new(@_)->sets; |
24
|
5
|
|
|
|
|
2696
|
my @res; |
25
|
5
|
|
|
|
|
10
|
for my $set (@sets) { |
26
|
14
|
|
|
|
|
30
|
my $min = $set->min; |
27
|
14
|
|
|
|
|
148
|
my $max = $set->max; |
28
|
14
|
|
|
|
|
136
|
my ($smin, $smax); |
29
|
14
|
50
|
|
|
|
26
|
if (!defined($min)) { |
30
|
0
|
|
|
|
|
0
|
$smin = "-Inf"; |
31
|
|
|
|
|
|
|
} |
32
|
14
|
50
|
|
|
|
22
|
if (!defined($max)) { |
33
|
0
|
0
|
|
|
|
0
|
$smax = defined $min ? "Inf" : "+Inf"; |
34
|
|
|
|
|
|
|
} |
35
|
14
|
100
|
33
|
|
|
50
|
if (defined $min && defined $max && $min == $max) { |
|
|
|
66
|
|
|
|
|
36
|
10
|
|
|
|
|
17
|
push @res, $min; |
37
|
|
|
|
|
|
|
} else { |
38
|
4
|
|
33
|
|
|
26
|
push @res, ($smin // $min) . $opts->{dash} . ($smax // $max); |
|
|
|
33
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
5
|
|
|
|
|
35
|
join($opts->{comma}, @res); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
# ABSTRACT: Utility routines related to integer spans |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |