line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Compare::Number; |
2
|
169
|
|
|
169
|
|
1207
|
use strict; |
|
169
|
|
|
|
|
387
|
|
|
169
|
|
|
|
|
5228
|
|
3
|
169
|
|
|
169
|
|
902
|
use warnings; |
|
169
|
|
|
|
|
360
|
|
|
169
|
|
|
|
|
4612
|
|
4
|
|
|
|
|
|
|
|
5
|
169
|
|
|
169
|
|
890
|
use Carp qw/confess/; |
|
169
|
|
|
|
|
343
|
|
|
169
|
|
|
|
|
7525
|
|
6
|
|
|
|
|
|
|
|
7
|
169
|
|
|
169
|
|
979
|
use base 'Test2::Compare::Base'; |
|
169
|
|
|
|
|
361
|
|
|
169
|
|
|
|
|
18864
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.000156'; |
10
|
|
|
|
|
|
|
|
11
|
169
|
|
|
169
|
|
1269
|
use Test2::Util::HashBase qw/input mode/; |
|
169
|
|
|
|
|
368
|
|
|
169
|
|
|
|
|
1175
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Overloads '!' for us. |
14
|
169
|
|
|
169
|
|
27949
|
use Test2::Compare::Negatable; |
|
169
|
|
|
|
|
460
|
|
|
169
|
|
|
|
|
1038
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub init { |
17
|
13
|
|
|
13
|
0
|
533
|
my $self = shift; |
18
|
13
|
|
|
|
|
111
|
my $input = $self->{+INPUT}; |
19
|
|
|
|
|
|
|
|
20
|
13
|
100
|
|
|
|
337
|
confess "input must be defined for 'Number' check" |
21
|
|
|
|
|
|
|
unless defined $input; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Check for '' |
24
|
12
|
100
|
100
|
|
|
386
|
confess "input must be a number for 'Number' check" |
25
|
|
|
|
|
|
|
unless length($input) && $input =~ m/\S/; |
26
|
|
|
|
|
|
|
|
27
|
10
|
100
|
|
|
|
30
|
defined $self->{+MODE} or $self->{+MODE} = '=='; |
28
|
|
|
|
|
|
|
|
29
|
10
|
|
|
|
|
36
|
$self->SUPER::init(@_); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub name { |
33
|
18
|
|
|
18
|
1
|
321
|
my $self = shift; |
34
|
18
|
|
|
|
|
42
|
my $in = $self->{+INPUT}; |
35
|
18
|
|
|
|
|
57
|
return $in; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my %NEGATED = ( |
39
|
|
|
|
|
|
|
'==' => '!=', |
40
|
|
|
|
|
|
|
'!=' => '==', |
41
|
|
|
|
|
|
|
'<' => '>=', |
42
|
|
|
|
|
|
|
'<=' => '>', |
43
|
|
|
|
|
|
|
'>=' => '<', |
44
|
|
|
|
|
|
|
'>' => '<=', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub operator { |
48
|
22
|
|
|
22
|
1
|
239
|
my $self = shift; |
49
|
22
|
100
|
|
|
|
70
|
return '' unless @_; |
50
|
20
|
|
|
|
|
47
|
my ($got) = @_; |
51
|
|
|
|
|
|
|
|
52
|
20
|
100
|
|
|
|
54
|
return '' unless defined($got); |
53
|
18
|
50
|
33
|
|
|
116
|
return '' unless length($got) && $got =~ m/\S/; |
54
|
|
|
|
|
|
|
|
55
|
18
|
100
|
|
|
|
95
|
return $NEGATED{ $self->{+MODE} } if $self->{+NEGATE}; |
56
|
8
|
|
|
|
|
31
|
return $self->{+MODE}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub verify { |
60
|
43
|
|
|
43
|
1
|
297
|
my $self = shift; |
61
|
43
|
|
|
|
|
128
|
my %params = @_; |
62
|
43
|
|
|
|
|
111
|
my ($got, $exists) = @params{qw/got exists/}; |
63
|
|
|
|
|
|
|
|
64
|
43
|
100
|
|
|
|
116
|
return 0 unless $exists; |
65
|
41
|
100
|
|
|
|
96
|
return 0 unless defined $got; |
66
|
39
|
100
|
|
|
|
96
|
return 0 if ref $got; |
67
|
37
|
100
|
100
|
|
|
273
|
return 0 unless length($got) && $got =~ m/\S/; |
68
|
|
|
|
|
|
|
|
69
|
35
|
|
|
|
|
81
|
my $want = $self->{+INPUT}; |
70
|
35
|
|
|
|
|
77
|
my $mode = $self->{+MODE}; |
71
|
35
|
|
|
|
|
54
|
my $negate = $self->{+NEGATE}; |
72
|
|
|
|
|
|
|
|
73
|
35
|
|
|
|
|
61
|
my @warnings; |
74
|
|
|
|
|
|
|
my $out; |
75
|
|
|
|
|
|
|
{ |
76
|
35
|
|
|
5
|
|
48
|
local $SIG{__WARN__} = sub { push @warnings => @_ }; |
|
35
|
|
|
|
|
223
|
|
|
5
|
|
|
|
|
27
|
|
77
|
35
|
50
|
|
|
|
242
|
$out = $mode eq '==' ? ($got == $want) : |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
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
|
100
|
|
|
|
207
|
$out ^= 1 if $negate; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
35
|
|
|
|
|
99
|
for my $warn (@warnings) { |
88
|
5
|
50
|
|
|
|
31
|
if ($warn =~ m/numeric/) { |
89
|
5
|
|
|
|
|
12
|
$out = 0; |
90
|
5
|
|
|
|
|
11
|
next; # This warning won't help anyone. |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
0
|
warn $warn; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
35
|
|
|
|
|
173
|
return $out; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |