Rx/CoreType/str.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 80.0% 16 / 20 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 85.0% 68 / 80 CC 14 SCAR 18.7
CC
14
Cov
89%
guts_from_arg
9.4
assert_valid
7.0
BEGIN
1.0
CRAP 6.5
« Rx/CoreType/num.pm ↑ Summary Rx/Failure.pm »
1 1 ▶use strict;
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::str;
4 # ABSTRACT: the Rx //str type
5 1 $Data::Rx::CoreType::str::VERSION = '0.200007';
6 1 ▶use parent 'Data::Rx::CoreType';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Data::Rx::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub guts_from_arg {
11 18 ▶ my ($class, $arg, $rx, $type) = @_;
Subroutine guts_from_arg: called CC=8 SCAR=22.4
Pod undocumented
12  
13 18 ▶ Carp::croak("unknown arguments to new")
Branch: 1 branch
BranchTrueFalseTotal
unless "Data::Rx::Util"->_x_subset_keys_y($arg, {"length", 1, "value", 1}) 0 18 18
14 unless Data::Rx::Util->_x_subset_keys_y($arg, { length => 1, value => 1});
15  
16 # XXX: We should be able to reject num values, too. :( -- rjbs, 2008-08-25
17 18 ▶ if (exists $arg->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg->{"value"}) 2 16 18
18 2 my $val = $arg->{value};
19 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or ref $val) 0 2 2
Condition33%1/3
not defined $val or ref $val
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $val or ref $val
not defined $val ref $val
Truth table33%1/3
not(A) or B
A= not defined $valB= ref $val
ABresult
1X1
011
000
20 (! defined $val)
21 or ref $val
22 ) {
23 0 ▶ Carp::croak(sprintf(
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
24 'invalid value (%s) for //str',
25 defined $val ? $val : 'undef',
26 ));
27 }
28 }
29  
30 18 my $guts = {};
31  
32 $guts->{length_check} = Data::Rx::Util->_make_range_check($arg->{length})
33 18 ▶ if $arg->{length};
Branch: 1 branch
BranchTrueFalseTotal
if $arg->{"length"} 1 17 18
34  
35 18 ▶ $guts->{value} = $arg->{value} if defined $arg->{value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg->{"value"} 2 16 18
36  
37 18 return $guts;
38 }
39  
40 sub assert_valid {
41 235 ▶ my ($self, $value) = @_;
Subroutine assert_valid: called CC=7 SCAR=19.5
Pod undocumented
42  
43 235 ▶ unless (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 6 229 235
44 6 $self->fail({
45 error => [ qw(type) ],
46 message => "found value is undef",
47 value => $value,
48 });
49 }
50  
51 # XXX: This is insufficiently precise. It's here to keep us from believing
52 # that JSON::XS::Boolean objects, which end up looking like 0 or 1, are
53 # integers. -- rjbs, 2008-07-24
54 229 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 112 117 229
55 112 $self->fail({
56 error => [ qw(type) ],
57 message => "found value is a reference",
58 value => $value,
59 });
60 }
61  
62 117 ▶ if ($self->{length_check} && ! $self->{length_check}->(length $value)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"length_check"} and not $self->{"length_check"}->(length $value)) 15 102 117
Condition100%3/3
$self->{"length_check"} and not $self->{"length_check"}->(length $value)
!ll&&!rl&&r
101115
MC/DC100%2/2
$self->{"length_check"} and not $self->{"length_check"}->(length $value)
$self->{"length_check"} not $self->{"length_check"}->(length $value)
Truth table100%3/3
A and not(B)
A= $self->{"length_check"}B= not $self->{"length_check"}->(length $value)
ABresult
0X0
100
111
63 15 $self->fail({
64 error => [ qw(length) ],
65 message => "length of value is outside allowed range",
66 value => $value,
67 });
68 }
69  
70 102 ▶ if (defined $self->{value} and $self->{value} ne $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"value"} and $self->{"value"} ne $value) 44 58 102
Condition100%3/3
defined $self->{"value"} and $self->{"value"} ne $value
!ll&&!rl&&r
56244
MC/DC100%2/2
defined $self->{"value"} and $self->{"value"} ne $value
defined $self->{"value"} $self->{"value"} ne $value
Truth table100%3/3
A and B
A= defined $self->{"value"}B= $self->{"value"} ne $value
ABresult
0X0
100
111
71 44 $self->fail({
72 error => [ qw(value) ],
73 message => "found value is not the required value",
74 value => $value,
75 });
76 }
77  
78 # XXX: Really, we need a way to know whether (say) the JSON was one of the
79 # following: { "foo": 1 } or { "foo": "1" }
80 # Only one of those is providing a string. -- rjbs, 2008-07-27
81 58 return 1;
82 }
83  
84 54 ▶sub subname { 'str' }
Subroutine subname: called CC=1 SCAR=0.0
Pod undocumented
85  
86 1 1;
87  
88 __END__
« Rx/CoreType/num.pm ↑ Summary Rx/Failure.pm »