line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::EX::Numbers; |
2
|
1
|
|
|
1
|
|
79620
|
use version; our $VERSION = version->declare("2.1.4"); |
|
1
|
|
|
|
|
2088
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
115
|
use v5.14; |
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
78
|
|
8
|
1
|
|
|
1
|
|
22
|
use List::Util qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
9
|
1
|
|
|
1
|
|
663
|
use Hash::Util qw(lock_keys); |
|
1
|
|
|
|
|
2969
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
88
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
11
|
|
|
|
|
|
|
$Data::Dumper::Sortkeys = 1; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
307
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _default { |
17
|
|
|
|
|
|
|
return { |
18
|
6
|
|
|
6
|
|
29
|
min => 0, |
19
|
|
|
|
|
|
|
max => undef, |
20
|
|
|
|
|
|
|
start => '', |
21
|
|
|
|
|
|
|
end => '', |
22
|
|
|
|
|
|
|
step => '', |
23
|
|
|
|
|
|
|
length => '', |
24
|
|
|
|
|
|
|
_spec => undef, |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
6
|
|
|
6
|
1
|
1249
|
my $class = shift; |
30
|
6
|
|
|
|
|
15
|
my $obj = bless _default(), $class; |
31
|
6
|
|
|
|
|
10
|
lock_keys %{$obj}; |
|
6
|
|
|
|
|
26
|
|
32
|
6
|
50
|
|
|
|
84
|
@_ % 2 and croak "invalid number of parameters"; |
33
|
6
|
|
|
|
|
35
|
while (my($key, $value) = splice(@_, 0, 2)) { |
34
|
15
|
50
|
|
|
|
31
|
croak "$key: invalid parameter" if not exists $obj->{$key}; |
35
|
15
|
|
|
|
|
41
|
$obj->{$key} = $value; |
36
|
|
|
|
|
|
|
} |
37
|
6
|
|
|
|
|
30
|
$obj; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub parse { |
41
|
31
|
|
|
31
|
1
|
19743
|
my $obj = shift; |
42
|
31
|
|
|
|
|
55
|
local $_ = shift; |
43
|
31
|
50
|
|
|
|
222
|
if (m{ |
44
|
|
|
|
|
|
|
^ |
45
|
|
|
|
|
|
|
(? -\d+ | \d* ) |
46
|
|
|
|
|
|
|
(?: |
47
|
|
|
|
|
|
|
(?: \.\. | : ) (? [-+]\d+ | \d* ) |
48
|
|
|
|
|
|
|
(?: |
49
|
|
|
|
|
|
|
: (? \d* ) |
50
|
|
|
|
|
|
|
(?: |
51
|
|
|
|
|
|
|
: (? \d* ) |
52
|
|
|
|
|
|
|
)? |
53
|
|
|
|
|
|
|
)? |
54
|
|
|
|
|
|
|
)? |
55
|
|
|
|
|
|
|
$ |
56
|
|
|
|
|
|
|
}x) { |
57
|
1
|
|
|
1
|
|
488
|
$obj->{start} = $+{start}; |
|
1
|
|
|
|
|
390
|
|
|
1
|
|
|
|
|
629
|
|
|
31
|
|
|
|
|
198
|
|
58
|
31
|
|
|
|
|
163
|
$obj->{end} = $+{end}; |
59
|
31
|
|
|
|
|
106
|
$obj->{step} = $+{step}; |
60
|
31
|
|
|
|
|
96
|
$obj->{length} = $+{length}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
0
|
|
|
|
|
0
|
carp "$_: format error"; |
64
|
0
|
|
|
|
|
0
|
return undef; |
65
|
|
|
|
|
|
|
} |
66
|
31
|
|
|
|
|
63
|
$obj->{_spec} = $_; |
67
|
31
|
|
|
|
|
102
|
$obj; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub range { |
71
|
32
|
|
|
32
|
1
|
52
|
my $obj = shift; |
72
|
32
|
|
|
|
|
46
|
my $max = $obj->{max}; |
73
|
32
|
|
|
|
|
44
|
my $min = $obj->{min}; |
74
|
|
|
|
|
|
|
|
75
|
32
|
|
|
|
|
46
|
my $start = $obj->{start}; |
76
|
32
|
|
|
|
|
45
|
my $end = $obj->{end}; |
77
|
32
|
|
|
|
|
46
|
my $step = $obj->{step}; |
78
|
32
|
|
|
|
|
47
|
my $length = $obj->{length}; |
79
|
|
|
|
|
|
|
|
80
|
32
|
100
|
|
|
|
75
|
if (not defined $max) { |
81
|
2
|
50
|
33
|
|
|
26
|
if ($start =~ /^-\d+$/ or |
|
|
|
33
|
|
|
|
|
82
|
|
|
|
|
|
|
(defined $end and $end =~ /^-\d+$/)) { |
83
|
0
|
|
|
|
|
0
|
carp "$_: max required"; |
84
|
0
|
|
|
|
|
0
|
return (); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
32
|
50
|
100
|
|
|
155
|
if ($start =~ /\d/ and defined $max and $start > $max) { |
|
|
|
66
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
return (); |
90
|
|
|
|
|
|
|
} |
91
|
32
|
100
|
|
|
|
76
|
if ($start eq '') { |
|
|
100
|
|
|
|
|
|
92
|
17
|
|
|
|
|
30
|
$start = $min; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ($start =~ /^-\d+$/) { |
95
|
2
|
|
|
|
|
8
|
$start = List::Util::max($min, $start + $max); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
32
|
100
|
|
|
|
105
|
if (not defined $end) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
99
|
3
|
|
|
|
|
6
|
$end = $start; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif ($end eq '') { |
102
|
7
|
50
|
|
|
|
18
|
$end = defined $max ? $max : $start; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif ($end =~ /^-/) { |
105
|
2
|
|
|
|
|
7
|
$end = List::Util::max(0, $end + $max); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
elsif ($end =~ s/^\+//) { |
108
|
1
|
|
|
|
|
3
|
$end += $start; |
109
|
|
|
|
|
|
|
} |
110
|
32
|
100
|
100
|
|
|
121
|
$end = $max if defined $max and $end > $max; |
111
|
|
|
|
|
|
|
|
112
|
32
|
|
100
|
|
|
90
|
$length ||= 1; |
113
|
32
|
|
66
|
|
|
93
|
$step ||= $length; |
114
|
|
|
|
|
|
|
|
115
|
32
|
|
|
|
|
53
|
my @l; |
116
|
32
|
100
|
|
|
|
53
|
if ($step == 1) { |
117
|
15
|
|
|
|
|
39
|
@l = ( [$start, $end] ); |
118
|
|
|
|
|
|
|
} else { |
119
|
17
|
|
|
|
|
50
|
for (my $from = $start; $from <= $end; $from += $step) { |
120
|
75
|
|
|
|
|
110
|
my $to = $from + $length - 1; |
121
|
75
|
100
|
|
|
|
148
|
$to = List::Util::min($max, $to) if defined $max; |
122
|
75
|
|
|
|
|
182
|
push @l, [$from, $to]; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
32
|
|
|
|
|
100
|
return @l; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub sequence { |
130
|
17
|
|
|
17
|
1
|
25
|
my $obj = shift; |
131
|
17
|
50
|
|
|
|
34
|
map { ref $_ eq 'ARRAY' ? ($_->[0] .. $_->[1]) : $_ } $obj->range; |
|
57
|
|
|
|
|
182
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |