| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 18 | 2 | my $val = $arg->{value}; | |||||||||||||||||||||||||||
| 19 | 2 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $val or ref $val
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
| |||||||||||||||||||||||||||||
| 20 | (! defined $val) | ||||||||||||||||||||||||||||
| 21 | or ref $val | ||||||||||||||||||||||||||||
| 22 | ) { | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | Carp::croak(sprintf( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 18 | ▶ | $guts->{value} = $arg->{value} if defined $arg->{value}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->{"length_check"} and not $self->{"length_check"}->(length $value)
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)
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $self->{"value"} and $self->{"value"} ne $value
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||