| 1 | package Range::Object::Interval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This is basically what common::sense does, but without the pragma itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # to remain compatible with Perls older than 5.8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings qw(FATAL closed internal debugging pack malloc portable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | prototype inplace io pipe unpack deprecated glob digit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | printf reserved taint closure semicolon); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | no warnings qw(exec newline unopened); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use List::Util qw( first ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use base qw(Range::Object); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Overload definitions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use overload q{""} => 'stringify_collapsed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | fallback => 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ### PUBLIC CLASS METHOD (CONSTRUCTOR) ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Initializes new instance of Range::Object::Interval from @input_range using | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # $interval length. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 25 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 25 | my ($class, $interval, @input_range) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 25 | ▶ | croak "Interval can be 15, 30 or 60 minutes not '$interval'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$interval != 15 and $interval != 30 and $interval != 60
$interval != 15 and $interval != 30
MC/DC0%0/3
$interval != 15 and $interval != 30 and $interval != 60
$interval != 15
$interval != 30
$interval != 60
Truth table75%3/4
A and B and C
A= $interval != 15B= $interval != 30C= $interval != 60
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | if $interval != 15 && $interval != 30 && $interval != 60; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 25 | my $self = bless { interval => $interval }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 25 | return $self->add(@input_range); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Returns sorted array or string representation of internal storage. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # In scalar context it can use optional list separator instead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # default one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 36 | ▶ | sub range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
range: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 36 | my ($self, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 36 | ▶ | return wantarray ? map { $self->_colonify($_) } $self->_full_range() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | : $self->stringify($separator) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Returns sorted and collapsed representation of internal storage. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # In list context, resulting list consists of separate values and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # range hashrefs with three elements: start, end and count. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # In scalar context, result is a string of separate values and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # ranges separated by value returned by delimiter() method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Optional list separator can be used instead of default one in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # scalar context. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 36 | ▶ | sub collapsed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collapsed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 36 | my ($self, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 36 | ▶ | return $self->stringify_collapsed($separator) unless wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | return map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | !ref($_) ? $self->_colonify($_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | start => $self->_colonify($_->{start}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | end => $self->_colonify($_->{end}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | count => $_->{count}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 72 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 18 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Returns the current range in military format. In scalar context it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # can use optional list $separator instead of default one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Note that this format cannot be fed back to add() or remove() since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # there is no way to distinguish certain time intervals in military | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # format from any run of the mill integer numbers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # military() always returns collapsed output in both list and scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # context. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 18 | ▶ | sub military { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
military: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 18 | my ($self, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 18 | ▶ | $separator ||= $self->_list_separator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$separator ||= $self->_list_separator
MC/DC0%0/2
$separator ||= $self->_list_separator
$separator
$self->_list_separator
Truth table33%1/3
A ||= B
A= $separatorB= $self->_list_separator
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 18 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | return map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | !ref($_) ? 0 + $_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | start => 0 + $_->{start}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | end => 0 + $_->{end}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | count => $_->{count}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 36 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 9 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | my @military_range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | !ref($_) ? 0+$_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | : $self->_stringify_range(0+$_->{start}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0+$_->{end}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 36 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 9 | return join $separator, @military_range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return; # Just in case, as usual | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Tests if items of @input_range are matching items in our internal storage. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Returns true/false in scalar context, list of mismatching items in list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # context. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 319 | ▶ | sub in { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 319 | my ($self, @input_range) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 319 | ▶ | return $self->SUPER::in(@input_range) unless wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 18 | my @invalid_values = map { $self->_colonify($_) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | $self->SUPER::in(@input_range); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 18 | return @invalid_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Returns string representation of all items in internal storage (sorted). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 18 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 18 | my ($self, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 18 | ▶ | $separator ||= $self->_list_separator(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$separator ||= $self->_list_separator
MC/DC0%0/2
$separator ||= $self->_list_separator
$separator
$self->_list_separator
Truth table33%1/3
A ||= B
A= $separatorB= $self->_list_separator
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 18 | my $delimiter = $self->delimiter(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | my @full_range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 242 | = map { $self->_colonify($_) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 18 | ref($_) ? $self->_stringify_range( $_->{start}, $_->{end} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 242 | ▶ | : "$_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $self->_full_range(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 18 | return join $separator, @full_range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Returns string representation of collapsed current range. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 36 | ▶ | sub stringify_collapsed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify_collapsed: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 36 | my ($self, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 36 | ▶ | $separator ||= $self->_list_separator(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$separator ||= $self->_list_separator
MC/DC0%0/2
$separator ||= $self->_list_separator
$separator
$self->_list_separator
Truth table33%1/3
A ||= B
A= $separatorB= $self->_list_separator
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | my @collapsed_range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 144 | = map { $self->_colonify($_) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ref($_) ? $self->_stringify_range( $_->{start}, $_->{end} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 144 | ▶ | : "$_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 36 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 36 | return join $separator, @collapsed_range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # Returns regex that is used to validate range items. Regex should | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # include patterns both for separate disjointed items and contiguous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # ranges. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 350 | ▶ | sub pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pattern: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 350 | return qr/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | (?<! [:0-9] ) # Can't have colon or digits behind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | (?: # Group but don't collect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | \d{2} # Two digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | : # Colon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | \d{2} # Two digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | ) # ... end group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | /xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Returns regex that is used to separate items in a range list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 350 | ▶ | sub separator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
separator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 350 | return qr/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | [,;] # Comma or semicolon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | \s* # Greedy whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | /xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # Returns range delimiter, for Interval it is forward slash (/) in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # compliance with ISO 8601. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1477 | ▶ | sub delimiter { '/' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delimiter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # Returns current object's interval length in minutes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 717 | ▶ | sub interval { $_[0]->{interval} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interval: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | ############## PRIVATE METHODS BELOW ############## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # Returns default list separator for use with stringify() and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # stringify_collapsed() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 72 | ▶ | sub _list_separator { q{,} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list_separator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # Validates and unpacks input @input_range of items, returns full list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 350 | ▶ | sub _validate_and_expand { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_and_expand: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 350 | my ($self, @input_range) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 350 | my $pattern = $self->pattern(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 350 | my $separator = $self->separator(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 350 | my $delimiter = $self->delimiter(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 350 | my $interval = $self->interval(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # We use hash to remove duplicates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 350 | my %temp = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # Validate and expand items in @input_range, add them if all OK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | ITEM: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 350 | ▶ | while ( @input_range ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 774 | my $item = shift @input_range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 774 | ▶ | if ( $separator && $item =~ $separator ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$separator and $item =~ /$separator/msx
MC/DC50%1/2
$separator and $item =~ /$separator/msx
$separator
$item =~ /$separator/msx
Truth table66%2/3
A and B
A= $separatorB= $item =~ /$separator/msx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 11 | unshift @input_range, split $separator, $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 11 | next ITEM; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 763 | ▶ | croak "Invalid input: $item" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$item and not $item =~ /$pattern/msx
MC/DC50%1/2
$item and not $item =~ /$pattern/msx
$item
not $item =~ /$pattern/msx
Truth table66%2/3
A and not(B)
A= $itemB= not $item =~ /$pattern/msx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | if $item && $item !~ $pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # Analogous to Range::Dates but not quite so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 762 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 762 | ▶ | if ( $item =~ m{ ($pattern) / ($pattern) }xms ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 25 | my ($start, $end) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # Remove colons | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 25 | $start =~ s/://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 25 | $end =~ s/://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 25 | my @full_list = $self->_explode_range($start.$delimiter.$end); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 22 | @temp{ @full_list } = (1) x @full_list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | elsif ( $item =~ / \A (\d{2}) : (\d{2}) \z /xms) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 736 | my ($hr, $mn) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 736 | ▶ | croak "Invalid input: '$item'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
not $hr =~ / \A \d{1,2} \z /msx or $hr < 0 or $hr > 23 or $mn % $interval != 0
not $hr =~ / \A \d{1,2} \z /msx or $hr < 0 or $hr > 23
not $hr =~ / \A \d{1,2} \z /msx or $hr < 0
MC/DC50%2/4
not $hr =~ / \A \d{1,2} \z /msx or $hr < 0 or $hr > 23 or $mn % $interval != 0
not $hr =~ / \A \d{1,2} \z /msx
$hr < 0
$hr > 23
$mn % $interval != 0
Truth table60%3/5
not(A) or B or C or D
A= not $hr =~ / \A \d{1,2} \z /msxB= $hr < 0C= $hr > 23D= $mn % $interval != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | if ( $hr !~ / \A \d{1,2} \z /xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | || $hr < 0 || $hr > 23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | || ($mn % $interval) != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 728 | my $interval_value = sprintf "%02d%02d", $hr, $mn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 728 | @temp{ $interval_value } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | croak "Invalid input: '$item'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # Order of items is important, and we treat them as numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 337 | my @validated_input = sort keys %temp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 337 | return @validated_input; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # Explodes stringified range of items using Perl range operator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 143 | ▶ | sub _explode_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_explode_range: called CC=16 SCAR=30.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 143 | my ($self, $item) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 143 | ▶ | croak "Invalid input: '$item'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | unless $item =~ m{ \A (\d{4}) / (\d{4}) \z }xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 143 | my ($first, $last) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 143 | my $interval = $self->interval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 143 | my ($fhr, $fmn) = $first =~ /\A (\d{2}) (\d{2}) \z/xms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 143 | ▶ | croak "Invalid input: '$first'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$fhr < 0 or $fhr > 23 or $fmn % $interval != 0
$fhr < 0 or $fhr > 23
MC/DC0%0/3
$fhr < 0 or $fhr > 23 or $fmn % $interval != 0
$fhr < 0
$fhr > 23
$fmn % $interval != 0
Truth table25%1/4
A or B or C
A= $fhr < 0B= $fhr > 23C= $fmn % $interval != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | if $fhr < 0 || $fhr > 23 or ($fmn % $interval) != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 143 | my ($lhr, $lmn) = $last =~ /\A (\d{2}) (\d{2}) \z/xms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 143 | ▶ | croak "Invalid input: '$last'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$lhr < 0 or $lhr > 23 or $lmn % $interval != 0
$lhr < 0 or $lhr > 23
MC/DC33%1/3
$lhr < 0 or $lhr > 23 or $lmn % $interval != 0
$lhr < 0
$lhr > 23
$lmn % $interval != 0
Truth table50%2/4
A or B or C
A= $lhr < 0B= $lhr > 23C= $lmn % $interval != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | if $lhr < 0 || $lhr > 23 or ($lmn % $interval) != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 140 | ▶ | croak "Ending interval can't be less than starting interval" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$lhr < $fhr or $lhr == $fhr and $lmn < $fmn
$lhr == $fhr and $lmn < $fmn
MC/DC0%0/3
$lhr < $fhr or $lhr == $fhr and $lmn < $fmn
$lhr < $fhr
$lhr == $fhr
$lmn < $fmn
Truth table50%2/4
A or B and C
A= $lhr < $fhrB= $lhr == $fhrC= $lmn < $fmn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | if ($lhr < $fhr) || ($lhr == $fhr && $lmn < $fmn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 140 | my @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 140 | my ($hr, $mn) = ($fhr, $fmn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 140 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 509 | push @result, sprintf "%02d%02d", $hr, $mn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 509 | ▶ | if ($mn < (60 - $interval)) { $mn += $interval } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 301 | elsif ($hr < 23) { $hr++; $mn = 0; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | else { $hr = $mn = 0; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 509 | ▶ | push @result, sprintf "%02d%02d", $hr, $mn and last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition85%6/7
$hr == $lhr && $mn == $lmn && (push(@result, sprintf('%02d%02d', $hr, $mn)) && (last))
$hr == $lhr and $mn == $lmn
push @result, sprintf("%02d%02d", $hr, $mn) and last
MC/DC0%0/3
$hr == $lhr && $mn == $lmn && (push(@result, sprintf('%02d%02d', $hr, $mn)) && (last))
$hr == $lhr
$mn == $lmn
push @result, sprintf("%02d%02d", $hr, $mn)
Truth table50%2/4
A and B && C
A= $hr == $lhrB= $mn == $lmnC= push @result, sprintf("%02d%02d", $hr, $mn)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | if ($hr == $lhr && $mn == $lmn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 140 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # Tests if two values are equal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 656 | ▶ | sub _equal_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equal_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 656 | my ($self, $first, $last) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 656 | return !!($first eq $last); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # Tests if two values are consequent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 224 | ▶ | sub _next_in_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_in_range: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 224 | my ($self, $first, $last) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 224 | my $interval = $self->interval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 224 | my ($fhr, $fmn) = $first =~ /\A (\d{2}) (\d{2}) \z/xms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 224 | my ($lhr, $lmn) = $last =~ /\A (\d{2}) (\d{2}) \z/xms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # Increment by interval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 224 | $fmn += $interval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # Check for overflown value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 224 | ▶ | if ($fmn == 60) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 134 | $fhr++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 134 | $fmn = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 224 | ▶ | return !!($fhr == $lhr && $fmn == $lmn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$fhr == $lhr && $fmn == $lmn
MC/DC100%2/2
$fhr == $lhr && $fmn == $lmn
$fhr == $lhr
$fmn == $lmn
Truth table100%3/3
A && B
A= $fhr == $lhrB= $fmn == $lmn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | ### INTERNAL INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Formats time from 4-digit internal representation to HH:MM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 930 | ▶ | sub _colonify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_colonify: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 930 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 930 | my $delim = $self->delimiter(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 930 | ▶ | croak "Can't colonify invalid value '$value'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value =~ /\A (\d{2}) (\d{2}) \z/msx or $value =~ /\A (\d{2}) (\d{2}) ($delim) (\d{2}) (\d{2}) \z/msx
MC/DC0%0/2
$value =~ /\A (\d{2}) (\d{2}) \z/msx or $value =~ /\A (\d{2}) (\d{2}) ($delim) (\d{2}) (\d{2}) \z/msx
$value =~ /\A (\d{2}) (\d{2}) \z/msx
$value =~ /\A (\d{2}) (\d{2}) ($delim) (\d{2}) (\d{2}) \z/msx
Truth table66%2/3
A or B
A= $value =~ /\A (\d{2}) (\d{2}) \z/msxB= $value =~ /\A (\d{2}) (\d{2}) ($delim) (\d{2}) (\d{2}) \z/msx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | unless $value =~ /\A (\d{2}) (\d{2}) \z/xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | || $value =~ /\A (\d{2}) (\d{2}) ($delim) (\d{2}) (\d{2}) \z/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 930 | ▶ | return $3 ne $delim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | ? sprintf "%02d:%02d", $1, $2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | : sprintf "%02d:%02d".$delim."%02d:%02d", $1, $2, $4, $5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||