| 1 | package Range::Object::Date; | ||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use Date::Simple; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Date::Range; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use base qw(Range::Object); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||
| 21 | # Overload definitions | ||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use overload q{""} => 'stringify_collapsed', | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | fallback => 1; | |||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | ### PUBLIC PACKAGE SUBROUTINE ### | ||||||||||||||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||||||||||||||
| 28 | # Returns regex used to check date validity, both for full dates | ||||||||||||||||||||||||||||||||||||||||
| 29 | # and month only dates. This implementation is reasonably simple | ||||||||||||||||||||||||||||||||||||||||
| 30 | # since Date::Simple constructor will check dates more strictly | ||||||||||||||||||||||||||||||||||||||||
| 31 | # in any case. | ||||||||||||||||||||||||||||||||||||||||
| 32 | # | ||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub YYYYMMDD { qr/\A \d{4} - \d{2} -\d{2} \z/xms } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
YYYYMMDD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 34 | 201 | ▶ | sub YYYYMM { qr/\A \d{4} - \d{2} \z/xms } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
YYYYMM: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||
| 36 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||||||||||||||
| 38 | # Returns the number of separate items in internal storage. | ||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | sub size { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | my $size = 0; | |||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||
| 46 | $size += (ref eq 'Date::Range' ? $_->length() : 1) | ||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | for @{ $self->{range} }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | return $size; | |||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||
| 52 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||||||||||
| 54 | # Returns array or string representation of internal storage. | ||||||||||||||||||||||||||||||||||||||||
| 55 | # | ||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | ▶ | sub range { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
range: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | my ($self, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | return $self->stringify($separator) unless wantarray; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||
| 62 | 110 | return sort { $a cmp $b } | |||||||||||||||||||||||||||||||||||||||
| 63 | map { | ||||||||||||||||||||||||||||||||||||||||
| 64 | 16 | ▶ | ref eq 'Date::Range' ? map { "$_" } $_->dates() | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 65 | : "$_" | ||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||
| 70 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||||||||||||||
| 72 | # Returns sorted and collapsed representation of internal storage. | ||||||||||||||||||||||||||||||||||||||||
| 73 | # In list context, resulting list consists of separate values and/or | ||||||||||||||||||||||||||||||||||||||||
| 74 | # range hashrefs with three elements: start, end and count. | ||||||||||||||||||||||||||||||||||||||||
| 75 | # In scalar context, result is a string of separate values and/or | ||||||||||||||||||||||||||||||||||||||||
| 76 | # ranges separated by value returned by delimiter() method. | ||||||||||||||||||||||||||||||||||||||||
| 77 | # Optional list separator can be used instead of default one in | ||||||||||||||||||||||||||||||||||||||||
| 78 | # scalar context. | ||||||||||||||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||
| 81 | 12 | ▶ | sub collapsed { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
collapsed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 82 | 12 | my ($self, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||
| 84 | 12 | ▶ | return $self->stringify_collapsed($separator) unless wantarray; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||
| 86 | return | ||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | ▶ | map { ref($_) eq 'Date::Simple' ? "$_" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 88 | : { | ||||||||||||||||||||||||||||||||||||||||
| 89 | start => ''.$_->start(), | ||||||||||||||||||||||||||||||||||||||||
| 90 | end => ''.$_->end(), | ||||||||||||||||||||||||||||||||||||||||
| 91 | count => $_->length(), | ||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||
| 97 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||||||||||||||
| 99 | # Tests if items of @range are matching items in our internal storage. | ||||||||||||||||||||||||||||||||||||||||
| 100 | # Returns true/false in scalar context, list of mismatching items in list | ||||||||||||||||||||||||||||||||||||||||
| 101 | # context. | ||||||||||||||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||
| 104 | 81 | ▶ | sub in { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
in: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 105 | 81 | my ($self, @range) = @_; | |||||||||||||||||||||||||||||||||||||||
| 106 | 81 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||
| 108 | # Normalize to array of Date::Simple objects | ||||||||||||||||||||||||||||||||||||||||
| 109 | 81 | my @objects = map { Date::Simple->new($_) } | |||||||||||||||||||||||||||||||||||||||
| 110 | $self->_validate_and_expand(@range); | ||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||
| 112 | # In this class we're operating on Date::Simple | ||||||||||||||||||||||||||||||||||||||||
| 113 | # objects as opposed to scalar values | ||||||||||||||||||||||||||||||||||||||||
| 114 | 81 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | my @result = grep { !$self->_search_range($_) } @objects; | |||||||||||||||||||||||||||||||||||||||
| 116 | 6 | return @result; | |||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||||||||||||||
| 119 | 75 | ▶ | my $result = defined first { $self->_search_range($_) } @objects; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 120 | 75 | return $result; | |||||||||||||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return; # Just in case | |||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||
| 126 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 127 | # | ||||||||||||||||||||||||||||||||||||||||
| 128 | # Returns string representation of collapsed current range. | ||||||||||||||||||||||||||||||||||||||||
| 129 | # | ||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||
| 131 | 12 | ▶ | sub stringify_collapsed { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify_collapsed: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 132 | 12 | my ($self, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||
| 134 | 12 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||
| 135 | 12 | my $delimiter = $self->delimiter(); | |||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||
| 137 | # Stringify into array | ||||||||||||||||||||||||||||||||||||||||
| 138 | my @collapsed_range | ||||||||||||||||||||||||||||||||||||||||
| 139 | 32 | ▶ | = map { ref($_) eq 'Date::Simple' ? "$_" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 140 | : $_->start() . | ||||||||||||||||||||||||||||||||||||||||
| 141 | $delimiter . | ||||||||||||||||||||||||||||||||||||||||
| 142 | $_->end() | ||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||
| 144 | 12 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||
| 146 | 12 | return join $separator, @collapsed_range; | |||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||
| 149 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 150 | # | ||||||||||||||||||||||||||||||||||||||||
| 151 | # Returns regex that is used to validate date items. Since Date::Simple | ||||||||||||||||||||||||||||||||||||||||
| 152 | # doesn't support date formats other than basic ISO 8601 (YYYY-MM-DD) we | ||||||||||||||||||||||||||||||||||||||||
| 153 | # don't have to support anything else. The only exception is YYYY-MM | ||||||||||||||||||||||||||||||||||||||||
| 154 | # format for month-only dates. | ||||||||||||||||||||||||||||||||||||||||
| 155 | # | ||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||
| 157 | 91 | ▶ | sub pattern { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
pattern: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 158 | 91 | return qr{ | |||||||||||||||||||||||||||||||||||||||
| 159 | (?<! [-0-9] ) # Can't have a digit in front | ||||||||||||||||||||||||||||||||||||||||
| 160 | (?: # Group but don't capture | ||||||||||||||||||||||||||||||||||||||||
| 161 | (?:\d{4}-\d{2}) # ... YYYY-MM | ||||||||||||||||||||||||||||||||||||||||
| 162 | | # or | ||||||||||||||||||||||||||||||||||||||||
| 163 | (?:\d{4}-\d{2}-\d{2}) # ... YYYY-MM-DD | ||||||||||||||||||||||||||||||||||||||||
| 164 | ) # ... end group | ||||||||||||||||||||||||||||||||||||||||
| 165 | (?= # Can't have this group after | ||||||||||||||||||||||||||||||||||||||||
| 166 | (?: # Group but don't capture | ||||||||||||||||||||||||||||||||||||||||
| 167 | \s # ... a whitespace | ||||||||||||||||||||||||||||||||||||||||
| 168 | | # or | ||||||||||||||||||||||||||||||||||||||||
| 169 | / # ... a forward slash [/] | ||||||||||||||||||||||||||||||||||||||||
| 170 | | # or | ||||||||||||||||||||||||||||||||||||||||
| 171 | \z # ... end of string | ||||||||||||||||||||||||||||||||||||||||
| 172 | ) # ... end group | ||||||||||||||||||||||||||||||||||||||||
| 173 | ) # ... end lookahead | ||||||||||||||||||||||||||||||||||||||||
| 174 | }xms; | ||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||
| 177 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 178 | # | ||||||||||||||||||||||||||||||||||||||||
| 179 | # Returns regex that is used to separate items in a range list. | ||||||||||||||||||||||||||||||||||||||||
| 180 | # Default is comma (,) or semicolon (;). | ||||||||||||||||||||||||||||||||||||||||
| 181 | # | ||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||
| 183 | 91 | ▶ | sub separator { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
separator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 184 | 91 | return qr/ | |||||||||||||||||||||||||||||||||||||||
| 185 | [;,] # Comma or semicolon | ||||||||||||||||||||||||||||||||||||||||
| 186 | \s* # Greedy whitespace | ||||||||||||||||||||||||||||||||||||||||
| 187 | /xms | ||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||
| 190 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 191 | # | ||||||||||||||||||||||||||||||||||||||||
| 192 | # For Range::Object::Date delimiter is forward slash (/) as per ISO 8601. | ||||||||||||||||||||||||||||||||||||||||
| 193 | # | ||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||
| 195 | 12 | ▶ | sub delimiter { '/' } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
delimiter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||
| 197 | ############## PRIVATE METHODS BELOW ############## | ||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||
| 199 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 200 | # | ||||||||||||||||||||||||||||||||||||||||
| 201 | # Returns default list separator for use with stingify() and | ||||||||||||||||||||||||||||||||||||||||
| 202 | # stringify_collapsed() | ||||||||||||||||||||||||||||||||||||||||
| 203 | # | ||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||
| 205 | 18 | ▶ | sub _list_separator { q{,} } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list_separator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||
| 207 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 208 | # | ||||||||||||||||||||||||||||||||||||||||
| 209 | # Uses Date::Simple and Date::Range to validate and unpack individual | ||||||||||||||||||||||||||||||||||||||||
| 210 | # date values and date ranges; returns full list of date strings. | ||||||||||||||||||||||||||||||||||||||||
| 211 | # | ||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||
| 213 | 91 | ▶ | sub _validate_and_expand { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_and_expand: called CC=21 SCAR=34.6
| |||||||||||||||||||||||||||||||||||||||||
| 214 | 91 | my ($self, @input_range) = @_; | |||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||
| 216 | # Retrieve patterns | ||||||||||||||||||||||||||||||||||||||||
| 217 | 91 | my $pattern = $self->pattern(); | |||||||||||||||||||||||||||||||||||||||
| 218 | 91 | my $separator = $self->separator(); | |||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||
| 220 | # We use hash to avoid duplicates | ||||||||||||||||||||||||||||||||||||||||
| 221 | 91 | my %temp; | |||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||
| 223 | # Go over each item | ||||||||||||||||||||||||||||||||||||||||
| 224 | ITEM: | ||||||||||||||||||||||||||||||||||||||||
| 225 | 91 | ▶ | while ( @input_range ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 226 | 203 | my $item = shift @input_range; | |||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||
| 228 | # Expand on $separator | ||||||||||||||||||||||||||||||||||||||||
| 229 | 203 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | unshift @input_range, split $separator, $item; | |||||||||||||||||||||||||||||||||||||||
| 231 | 4 | next ITEM; | |||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||
| 234 | 199 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||
| 235 | if $item && $item !~ $pattern; | ||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||
| 237 | # We use Date::Range to validate and expand dates | ||||||||||||||||||||||||||||||||||||||||
| 238 | 197 | ▶ | if ($item =~ m{ ($pattern) / ($pattern) }xms) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | my ($first, $last) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||
| 241 | # Date::Simple doesn't support non-full dates so | ||||||||||||||||||||||||||||||||||||||||
| 242 | # we have to trick it a bit | ||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | if ($first =~ YYYYMM || $last =~ YYYYMM) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$first =~ YYYYMM() or $last =~ YYYYMM()
MC/DC0%0/2
$first =~ YYYYMM() or $last =~ YYYYMM()
$first =~ YYYYMM()
$last =~ YYYYMM()
Truth table33%1/3
A or B
A= $first =~ YYYYMM()B= $last =~ YYYYMM()
| |||||||||||||||||||||||||||||||||||||||||
| 244 | # First check if *both* $first and $last are month-only | ||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | croak "Can't mix YYYY-MM and YYYY-MM-DD input formats" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$first =~ YYYYMM() and $last =~ YYYYMM()
MC/DC0%0/2
$first =~ YYYYMM() and $last =~ YYYYMM()
$first =~ YYYYMM()
$last =~ YYYYMM()
Truth table0%0/3
A and B
A= $first =~ YYYYMM()B= $last =~ YYYYMM()
| |||||||||||||||||||||||||||||||||||||||||
| 246 | unless $first =~ YYYYMM && $last =~ YYYYMM; | ||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||
| 248 | # Now add dates | ||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $first .= '-01'; | |||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $last .= '-01'; | |||||||||||||||||||||||||||||||||||||||
| 251 | }; | ||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||
| 253 | # Create Date::Simple objects | ||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | my ($date1, $date2) = eval { | |||||||||||||||||||||||||||||||||||||||
| 255 | 4 | return Date::Simple->new($first), Date::Simple->new($last) | |||||||||||||||||||||||||||||||||||||||
| 256 | }; | ||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||
| 258 | # Check that everything is OK | ||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | croak "Invalid input date in range '$item': $@" if $@; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | ▶ | croak "Invalid input date '$first'" if !defined $date1; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | ▶ | croak "Invalid input date '$last'" if !defined $date2; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | ▶ | croak "Last date in range cannot be earlier than first date" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 263 | if $date1 > $date2; | ||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||
| 265 | # Create Date::Range object | ||||||||||||||||||||||||||||||||||||||||
| 266 | 4 | my $range = eval { Date::Range->new($date1, $date2) }; | |||||||||||||||||||||||||||||||||||||||
| 267 | 4 | ▶ | $@ || !defined $range and | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not defined $range
MC/DC0%0/2
$@ or not defined $range
$@
not defined $range
Truth table33%1/3
A or not(B)
A= $@B= not defined $range
| |||||||||||||||||||||||||||||||||||||||||
| 268 | croak "Invalid input range '$item': $@"; | ||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||
| 270 | # Expand Date::Range object and store resulting dates | ||||||||||||||||||||||||||||||||||||||||
| 271 | 4 | my @dates = $range->dates(); | |||||||||||||||||||||||||||||||||||||||
| 272 | 4 | @temp{ @dates } = (1) x @dates; | |||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||
| 275 | # See if that's an individual date | ||||||||||||||||||||||||||||||||||||||||
| 276 | elsif ($item =~ /\A ( $pattern ) \z/xms) { | ||||||||||||||||||||||||||||||||||||||||
| 277 | 193 | my $date = $1; | |||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||
| 279 | # The same trick as with months range | ||||||||||||||||||||||||||||||||||||||||
| 280 | 193 | ▶ | $date .= '-01' if $date =~ YYYYMM; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||
| 282 | # Create Date::Simple object | ||||||||||||||||||||||||||||||||||||||||
| 283 | 193 | my $d = eval { Date::Simple->new($date) }; | |||||||||||||||||||||||||||||||||||||||
| 284 | 193 | ▶ | $@ || !defined $d and | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$@ or not defined $d
MC/DC50%1/2
$@ or not defined $d
$@
not defined $d
Truth table66%2/3
A or not(B)
A= $@B= not defined $d
| |||||||||||||||||||||||||||||||||||||||||
| 285 | croak "Invalid input date '$item': $@"; | ||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||
| 287 | # ... and store it | ||||||||||||||||||||||||||||||||||||||||
| 288 | 191 | $temp{ "$d" } = 1; | |||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||
| 291 | # Didn't find anything useful | ||||||||||||||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | croak "Invalid input '$item': no ISO 8601 dates found"; | |||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||
| 297 | # Order matters for later _collapse_range() | ||||||||||||||||||||||||||||||||||||||||
| 298 | 87 | my @dates = sort { $a cmp $b } keys %temp; | |||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||
| 300 | 87 | return @dates; | |||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||
| 303 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 304 | # | ||||||||||||||||||||||||||||||||||||||||
| 305 | # Tests if a sigle value is in current range. | ||||||||||||||||||||||||||||||||||||||||
| 306 | # | ||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||
| 308 | 149 | ▶ | sub _search_range { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_search_range: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 309 | 149 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||
| 311 | 419 | ▶ | return first { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 312 | 419 | ▶ | ref eq 'Date::Range' ? $_->includes($value) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 313 | : $_ == $value | ||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||
| 315 | 149 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||
| 318 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 319 | # | ||||||||||||||||||||||||||||||||||||||||
| 320 | # Returns sorted list of all single items within current range. | ||||||||||||||||||||||||||||||||||||||||
| 321 | # Default sort is string-based. | ||||||||||||||||||||||||||||||||||||||||
| 322 | # | ||||||||||||||||||||||||||||||||||||||||
| 323 | # Works in list context only, croaks if called otherwise. | ||||||||||||||||||||||||||||||||||||||||
| 324 | # | ||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||
| 326 | 6 | ▶ | sub _sort_range { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sort_range: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||
| 327 | 6 | my ($self, @range) = @_; | |||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||
| 329 | 6 | ▶ | croak "_sort_range can only be used in list context" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 330 | unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||
| 332 | 110 | return sort { $a cmp $b } | |||||||||||||||||||||||||||||||||||||||
| 333 | 16 | ▶ | map { ref eq 'Date::Range' ? $_->dates : "$_" } | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@range || @{$self->{'range'};}
MC/DC0%0/2
@range || @{$self->{'range'};}
@range
@{$self->{'range'};}
Truth table33%1/3
A || B
A= @rangeB= @{$self->{'range'};}
| |||||||||||||||||||||||||||||||||||||||||
| 334 | 6 | @range || @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||
| 337 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 338 | # | ||||||||||||||||||||||||||||||||||||||||
| 339 | # Returns full list of items in current range. | ||||||||||||||||||||||||||||||||||||||||
| 340 | # | ||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||
| 342 | 6 | ▶ | sub _full_range { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_full_range: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||
| 343 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||
| 345 | 6 | ▶ | croak "_full_range can only be used in list context" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 346 | unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||
| 348 | 7 | ▶ | return map { ref($_) eq 'Date::Range' ? $_->dates() : "$_" } | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 349 | 6 | @{ $self->{range} }; | |||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||
| 352 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 353 | # | ||||||||||||||||||||||||||||||||||||||||
| 354 | # Returns collapsed list of current range items. Individual dates are | ||||||||||||||||||||||||||||||||||||||||
| 355 | # returned as Date::Simple objects while ranges are collapsed to | ||||||||||||||||||||||||||||||||||||||||
| 356 | # Date::Range objects. | ||||||||||||||||||||||||||||||||||||||||
| 357 | # | ||||||||||||||||||||||||||||||||||||||||
| 358 | # Works in list context only, croaks if called otherwise. | ||||||||||||||||||||||||||||||||||||||||
| 359 | # | ||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||
| 361 | 6 | ▶ | sub _collapse_range { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_collapse_range: called CC=10 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||
| 362 | 6 | my ($self, @range) = @_; | |||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||
| 364 | 6 | ▶ | croak "_collapse_range can only be used in list context" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 365 | unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||
| 367 | 6 | my ($first, $last, @result); | |||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||
| 369 | ITEM: | ||||||||||||||||||||||||||||||||||||||||
| 370 | 6 | for my $item ( sort @range ) { | |||||||||||||||||||||||||||||||||||||||
| 371 | # Create Date::Simple object | ||||||||||||||||||||||||||||||||||||||||
| 372 | 76 | $item = eval { Date::Simple->new($item) }; | |||||||||||||||||||||||||||||||||||||||
| 373 | 76 | ▶ | croak "Internal error: can't create Date::Simple: $@" if $@; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||
| 375 | # If $first is defined, it means range has started | ||||||||||||||||||||||||||||||||||||||||
| 376 | 76 | ▶ | if ( !defined $first ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 377 | 6 | $first = $last = $item; | |||||||||||||||||||||||||||||||||||||||
| 378 | 6 | next ITEM; | |||||||||||||||||||||||||||||||||||||||
| 379 | }; | ||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||
| 381 | # If $last immediately preceeds $item in range, | ||||||||||||||||||||||||||||||||||||||||
| 382 | # $item becomes next $last | ||||||||||||||||||||||||||||||||||||||||
| 383 | 70 | ▶ | if ( $self->_next_in_range($last, $item) ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 384 | 60 | $last = $item; | |||||||||||||||||||||||||||||||||||||||
| 385 | 60 | next ITEM; | |||||||||||||||||||||||||||||||||||||||
| 386 | }; | ||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||
| 388 | # If $item doesn't follow $last and $last is defined, | ||||||||||||||||||||||||||||||||||||||||
| 389 | # it means current contiguous range is complete | ||||||||||||||||||||||||||||||||||||||||
| 390 | 10 | ▶ | if ( !$self->_equal_value($first, $last) ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 391 | # Try to create range object which *should* go ok but still | ||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | eval { | |||||||||||||||||||||||||||||||||||||||
| 393 | 2 | push @result, Date::Range->new($first, $last); | |||||||||||||||||||||||||||||||||||||||
| 394 | 2 | $first = $last = $item; | |||||||||||||||||||||||||||||||||||||||
| 395 | 2 | next ITEM; | |||||||||||||||||||||||||||||||||||||||
| 396 | }; | ||||||||||||||||||||||||||||||||||||||||
| 397 | # ... and rethrow if anything untowards happen | ||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | croak "Internal error: can't create Date::Range: $@" if $@; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 399 | }; | ||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||
| 401 | # If $last wasn't defined, range was never contiguous | ||||||||||||||||||||||||||||||||||||||||
| 402 | 8 | push @result, $first; | |||||||||||||||||||||||||||||||||||||||
| 403 | 8 | $first = $last = $item; | |||||||||||||||||||||||||||||||||||||||
| 404 | 8 | next ITEM; | |||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||
| 407 | # We're here when last item has been processed | ||||||||||||||||||||||||||||||||||||||||
| 408 | 6 | ▶ | if ( $first eq $last ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | push @result, $first; | |||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||
| 411 | else { | ||||||||||||||||||||||||||||||||||||||||
| 412 | 6 | eval { | |||||||||||||||||||||||||||||||||||||||
| 413 | 6 | push @result, Date::Range->new($first, $last); | |||||||||||||||||||||||||||||||||||||||
| 414 | }; | ||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | ▶ | croak "Internal error: can't create Date::Range: $@" if $@; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 416 | }; | ||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | return @result; | |||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||
| 421 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 422 | # | ||||||||||||||||||||||||||||||||||||||||
| 423 | # Tests if two items are equal. Since we're storing both Date::Simple | ||||||||||||||||||||||||||||||||||||||||
| 424 | # and Date::Range items, this method has to account for details. | ||||||||||||||||||||||||||||||||||||||||
| 425 | # | ||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||
| 427 | 10 | ▶ | sub _equal_value { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equal_value: called CC=9 SCAR=39.7
| |||||||||||||||||||||||||||||||||||||||||
| 428 | 10 | my ($self, $first, $last) = @_; | |||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||
| 430 | # Compare $last with $first | ||||||||||||||||||||||||||||||||||||||||
| 431 | 10 | ▶ | if ( ref $first eq 'Date::Simple' && ref $last eq 'Date::Simple' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%1/3
ref $first eq "Date::Simple" and ref $last eq "Date::Simple"
MC/DC0%0/2
ref $first eq "Date::Simple" and ref $last eq "Date::Simple"
ref $first eq "Date::Simple"
ref $last eq "Date::Simple"
Truth table33%1/3
A and B
A= ref $first eq "Date::Simple"B= ref $last eq "Date::Simple"
| |||||||||||||||||||||||||||||||||||||||||
| 432 | 10 | return !!( $first == $last ); | |||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||
| 435 | # Compare last value in range with $last | ||||||||||||||||||||||||||||||||||||||||
| 436 | ▶ | elsif ( ref $first eq 'Date::Range' && ref $last eq 'Date::Simple' ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $first eq "Date::Range" and ref $last eq "Date::Simple"
MC/DC0%0/2
ref $first eq "Date::Range" and ref $last eq "Date::Simple"
ref $first eq "Date::Range"
ref $last eq "Date::Simple"
Truth table0%0/3
A and B
A= ref $first eq "Date::Range"B= ref $last eq "Date::Simple"
| |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | return !!( $first->end == $last ); | |||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||
| 440 | # Compare $last with first value in range | ||||||||||||||||||||||||||||||||||||||||
| 441 | ▶ | elsif ( ref $first eq 'Date::Simple' && ref $last eq 'Date::Range' ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $first eq "Date::Simple" and ref $last eq "Date::Range"
MC/DC0%0/2
ref $first eq "Date::Simple" and ref $last eq "Date::Range"
ref $first eq "Date::Simple"
ref $last eq "Date::Range"
Truth table0%0/3
A and B
A= ref $first eq "Date::Simple"B= ref $last eq "Date::Range"
| |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return !!( $first == $last->start ); | |||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||
| 445 | # This can't happen (theoretically) but still check | ||||||||||||||||||||||||||||||||||||||||
| 446 | ▶ | elsif ( ref $first eq 'Date::Range' && ref $last eq 'Date::Range' ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $first eq "Date::Range" and ref $last eq "Date::Range"
MC/DC0%0/2
ref $first eq "Date::Range" and ref $last eq "Date::Range"
ref $first eq "Date::Range"
ref $last eq "Date::Range"
Truth table0%0/3
A and B
A= ref $first eq "Date::Range"B= ref $last eq "Date::Range"
| |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | return !!( $first->equals($last) ); | |||||||||||||||||||||||||||||||||||||||
| 448 | }; | ||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | return; # Just fail if something goes awry | |||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||
| 453 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||||||||||||||
| 454 | # | ||||||||||||||||||||||||||||||||||||||||
| 455 | # Tests if two values are consequent. Same as with _equal_value(), this | ||||||||||||||||||||||||||||||||||||||||
| 456 | # method has to check item types first. | ||||||||||||||||||||||||||||||||||||||||
| 457 | # | ||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||
| 459 | 70 | ▶ | sub _next_in_range { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_in_range: called CC=9 SCAR=40.2
| |||||||||||||||||||||||||||||||||||||||||
| 460 | 70 | my ($self, $first, $last) = @_; | |||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||
| 462 | # Comparing apples to apples | ||||||||||||||||||||||||||||||||||||||||
| 463 | 70 | ▶ | if ( ref $first eq 'Date::Simple' && ref $last eq 'Date::Simple' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $first eq "Date::Simple" and ref $last eq "Date::Simple"
MC/DC0%0/2
ref $first eq "Date::Simple" and ref $last eq "Date::Simple"
ref $first eq "Date::Simple"
ref $last eq "Date::Simple"
Truth table33%1/3
A and B
A= ref $first eq "Date::Simple"B= ref $last eq "Date::Simple"
| |||||||||||||||||||||||||||||||||||||||||
| 464 | 70 | return !!( $first + 1 == $last ); | |||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||
| 467 | # Apples to oranges | ||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if ( ref $first eq 'Date::Simple' && ref $last eq 'Date::Range' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $first eq "Date::Simple" and ref $last eq "Date::Range"
MC/DC0%0/2
ref $first eq "Date::Simple" and ref $last eq "Date::Range"
ref $first eq "Date::Simple"
ref $last eq "Date::Range"
Truth table0%0/3
A and B
A= ref $first eq "Date::Simple"B= ref $last eq "Date::Range"
| |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | return !!( $first + 1 == $last->begin ); | |||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||
| 472 | # Vice versa | ||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if ( ref $first eq 'Date::Range' && ref $last eq 'Date::Simple' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $first eq "Date::Range" and ref $last eq "Date::Simple"
MC/DC0%0/2
ref $first eq "Date::Range" and ref $last eq "Date::Simple"
ref $first eq "Date::Range"
ref $last eq "Date::Simple"
Truth table0%0/3
A and B
A= ref $first eq "Date::Range"B= ref $last eq "Date::Simple"
| |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | return !!( $first->end + 1 == $last ); | |||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||
| 477 | # Can't happen but still | ||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if ( ref $first eq 'Date::Range' && ref $last eq 'Date::Range' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $first eq "Date::Range" and ref $last eq "Date::Range"
MC/DC0%0/2
ref $first eq "Date::Range" and ref $last eq "Date::Range"
ref $first eq "Date::Range"
ref $last eq "Date::Range"
Truth table0%0/3
A and B
A= ref $first eq "Date::Range"B= ref $last eq "Date::Range"
| |||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | return $first->abuts($last); | |||||||||||||||||||||||||||||||||||||||
| 480 | }; | ||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | return; # Quell the critics | |||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||
| 487 | __END__ | ||||||||||||||||||||||||||||||||||||||||