| 1 | package Test2::Compare::Number; | ||||||||||||||||||||||||||||||
| 2 | 176 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 176 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | 176 | ▶ | use Carp qw/confess/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 176 | ▶ | use base 'Test2::Compare::Base'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | 176 | our $VERSION = '1.302226'; | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | 176 | ▶ | use Test2::Util::HashBase qw/input mode/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | # Overloads '!' for us. | ||||||||||||||||||||||||||||||
| 14 | 176 | ▶ | use Test2::Compare::Negatable; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | sub init { | ||||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 17 | 13 | my $self = shift; | |||||||||||||||||||||||||||||
| 18 | 13 | my $input = $self->{+INPUT}; | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | confess "input must be defined for 'Number' check" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 21 | unless defined $input; | ||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | # Check for '' | ||||||||||||||||||||||||||||||
| 24 | 12 | ▶ | confess "input must be a number for 'Number' check" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $input and $input =~ /\S/
MC/DC100%2/2
length $input and $input =~ /\S/
length $input
$input =~ /\S/
Truth table100%3/3
A and B
A= length $inputB= $input =~ /\S/
| |||||||||||||||||||||||||||||||
| 25 | unless length($input) && $input =~ m/\S/; | ||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | 10 | ▶ | defined $self->{+MODE} or $self->{+MODE} = '=='; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | 10 | $self->SUPER::init(@_); | |||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | 18 | ▶ | sub name { | ||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 33 | 18 | my $self = shift; | |||||||||||||||||||||||||||||
| 34 | 18 | my $in = $self->{+INPUT}; | |||||||||||||||||||||||||||||
| 35 | 18 | return $in; | |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 176 | my %NEGATED = ( | |||||||||||||||||||||||||||||
| 39 | '==' => '!=', | ||||||||||||||||||||||||||||||
| 40 | '!=' => '==', | ||||||||||||||||||||||||||||||
| 41 | '<' => '>=', | ||||||||||||||||||||||||||||||
| 42 | '<=' => '>', | ||||||||||||||||||||||||||||||
| 43 | '>=' => '<', | ||||||||||||||||||||||||||||||
| 44 | '>' => '<=', | ||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | 22 | ▶ | sub operator { | ||||||||||||||||||||||||||||
|
Subroutine
operator: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 48 | 22 | my $self = shift; | |||||||||||||||||||||||||||||
| 49 | 22 | ▶ | return '' unless @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 50 | 20 | my ($got) = @_; | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 20 | ▶ | return '' unless defined($got); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 53 | 18 | ▶ | return '' unless length($got) && $got =~ m/\S/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $got and $got =~ /\S/
MC/DC0%0/2
length $got and $got =~ /\S/
length $got
$got =~ /\S/
Truth table33%1/3
A and B
A= length $gotB= $got =~ /\S/
| |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | 18 | ▶ | return $NEGATED{ $self->{+MODE} } if $self->{+NEGATE}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 56 | 8 | return $self->{+MODE}; | |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | 43 | ▶ | sub verify { | ||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=15 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 60 | 43 | my $self = shift; | |||||||||||||||||||||||||||||
| 61 | 43 | my %params = @_; | |||||||||||||||||||||||||||||
| 62 | 43 | my ($got, $exists) = @params{qw/got exists/}; | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | 43 | ▶ | return 0 unless $exists; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 65 | 41 | ▶ | return 0 unless defined $got; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 66 | 39 | ▶ | return 0 if ref $got; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 67 | 37 | ▶ | return 0 unless length($got) && $got =~ m/\S/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $got and $got =~ /\S/
MC/DC100%2/2
length $got and $got =~ /\S/
length $got
$got =~ /\S/
Truth table100%3/3
A and B
A= length $gotB= $got =~ /\S/
| |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | 35 | my $want = $self->{+INPUT}; | |||||||||||||||||||||||||||||
| 70 | 35 | my $mode = $self->{+MODE}; | |||||||||||||||||||||||||||||
| 71 | 35 | my $negate = $self->{+NEGATE}; | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 35 | my @warnings; | |||||||||||||||||||||||||||||
| 74 | my $out; | ||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||
| 76 | 35 | ▶ | local $SIG{__WARN__} = sub { push @warnings => @_ }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 77 | 35 | ▶ | $out = $mode eq '==' ? ($got == $want) : | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 78 | $mode eq '!=' ? ($got != $want) : | ||||||||||||||||||||||||||||||
| 79 | $mode eq '<' ? ($got < $want) : | ||||||||||||||||||||||||||||||
| 80 | $mode eq '<=' ? ($got <= $want) : | ||||||||||||||||||||||||||||||
| 81 | $mode eq '>=' ? ($got >= $want) : | ||||||||||||||||||||||||||||||
| 82 | $mode eq '>' ? ($got > $want) : | ||||||||||||||||||||||||||||||
| 83 | die "Unrecognised MODE"; | ||||||||||||||||||||||||||||||
| 84 | 35 | ▶ | $out ^= 1 if $negate; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | 35 | for my $warn (@warnings) { | |||||||||||||||||||||||||||||
| 88 | 5 | ▶ | if ($warn =~ m/numeric/) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 89 | 5 | $out = 0; | |||||||||||||||||||||||||||||
| 90 | 5 | next; # This warning won't help anyone. | |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||
| 92 | 0 | warn $warn; | |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | 35 | return $out; | |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | 176 | 1; | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||||