| 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::CommonType 0.200008; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: base class for core Rx types | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Data::Rx::Failure; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Data::Rx::FailureSet; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # requires: new_checker, type, type_uri, rx, assert_valid | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub new_checker { Carp::croak "$_[0] did not implement new_checker" } | ||||||||||||||||||||||||||
|
Subroutine
new_checker: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub type_uri { Carp::croak "$_[0] did not implement type_uri" } | ||||||||||||||||||||||||||
|
Subroutine
type_uri: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub type { Carp::croak "$_[0] did not implement type" } | ||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub rx { Carp::croak "$_[0] did not implement rx" } | ||||||||||||||||||||||||||
|
Subroutine
rx: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub assert_valid { Carp::croak "$_[0] did not implement assert_valid" } | ||||||||||||||||||||||||||
|
Subroutine
assert_valid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub check { | ||||||||||||||||||||||||||
|
Subroutine
check: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 21 | 0 | local $@; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | return 1 if eval { $self->assert_valid($value); }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | my $error = $@; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # If you wanted the failure, you should've used assert_valid. | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return 0 if eval { $error->isa('Data::Rx::FailureSet') }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | die $error; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1507 | ▶ | sub new_fail { | ||||||||||||||||||||||||||
|
Subroutine
new_fail: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 1507 | my ($self, $struct) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1507 | ▶ | $struct->{type} ||= $self->type; | ||||||||||||||||||||||||||
|
Condition33%1/3
$struct->{"type"} ||= $self->type
MC/DC0%0/2
$struct->{"type"} ||= $self->type
$struct->{"type"}
$self->type
Truth table33%1/3
A ||= B
A= $struct->{"type"}B= $self->type
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1507 | Data::Rx::FailureSet->new({ | |||||||||||||||||||||||||||
| 38 | rx => $self->rx, | ||||||||||||||||||||||||||||
| 39 | failures => [ | ||||||||||||||||||||||||||||
| 40 | Data::Rx::Failure->new({ | ||||||||||||||||||||||||||||
| 41 | rx => $self->rx, | ||||||||||||||||||||||||||||
| 42 | struct => $struct, | ||||||||||||||||||||||||||||
| 43 | }) | ||||||||||||||||||||||||||||
| 44 | ] | ||||||||||||||||||||||||||||
| 45 | }); | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1460 | ▶ | sub fail { | ||||||||||||||||||||||||||
|
Subroutine
fail: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 1460 | my ($self, $struct) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1460 | die $self->new_fail($struct); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 193 | ▶ | sub perform_subchecks { | ||||||||||||||||||||||||||
|
Subroutine
perform_subchecks: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 193 | my ($self, $subchecks) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 193 | my @fails; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 193 | foreach my $subcheck (@$subchecks) { | |||||||||||||||||||||||||||
| 60 | 421 | ▶ | if (Scalar::Util::blessed($subcheck)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 47 | push @fails, $subcheck; | |||||||||||||||||||||||||||
| 62 | 47 | next; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 374 | my ($value, $checker, $context) = @$subcheck; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 374 | ▶ | next if eval { $checker->assert_valid($value) }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 148 | my $failure = $@; | |||||||||||||||||||||||||||
| 70 | Carp::confess($failure) | ||||||||||||||||||||||||||||
| 71 | 148 | ▶ | unless eval { $failure->isa('Data::Rx::FailureSet') || | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$failure->isa('Data::Rx::FailureSet') || $failure->isa('Data::Rx::Failure')
MC/DC0%0/2
$failure->isa('Data::Rx::FailureSet') || $failure->isa('Data::Rx::Failure')
$failure->isa('Data::Rx::FailureSet')
$failure->isa('Data::Rx::Failure')
Truth table33%1/3
A || B
A= $failure->isa('Data::Rx::FailureSet')B= $failure->isa('Data::Rx::Failure')
| |||||||||||||||||||||||||||||
| 72 | $failure->isa('Data::Rx::Failure') }; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 148 | $failure->contextualize({ | |||||||||||||||||||||||||||
| 75 | type => $self->type, | ||||||||||||||||||||||||||||
| 76 | %$context, | ||||||||||||||||||||||||||||
| 77 | }); | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 148 | push @fails, $failure; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 193 | ▶ | if (@fails) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 125 | die Data::Rx::FailureSet->new( { rx => $self->rx, failures => \@fails } ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 68 | return 1; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | 1; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||