Rx/CoreType/num.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 20 / 20 Conditioncond 78.5% 11 / 14 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 89.8% 80 / 89 CC 16 SCAR 18.5
CC
16
Cov
96%
guts_from_arg
9.1
assert_valid
8.0
BEGIN
1.0
CRAP 6.4
« Rx/CoreType/rec.pm ↑ Summary Rx/Failure.pm »
1 1 ▶use v5.12.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Data::Rx::CoreType::num 0.200008;
4 # ABSTRACT: the Rx //num type
5  
6 1 ▶use parent 'Data::Rx::CoreType';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 34 ▶sub guts_from_arg {
Subroutine guts_from_arg: called CC=9 SCAR=22.1
Pod undocumented
9 34 my ($class, $arg, $rx, $type) = @_;
10  
11 34 ▶ Carp::croak("unknown arguments to new")
Branch: 1 branch
BranchTrueFalseTotal
unless "Data::Rx::Util"->_x_subset_keys_y($arg, {"range", 1, "value", 1}) 2 32 34
12 unless Data::Rx::Util->_x_subset_keys_y($arg, { range => 1, value => 1});
13  
14 32 my $guts = {};
15  
16 $guts->{range_check} = Data::Rx::Util->_make_range_check($arg->{range})
17 32 ▶ if $arg->{range};
Branch: 1 branch
BranchTrueFalseTotal
if $arg->{"range"} 4 28 32
18  
19 32 ▶ if (exists $arg->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg->{"value"}) 4 28 32
20 4 my $val = $arg->{value};
21 4 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or ref $val or not $class->_value_is_of_type($val)) 1 3 4
Condition66%4/6
not defined $val or ref $val or not $class->_value_is_of_type($val)
l!l&&r!l&&!r
103
not defined $val or ref $val
l!l&&r!l&&!r
103
MC/DC33%1/3
not defined $val or ref $val or not $class->_value_is_of_type($val)
not defined $val ref $val not $class->_value_is_of_type($val)
Truth table50%2/4
not(A) or B or not(C)
A= not defined $valB= ref $valC= not $class->_value_is_of_type($val)
ABCresult
1XX1
01X1
0011
0000
22 (! defined $val)
23 or ref $val
24 or ! $class->_value_is_of_type($val)
25 ) {
26 1 ▶ Carp::croak(sprintf(
Condition50%1/2
$val // "undef"
l!l
01
MC/DC0%0/1
$val // "undef"
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
27 'invalid value (%s) for //%s',
28 $val // 'undef',
29 $class->subname,
30 ));
31 }
32 }
33  
34 31 ▶ $guts->{value} = $arg->{value} if defined $arg->{value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg->{"value"} 3 28 31
35  
36 31 return $guts;
37 }
38  
39 114 ▶sub __type_fail {
Subroutine __type_fail: called CC=1 SCAR=0.0
40 114 my ($self, $value) = @_;
41 114 $self->fail({
42 error => [ qw(type) ],
43 message => "value is not a number",
44 value => $value,
45 });
46 }
47  
48 1 my $_NUM_RE;
49 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 $_NUM_RE = qr/
51 \A
52 [-+]?
53 (?:0|[1-9]\d*)
54 (?:\.\d+)?
55 (?:e
56 (?:0|[1-9]\d*)
57 )?
58 \z
59 /ix;
60 }
61  
62 289 ▶sub _value_is_of_type {
Subroutine _value_is_of_type: called CC=1 SCAR=0.0
63 289 my ($self, $value) = @_;
64  
65 289 return $value =~ $_NUM_RE;
66 }
67  
68 499 ▶sub assert_valid {
Subroutine assert_valid: called CC=8 SCAR=20.8
Pod undocumented
69 499 my ($self, $value) = @_;
70  
71 499 ▶ $self->__type_fail($value) unless length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 14 485 499
72  
73 # XXX: This is insufficiently precise. It's here to keep us from believing
74 # that JSON::XS::Boolean objects, which end up looking like 0 or 1, are
75 # integers. -- rjbs, 2008-07-24
76 485 ▶ $self->__type_fail($value) if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 199 286 485
77  
78 286 ▶ $self->__type_fail($value) unless $self->_value_is_of_type($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_value_is_of_type($value) 89 197 286
79  
80 197 ▶ if ($self->{range_check} && ! $self->{range_check}->($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"range_check"} and not $self->{"range_check"}->($value)) 24 173 197
Condition100%3/3
$self->{"range_check"} and not $self->{"range_check"}->($value)
!ll&&!rl&&r
1541924
MC/DC100%2/2
$self->{"range_check"} and not $self->{"range_check"}->($value)
$self->{"range_check"} not $self->{"range_check"}->($value)
Truth table100%3/3
A and not(B)
A= $self->{"range_check"}B= not $self->{"range_check"}->($value)
ABresult
0X0
100
111
81 24 $self->fail({
82 error => [ qw(range) ],
83 message => "value is outside allowed range",
84 value => $value,
85 });
86 }
87  
88 173 ▶ if (defined($self->{value}) && $value != $self->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"value"} and $value != $self->{"value"}) 20 153 173
Condition100%3/3
defined $self->{"value"} and $value != $self->{"value"}
!ll&&!rl&&r
145820
MC/DC100%2/2
defined $self->{"value"} and $value != $self->{"value"}
defined $self->{"value"} $value != $self->{"value"}
Truth table100%3/3
A and B
A= defined $self->{"value"}B= $value != $self->{"value"}
ABresult
0X0
100
111
89 20 $self->fail({
90 error => [ qw(value) ],
91 message => "found value is not the required value",
92 value => $value,
93 });
94 }
95  
96 153 return 1;
97 }
98  
99 71 ▶sub subname { 'num' }
Subroutine subname: called CC=1 SCAR=0.0
Pod undocumented
100  
101 1 1;
102  
103 __END__
« Rx/CoreType/rec.pm ↑ Summary Rx/Failure.pm »