| 1 | # Number::Range::Regex::SimpleRange | ||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||
| 3 | # Copyright 2012 Brian Szymanski. All rights reserved. This module is | ||||||||||||||||||||||||||||||||||||
| 4 | # free software; you can redistribute it and/or modify it under the same | ||||||||||||||||||||||||||||||||||||
| 5 | # terms as Perl itself. | ||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | package Number::Range::Regex::SimpleRange; | ||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | # a contiguous, finite range, can be expressed as an array of TrivialRange | ||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use vars qw ( @ISA @EXPORT @EXPORT_OK $VERSION ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | 14 | eval { require warnings; }; #it's ok if we can't load warnings | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 14 | require Exporter; | |||||||||||||||||||||||||||||||||||
| 16 | 14 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 17 | 14 | @ISA = qw( Exporter Number::Range::Regex::Range ); | |||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | 14 | $VERSION = '0.32'; | |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 14 | ▶ | use Number::Range::Regex::Util ':all'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 22 | 14 | ▶ | use Number::Range::Regex::Util::inf qw( neg_inf pos_inf inf_type _is_negative _pad ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | 1206 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=21 SCAR=30.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 25 | 1206 | my ($class, $min, $max, $passed_opts) = @_; | |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | 1206 | my $opts = option_mangler( $passed_opts ); | |||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | 1206 | ▶ | die 'internal error: undefined min and max from caller: '.join(":", caller) if !( defined $min && defined $max ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $min and defined $max
MC/DC0%0/2
defined $min and defined $max
defined $min
defined $max
Truth table33%1/3
A and B
A= defined $minB= defined $max
| |||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||
| 31 | 1206 | my $base = $opts->{base}; | |||||||||||||||||||||||||||||||||||
| 32 | 1206 | my $base_digits = $opts->{base_digits} = base_digits($base); | |||||||||||||||||||||||||||||||||||
| 33 | 1206 | my $base_max = $opts->{base_max} = substr($base_digits, -1); | |||||||||||||||||||||||||||||||||||
| 34 | 1206 | my $base_digits_regex = $opts->{base_digits_regex} = _calculate_digit_range( 0, $base_max, $base_digits ); | |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | 1206 | ▶ | die "min ($min) must be a base $opts->{base} integer or /^[+-]?inf\$/" if $min !~ /^[-+]?(?:inf|[$base_digits]+)$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 37 | 1206 | ▶ | die "max ($max) must be a base $opts->{base} integer or /^[+-]?inf\$/" if $max !~ /^[-+]?(?:inf|[$base_digits]+)$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||
| 39 | # convert '-inf' / '+inf' strings to neg_inf / pos_inf objects | ||||||||||||||||||||||||||||||||||||
| 40 | # and canonicalize min and max by removing leading zeroes, plus signs | ||||||||||||||||||||||||||||||||||||
| 41 | 1206 | foreach my $val ( \$min, \$max ) { | |||||||||||||||||||||||||||||||||||
| 42 | 2412 | ▶ | next if ref $$val; # don't do these checks on pos_inf/neg_inf objects | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 43 | 2113 | $$val =~ s/^\+//; | |||||||||||||||||||||||||||||||||||
| 44 | 2113 | $$val =~ s/^(-?)0+/$1/; #strip leading zeroes | |||||||||||||||||||||||||||||||||||
| 45 | 2113 | ▶ | $$val = 0 if $$val =~ /^-?$/; #don't strip "0" or "-0" -> "" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 46 | 2113 | ▶ | $$val = pos_inf if $$val =~ /^[+]?inf$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 47 | 2113 | ▶ | $$val = neg_inf if $$val =~ /^-inf$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||
| 50 | # any infinite numbers are compared using Util::inf, but others | ||||||||||||||||||||||||||||||||||||
| 51 | # must be compared as strings to account for bases >10 | ||||||||||||||||||||||||||||||||||||
| 52 | # TODO: this assumes we have a base in ascii-order! | ||||||||||||||||||||||||||||||||||||
| 53 | 1206 | my $out_of_order; | |||||||||||||||||||||||||||||||||||
| 54 | 1206 | ▶ | if(inf_type($min) || inf_type($max)) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
inf_type($min) or inf_type($max)
MC/DC100%2/2
inf_type($min) or inf_type($max)
inf_type($min)
inf_type($max)
Truth table100%3/3
A or B
A= inf_type($min)B= inf_type($max)
| |||||||||||||||||||||||||||||||||||||
| 55 | 387 | $out_of_order = $min > $max; | |||||||||||||||||||||||||||||||||||
| 56 | ▶ | } elsif( !_is_negative($min) && _is_negative($max) ) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not _is_negative($min) and _is_negative($max)
MC/DC0%0/2
not _is_negative($min) and _is_negative($max)
not _is_negative($min)
_is_negative($max)
Truth table66%2/3
not(A) and B
A= not _is_negative($min)B= _is_negative($max)
| |||||||||||||||||||||||||||||||||||||
| 57 | 0 | $out_of_order = 1; | |||||||||||||||||||||||||||||||||||
| 58 | ▶ | } elsif( _is_negative($min) && !_is_negative($max) ) { | |||||||||||||||||||||||||||||||||||
|
Condition100%3/3
_is_negative($min) and not _is_negative($max)
MC/DC100%2/2
_is_negative($min) and not _is_negative($max)
_is_negative($min)
not _is_negative($max)
Truth table100%3/3
A and not(B)
A= _is_negative($min)B= not _is_negative($max)
| |||||||||||||||||||||||||||||||||||||
| 59 | 24 | $out_of_order = 0; | |||||||||||||||||||||||||||||||||||
| 60 | } else { #min and max have same sign | ||||||||||||||||||||||||||||||||||||
| 61 | 795 | my $digdiff = length($max)-length($min); | |||||||||||||||||||||||||||||||||||
| 62 | 795 | ▶ | my $pmin = $digdiff > 0 ? _pad($min, $digdiff) : $min; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 63 | 795 | ▶ | my $pmax = $digdiff < 0 ? _pad($max, -$digdiff) : $max; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 64 | 795 | ▶ | $out_of_order = _is_negative($max) ? $pmin lt $pmax : $pmin gt $pmax; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | 1206 | ▶ | if( $out_of_order ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | die "min($min) > max($max) (autoswap option not specified)" if !$opts->{autoswap}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 69 | 2 | ($min, $max) = ($max, $min); | |||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||
| 72 | 1204 | return bless { min => $min, max => $max, opts => $opts, | |||||||||||||||||||||||||||||||||||
| 73 | base => $base, base_max => $base_max, | ||||||||||||||||||||||||||||||||||||
| 74 | base_digits => $base_digits, base_digits_regex => $base_digits_regex, | ||||||||||||||||||||||||||||||||||||
| 75 | }, $class; | ||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | 1086 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 79 | 1086 | my ($self, $passed_opts) = @_; | |||||||||||||||||||||||||||||||||||
| 80 | 1086 | ▶ | if( $self->{min} eq $self->{max} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 81 | 210 | return $self->{min}; | |||||||||||||||||||||||||||||||||||
| 82 | # the prefer_comma option is dangerous because if you read in 3,4 | ||||||||||||||||||||||||||||||||||||
| 83 | # you don't get 3..4, but instead 3..3,4..4 which requires collapsing | ||||||||||||||||||||||||||||||||||||
| 84 | #} elsif($self->{min}+$opts->{prefer_comma} >= $self->{max}) { | ||||||||||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||||||||||
| 86 | 876 | return "$self->{min}..$self->{max}"; | |||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | 1586 | ▶ | sub regex { | ||||||||||||||||||||||||||||||||||
|
Subroutine
regex: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 91 | 1586 | my ($self, $passed_opts) = @_; | |||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||
| 93 | 1586 | my $opts = option_mangler( $self->{opts}, $passed_opts ); | |||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||
| 95 | 1586 | ▶ | $self->{tranges} ||= [ $self->_calculate_tranges() ]; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"tranges"} ||= [$self->_calculate_tranges]
MC/DC100%1/1
$self->{"tranges"} ||= [$self->_calculate_tranges]
$self->{"tranges"}
Truth table100%2/2
A
A= $self->{"tranges"}
| |||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||
| 97 | 1586 | ▶ | my $separator = $opts->{readable} ? ' | ' : '|'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 98 | 1586 | my $regex_str = join $separator, map { $_->regex( $opts ) } @{$self->{tranges}}; | |||||||||||||||||||||||||||||||||||
| 99 | 1586 | ▶ | $regex_str = " $regex_str " if $opts->{readable}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | 1586 | ▶ | my $modifier_maybe = $opts->{readable} ? '(?x)' : ''; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 102 | 1586 | my ($begin_comment_maybe, $end_comment_maybe) = ('', ''); | |||||||||||||||||||||||||||||||||||
| 103 | 1586 | ▶ | if($opts->{comment}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 104 | 1154 | my ($min, $max) = ($self->{min}, $self->{max}); | |||||||||||||||||||||||||||||||||||
| 105 | 1154 | my $comment = "Number::Range::Regex::SimpleRange[$min..$max]"; | |||||||||||||||||||||||||||||||||||
| 106 | 1154 | ▶ | $begin_comment_maybe = $opts->{readable} ? " # begin $comment" : "(?# begin $comment )"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 107 | 1154 | ▶ | $end_comment_maybe = $opts->{readable} ? " # end $comment" : "(?# end $comment )"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||
| 109 | 1586 | ▶ | $regex_str = "(?:$regex_str)" if @{$self->{tranges}} != 1; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||
| 111 | 1586 | return qr/$begin_comment_maybe$modifier_maybe$regex_str$end_comment_maybe/; | |||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||
| 114 | 439 | ▶ | sub _calculate_tranges { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_calculate_tranges: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||
| 115 | 439 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 116 | 439 | my $min = $self->{min}; | |||||||||||||||||||||||||||||||||||
| 117 | 439 | my $max = $self->{max}; | |||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||
| 119 | 439 | ▶ | if( _is_negative( $min ) && _is_negative( $max ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
_is_negative($min) and _is_negative($max)
MC/DC100%2/2
_is_negative($min) and _is_negative($max)
_is_negative($min)
_is_negative($max)
Truth table100%3/3
A and B
A= _is_negative($min)B= _is_negative($max)
| |||||||||||||||||||||||||||||||||||||
| 120 | 9 | my $pos_sr = __PACKAGE__->new( -$max, -$min ); | |||||||||||||||||||||||||||||||||||
| 121 | 9 | my @tranges = $pos_sr->_calculate_tranges(); | |||||||||||||||||||||||||||||||||||
| 122 | 9 | @tranges = reverse map { Number::Range::Regex::TrivialRange->new( | |||||||||||||||||||||||||||||||||||
| 123 | 14 | -$_->{max}, -$_->{min} ) } @tranges; | |||||||||||||||||||||||||||||||||||
| 124 | 9 | return @tranges; | |||||||||||||||||||||||||||||||||||
| 125 | ▶ | } elsif( _is_negative( $min ) && !_is_negative( $max ) ) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
_is_negative($min) and not _is_negative($max)
MC/DC50%1/2
_is_negative($min) and not _is_negative($max)
_is_negative($min)
not _is_negative($max)
Truth table66%2/3
A and not(B)
A= _is_negative($min)B= not _is_negative($max)
| |||||||||||||||||||||||||||||||||||||
| 126 | # min..-1, 0..max | ||||||||||||||||||||||||||||||||||||
| 127 | 12 | my $pos_lo_sr = __PACKAGE__->new( 1, -$min ); | |||||||||||||||||||||||||||||||||||
| 128 | 12 | my @tranges = $pos_lo_sr->_calculate_tranges(); | |||||||||||||||||||||||||||||||||||
| 129 | 12 | @tranges = reverse map { Number::Range::Regex::TrivialRange->new( | |||||||||||||||||||||||||||||||||||
| 130 | 24 | -$_->{max}, -$_->{min}, ) } @tranges; | |||||||||||||||||||||||||||||||||||
| 131 | 12 | push @tranges, __PACKAGE__->new( 0, $max )->_calculate_tranges(); | |||||||||||||||||||||||||||||||||||
| 132 | 12 | return @tranges; | |||||||||||||||||||||||||||||||||||
| 133 | ▶ | } elsif( !_is_negative( $min ) && _is_negative( $max ) ) { | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not _is_negative($min) and _is_negative($max)
MC/DC0%0/2
not _is_negative($min) and _is_negative($max)
not _is_negative($min)
_is_negative($max)
Truth table33%1/3
not(A) and B
A= not _is_negative($min)B= _is_negative($max)
| |||||||||||||||||||||||||||||||||||||
| 134 | 0 | die "_calculate_tranges() - internal error - min($min)>=0 but max($max)<0?"; | |||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||
| 136 | # if we get here, $min >= 0 and $max >= 0 | ||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||
| 138 | 418 | ▶ | if ( $min eq $max ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 139 | 102 | return Number::Range::Regex::TrivialRange->new( $min, $min ); | |||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||
| 142 | 316 | ▶ | if($max == pos_inf) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 143 | # iterate from $self->{min} up to the next (power of 10) - 1 (e.g. 9999) | ||||||||||||||||||||||||||||||||||||
| 144 | # then spit out a regex for any integer with a longer length | ||||||||||||||||||||||||||||||||||||
| 145 | 24 | my $tmp = $self->{base_max} x length $self->{min}; | |||||||||||||||||||||||||||||||||||
| 146 | 24 | my $noninf = __PACKAGE__->new($self->{min}, $tmp ); | |||||||||||||||||||||||||||||||||||
| 147 | 24 | return ( $noninf->_calculate_tranges(), | |||||||||||||||||||||||||||||||||||
| 148 | Number::Range::Regex::TrivialRange->new( $tmp+1, pos_inf ) ); | ||||||||||||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||
| 151 | # $min-- unless $self->{opts}->{exclusive_min} || $self->{opts}->{exclusive}; | ||||||||||||||||||||||||||||||||||||
| 152 | # $max++ unless $self->{opts}->{exclusive_max} || $self->{opts}->{exclusive}; | ||||||||||||||||||||||||||||||||||||
| 153 | # warn "WARNING: exclusive ranges untested!" if($self->{opts}->{exclusive_min} || $self->{opts}->{exclusive_max} || $self->{opts}->{exclusive}); | ||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||
| 155 | 292 | my $digits_diff = length($max)-length($min); | |||||||||||||||||||||||||||||||||||
| 156 | 292 | my $padded_min = ('0' x $digits_diff).$min; | |||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||
| 158 | 292 | my $samedigits = 0; | |||||||||||||||||||||||||||||||||||
| 159 | 292 | for my $digit (0..length($max)-1) { | |||||||||||||||||||||||||||||||||||
| 160 | 429 | ▶ | last unless substr($padded_min, $digit, 1) eq substr($max, $digit, 1); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 161 | 137 | $samedigits++; | |||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||
| 164 | 292 | my ($rightmost, $leftmost) = (length $max, $samedigits+1); | |||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||
| 166 | 292 | my @tranges = (); | |||||||||||||||||||||||||||||||||||
| 167 | push @tranges, | ||||||||||||||||||||||||||||||||||||
| 168 | $self->_do_range_setting_loop($min, $padded_min, length($max) - length($min), $rightmost, | ||||||||||||||||||||||||||||||||||||
| 169 | [ reverse ($leftmost+1..$rightmost) ], | ||||||||||||||||||||||||||||||||||||
| 170 | 317 | ▶ | sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 171 | 317 | my ( $digit, $trailer_len, $header ) = @_; | |||||||||||||||||||||||||||||||||||
| 172 | 317 | ▶ | return ($trailer_len ? base_next($digit, $self->{base_digits}) : $digit, $self->{base_max}); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||
| 174 | 292 | ); | |||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||
| 176 | push @tranges, | ||||||||||||||||||||||||||||||||||||
| 177 | $self->_do_range_setting_loop($min, $padded_min, length($max) - length($min), $rightmost, | ||||||||||||||||||||||||||||||||||||
| 178 | [ $leftmost ], | ||||||||||||||||||||||||||||||||||||
| 179 | 292 | ▶ | sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 180 | 292 | my ( $digit, $trailer_len, $header ) = @_; | |||||||||||||||||||||||||||||||||||
| 181 | 292 | ▶ | my $digit_min = $trailer_len ? base_next($digit, $self->{base_digits}) : $digit; #inclusive in ones column only! | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 182 | 292 | my $digit_max = substr($max, length($header), 1); | |||||||||||||||||||||||||||||||||||
| 183 | 292 | ▶ | $digit_max = base_prev($digit_max, $self->{base_digits}) if $trailer_len; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 184 | 292 | return ($digit_min, $digit_max); | |||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||
| 186 | 292 | ); | |||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||
| 188 | push @tranges, | ||||||||||||||||||||||||||||||||||||
| 189 | $self->_do_range_setting_loop($max, $max, 0, $rightmost, | ||||||||||||||||||||||||||||||||||||
| 190 | [ ($leftmost+1)..$rightmost ], | ||||||||||||||||||||||||||||||||||||
| 191 | 317 | ▶ | sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 192 | 317 | my ( $digit, $trailer_len, $header ) = @_; | |||||||||||||||||||||||||||||||||||
| 193 | 317 | ▶ | return (0, $trailer_len ? base_prev($digit, $self->{base_digits}) : $digit); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||
| 195 | 292 | ); | |||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | 292 | return @tranges; | |||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||
| 201 | 876 | ▶ | sub _do_range_setting_loop { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_do_range_setting_loop: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||
| 202 | 876 | my ($self, $string_base, $padded_string_base, $string_offset, | |||||||||||||||||||||||||||||||||||
| 203 | $rightmost, $digit_pos_range, $digit_range_sub) = @_; | ||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||
| 205 | 876 | my @ranges = (); | |||||||||||||||||||||||||||||||||||
| 206 | 876 | foreach my $digit_pos (@$digit_pos_range) { | |||||||||||||||||||||||||||||||||||
| 207 | 926 | my $pos = $digit_pos - $string_offset - 1; | |||||||||||||||||||||||||||||||||||
| 208 | 926 | ▶ | my $static_header = $pos < 0 ? "" : substr($string_base, 0, $pos); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 209 | 926 | my $trailer_len = $rightmost - $digit_pos; | |||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||
| 211 | 926 | my $digit = substr($padded_string_base, $digit_pos-1, 1); | |||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||
| 213 | 926 | my ($digit_min, $digit_max) = $digit_range_sub->( $digit, $trailer_len, $static_header ); | |||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||
| 215 | 926 | my $digit_range = _calculate_digit_range( $digit_min, $digit_max, $self->{base_digits} ); | |||||||||||||||||||||||||||||||||||
| 216 | 926 | ▶ | next unless defined $digit_range; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||
| 218 | 656 | my $range_min = $static_header.$digit_min.(0 x $trailer_len); | |||||||||||||||||||||||||||||||||||
| 219 | 656 | my $range_max = $static_header.$digit_max.($self->{base_max} x $trailer_len); | |||||||||||||||||||||||||||||||||||
| 220 | 656 | push @ranges, Number::Range::Regex::TrivialRange->new( | |||||||||||||||||||||||||||||||||||
| 221 | $range_min, $range_max ); | ||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||
| 223 | 876 | return @ranges; | |||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||
| 226 | 27 | ▶ | sub intersection { | ||||||||||||||||||||||||||||||||||
|
Subroutine
intersection: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 227 | 27 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||
| 229 | 27 | ▶ | if( $other->isa('Number::Range::Regex::CompoundRange') ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 230 | 4 | return Number::Range::Regex::CompoundRange->new( $self )->intersection( $other ); | |||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||
| 232 | 23 | my ($lower, $upper) = _order_by_min( $self, $other ); | |||||||||||||||||||||||||||||||||||
| 233 | 23 | ▶ | if( $upper->{min} <= $lower->{max} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 234 | 14 | ▶ | return $upper if $upper->{max} <= $lower->{max}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 235 | 6 | return __PACKAGE__->new( $upper->{min}, $lower->{max} ); | |||||||||||||||||||||||||||||||||||
| 236 | } else { | ||||||||||||||||||||||||||||||||||||
| 237 | 9 | return empty_set(); | |||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||
| 241 | 336 | ▶ | sub union { | ||||||||||||||||||||||||||||||||||
|
Subroutine
union: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 242 | 336 | ▶ | my $opts = option_mangler( ref $_[-1] eq 'HASH' ? pop : undef ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 243 | 336 | my ($self, @other) = @_; | |||||||||||||||||||||||||||||||||||
| 244 | #warn "sr::u, wo: $opts->{warn_overlap}, $self, @other"; | ||||||||||||||||||||||||||||||||||||
| 245 | 336 | ▶ | return multi_union( $self, @other ) if @other > 1; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 246 | 336 | my $other = shift @other; | |||||||||||||||||||||||||||||||||||
| 247 | 336 | ▶ | if( $other->isa('Number::Range::Regex::CompoundRange') ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 248 | 12 | return Number::Range::Regex::CompoundRange->new( $self )->union( $other ); | |||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||
| 250 | 324 | my ($lower, $upper) = _order_by_min( $self, $other ); | |||||||||||||||||||||||||||||||||||
| 251 | 324 | ▶ | if( $upper->{min} < $lower->{max}+1 ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 252 | 65 | ▶ | if( $opts->{warn_overlap} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 253 | 1 | my $overlap = __PACKAGE__->new( $upper->{min}, $lower->{max} ); | |||||||||||||||||||||||||||||||||||
| 254 | 1 | ▶ | my $subname = $opts->{warn_overlap} eq '1' ? 'union' : $opts->{warn_overlap}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 255 | 1 | warn "$subname call got overlap: ".$overlap->to_string(); | |||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||
| 257 | # NOTE: this is more complicated than it probably should be: we preserve | ||||||||||||||||||||||||||||||||||||
| 258 | # the original object if we can, so if it's a TR, it stays a TR. | ||||||||||||||||||||||||||||||||||||
| 259 | # we don't actually seem to need that, although we have tests for it. | ||||||||||||||||||||||||||||||||||||
| 260 | 65 | ▶ | if( $lower->{max} >= $upper->{max} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 261 | 37 | return $lower; | |||||||||||||||||||||||||||||||||||
| 262 | } else { | ||||||||||||||||||||||||||||||||||||
| 263 | 28 | return __PACKAGE__->new( $lower->{min}, $upper->{max} ); | |||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||
| 265 | } elsif( $upper->{min} == $lower->{max}+1 ) { | ||||||||||||||||||||||||||||||||||||
| 266 | 89 | return __PACKAGE__->new( $lower->{min}, $upper->{max} ); | |||||||||||||||||||||||||||||||||||
| 267 | } else { #$upper->{min} > $lower->{max}+1 | ||||||||||||||||||||||||||||||||||||
| 268 | 170 | return Number::Range::Regex::CompoundRange->new( $lower, $upper ); | |||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||
| 272 | 20 | ▶ | sub subtract { | ||||||||||||||||||||||||||||||||||
|
Subroutine
subtract: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 273 | 20 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||
| 274 | 20 | ▶ | if( $other->isa('Number::Range::Regex::CompoundRange') ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 275 | 4 | return Number::Range::Regex::CompoundRange->new( $self )->subtract( $other); | |||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||
| 277 | 16 | ▶ | return $self unless $self->touches($other); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||
| 279 | 16 | ▶ | if( $self->{min} < $other->{min} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 280 | 10 | ▶ | if( $self->{max} <= $other->{max} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 281 | # e.g. (1..7)-(3..11) = (1..2) | ||||||||||||||||||||||||||||||||||||
| 282 | # e.g. (1..11)-(3..11) = (1..2) | ||||||||||||||||||||||||||||||||||||
| 283 | 2 | return __PACKAGE__->new( $self->{min}, $other->{min}-1 ); | |||||||||||||||||||||||||||||||||||
| 284 | } else { | ||||||||||||||||||||||||||||||||||||
| 285 | # e.g. (1..7)-(2..6) = (1, 7) | ||||||||||||||||||||||||||||||||||||
| 286 | 8 | my $r1 = __PACKAGE__->new( $self->{min}, $other->{min}-1 ); | |||||||||||||||||||||||||||||||||||
| 287 | 8 | my $r2 = __PACKAGE__->new( $other->{max}+1, $self->{max} ); | |||||||||||||||||||||||||||||||||||
| 288 | 8 | return $r1->union( $r2 ); | |||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||||||||||
| 291 | 6 | ▶ | if( $self->{max} <= $other->{max} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 292 | # e.g. (1..7)-(1..11) = () | ||||||||||||||||||||||||||||||||||||
| 293 | # e.g. (1..7)-(1..7) = () | ||||||||||||||||||||||||||||||||||||
| 294 | 4 | return empty_set(); | |||||||||||||||||||||||||||||||||||
| 295 | } else { | ||||||||||||||||||||||||||||||||||||
| 296 | # e.g. (1..7)-(1..4) = (5..7) | ||||||||||||||||||||||||||||||||||||
| 297 | 2 | return __PACKAGE__->new( $other->{max}+1, $self->{max} ); | |||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||
| 302 | 17 | ▶ | sub xor { | ||||||||||||||||||||||||||||||||||
|
Subroutine
xor: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 303 | 17 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||
| 304 | 17 | ▶ | if( $other->isa('Number::Range::Regex::CompoundRange') ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 305 | 2 | return Number::Range::Regex::CompoundRange->new( $self )->xor( $other ); | |||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||
| 307 | 15 | ▶ | return $self->union($other) unless $self->touches($other); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||
| 309 | 15 | ▶ | if( $self->{min} == $other->{min} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 310 | 3 | ▶ | if( $self->{max} < $other->{max} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 311 | # e.g. (1..7)xor(1..11) = (8..11) | ||||||||||||||||||||||||||||||||||||
| 312 | 1 | return __PACKAGE__->new( $self->{max}+1, $other->{max} ); | |||||||||||||||||||||||||||||||||||
| 313 | } elsif($self->{max} == $other->{max}) { | ||||||||||||||||||||||||||||||||||||
| 314 | # e.g. (1..11)xor(1..11) = () | ||||||||||||||||||||||||||||||||||||
| 315 | 1 | return empty_set( $self->{opts} ); | |||||||||||||||||||||||||||||||||||
| 316 | } else { | ||||||||||||||||||||||||||||||||||||
| 317 | # e.g. (1..7)xor(1..6) = (7) | ||||||||||||||||||||||||||||||||||||
| 318 | 1 | return __PACKAGE__->new( $other->{max}+1, $self->{max} ); | |||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||
| 320 | } else { | ||||||||||||||||||||||||||||||||||||
| 321 | 12 | my ($lower, $upper) = _order_by_min( $self, $other ); | |||||||||||||||||||||||||||||||||||
| 322 | 12 | ▶ | if($lower->{max} < $upper->{max}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 323 | # e.g. (1..7)xor(3..11) = (1..2, 8..11) | ||||||||||||||||||||||||||||||||||||
| 324 | 4 | my $r1 = __PACKAGE__->new( $lower->{min}, $upper->{min}-1 ); | |||||||||||||||||||||||||||||||||||
| 325 | 4 | my $r2 = __PACKAGE__->new( $lower->{max}+1, $upper->{max} ); | |||||||||||||||||||||||||||||||||||
| 326 | 4 | return $r1->union( $r2 ); | |||||||||||||||||||||||||||||||||||
| 327 | } elsif($lower->{max} == $upper->{max}) { | ||||||||||||||||||||||||||||||||||||
| 328 | # e.g. (1..11)xor(3..11) = (1..2) | ||||||||||||||||||||||||||||||||||||
| 329 | 1 | return __PACKAGE__->new( $lower->{min}, $upper->{min}-1 ); | |||||||||||||||||||||||||||||||||||
| 330 | } else { | ||||||||||||||||||||||||||||||||||||
| 331 | # e.g. (1..7)xor(3..6) = (1..2, 7) | ||||||||||||||||||||||||||||||||||||
| 332 | 7 | my $r1 = __PACKAGE__->new( $lower->{min}, $upper->{min}-1 ); | |||||||||||||||||||||||||||||||||||
| 333 | 7 | my $r2 = __PACKAGE__->new( $upper->{max}+1, $lower->{max} ); | |||||||||||||||||||||||||||||||||||
| 334 | 7 | return $r1->union( $r2 ); | |||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||
| 339 | 39 | ▶ | sub invert { | ||||||||||||||||||||||||||||||||||
|
Subroutine
invert: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 340 | 39 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 341 | 39 | my @r; | |||||||||||||||||||||||||||||||||||
| 342 | 39 | ▶ | if($self->{min} != neg_inf) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 343 | 36 | push @r, __PACKAGE__->new( neg_inf, $self->{min}-1 ); | |||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||
| 345 | 39 | ▶ | if($self->{max} != pos_inf) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 346 | 36 | push @r, __PACKAGE__->new( $self->{max}+1, pos_inf ); | |||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||
| 348 | 39 | return multi_union( @r ); | |||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||
| 351 | 70 | ▶ | sub overlaps { | ||||||||||||||||||||||||||||||||||
|
Subroutine
overlaps: called CC=6 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 352 | 70 | my ($self, @other) = @_; | |||||||||||||||||||||||||||||||||||
| 353 | 70 | foreach my $other (@other) { | |||||||||||||||||||||||||||||||||||
| 354 | 70 | ▶ | if(!$other->isa( 'Number::Range::Regex::SimpleRange') ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | return 1 if $other->overlaps($self); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 356 | } else { | ||||||||||||||||||||||||||||||||||||
| 357 | 70 | ▶ | die "other argument is not a simple range (try swapping your args)" unless $other->isa('Number::Range::Regex::SimpleRange'); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 358 | 70 | my ($lower, $upper) = _order_by_min( $self, $other ); | |||||||||||||||||||||||||||||||||||
| 359 | 70 | ▶ | return 1 if $upper->{min} <= $lower->{max}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||
| 362 | 9 | return; | |||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||
| 365 | 472 | ▶ | sub touches { | ||||||||||||||||||||||||||||||||||
|
Subroutine
touches: called CC=6 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 366 | 472 | my ($self, @other) = @_; | |||||||||||||||||||||||||||||||||||
| 367 | 472 | foreach my $other (@other) { | |||||||||||||||||||||||||||||||||||
| 368 | 472 | ▶ | if(!$other->isa( 'Number::Range::Regex::SimpleRange') ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | return 1 if $other->touches($self); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 370 | } else { | ||||||||||||||||||||||||||||||||||||
| 371 | 472 | ▶ | die "other argument is not a simple range (try swapping your args)" unless $other->isa('Number::Range::Regex::SimpleRange'); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 372 | 472 | my ($lower, $upper) = _order_by_min( $self, $other ); | |||||||||||||||||||||||||||||||||||
| 373 | 472 | ▶ | return 1 if $upper->{min} <= $lower->{max}+1; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||
| 376 | 305 | return; | |||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||
| 379 | 1975 | ▶ | sub contains { | ||||||||||||||||||||||||||||||||||
|
Subroutine
contains: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 380 | 1975 | my ($self, $n) = @_; | |||||||||||||||||||||||||||||||||||
| 381 | 1975 | ▶ | return ($n >= $self->{min}) && ($n <= $self->{max}); | ||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$n >= $self->{'min'} && $n <= $self->{'max'}
MC/DC100%2/2
$n >= $self->{'min'} && $n <= $self->{'max'}
$n >= $self->{'min'}
$n <= $self->{'max'}
Truth table100%3/3
A && B
A= $n >= $self->{'min'}B= $n <= $self->{'max'}
| |||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||
| 384 | 347 | ▶ | sub has_lower_bound { my ($self) = @_; return $self->{min} != neg_inf; } | ||||||||||||||||||||||||||||||||||
|
Subroutine
has_lower_bound: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 385 | 11432 | ▶ | sub has_upper_bound { my ($self) = @_; return $self->{max} != pos_inf; } | ||||||||||||||||||||||||||||||||||
|
Subroutine
has_upper_bound: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||
| 387 | 46 | ▶ | sub is_infinite { | ||||||||||||||||||||||||||||||||||
|
Subroutine
is_infinite: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 388 | 46 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 389 | 46 | ▶ | return !( $self->has_lower_bound && $self->has_upper_bound ); | ||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->has_lower_bound && $self->has_upper_bound
MC/DC100%2/2
$self->has_lower_bound && $self->has_upper_bound
$self->has_lower_bound
$self->has_upper_bound
Truth table100%3/3
A && B
A= $self->has_lower_boundB= $self->has_upper_bound
| |||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||
| 392 | 42 | ▶ | sub is_empty { return; } | ||||||||||||||||||||||||||||||||||
|
Subroutine
is_empty: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||
| 394 | 14 | 1; | |||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||