Rx/CommonType.pm

filter: Statementstmt 76.3% 42 / 55 Branchbran 57.1% 8 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 9 / 15 Podpod 0.0% 0 / 9 totaltotal 61.2% 60 / 98 CC 10 SCAR 14.9
CC
10
Cov
71%
check
12.0
perform_subchecks
7.0
new_fail
2.1
CRAP 4.4
« Rx/CoreType/arr.pm ↑ Summary Rx.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::CommonType;
4 # ABSTRACT: base class for core Rx types
5 1 $Data::Rx::CommonType::VERSION = '0.200007';
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 sub check {
20 0 ▶ my ($self, $value) = @_;
Subroutine check: not called CC=3 SCAR=24.8
Pod undocumented
21 0 local $@;
22  
23 0 ▶ return 1 if eval { $self->assert_valid($value); };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $self->assert_valid($value) } } 0 0 0
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
BranchTrueFalseTotal
if eval { do { $error->isa("Data::Rx::FailureSet") } } 0 0 0
28  
29 0 die $error;
30 }
31  
32 sub new_fail {
33 1507 ▶ my ($self, $struct) = @_;
Subroutine new_fail: called CC=2 SCAR=7.6
Pod undocumented
34  
35 1507 ▶ $struct->{type} ||= $self->type;
Condition33%1/3
$struct->{"type"} ||= $self->type
l!l&&r!l&&!r
015070
MC/DC0%0/2
$struct->{"type"} ||= $self->type
$struct->{"type"} $self->type
Truth table33%1/3
A ||= B
A= $struct->{"type"}B= $self->type
ABresult
1X1
011
000
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 sub fail {
49 1460 ▶ my ($self, $struct) = @_;
Subroutine fail: called CC=1 SCAR=0.0
Pod undocumented
50  
51 1460 die $self->new_fail($struct);
52 }
53  
54 sub perform_subchecks {
55 193 ▶ my ($self, $subchecks) = @_;
Subroutine perform_subchecks: called CC=7 SCAR=19.5
Pod undocumented
56  
57 193 my @fails;
58  
59 193 foreach my $subcheck (@$subchecks) {
60 421 ▶ if (Scalar::Util::blessed($subcheck)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($subcheck)) 47 374 421
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
BranchTrueFalseTotal
if eval { do { $checker->assert_valid($value) } } 226 148 374
68  
69 148 my $failure = $@;
70 Carp::confess($failure)
71 148 ▶ unless eval { $failure->isa('Data::Rx::FailureSet') ||
Branch: 2 branches
BranchTrueFalseTotal
unless eval { do { $failure->isa("Data::Rx::FailureSet") or $failure->isa("Data::Rx::Failure") } } 0 148 148
$failure->isa("Data::Rx::FailureSet") or $failure->isa("Data::Rx::Failure") 0 148 148
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
BranchTrueFalseTotal
if (@fails) 125 68 193
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__
« Rx/CoreType/arr.pm ↑ Summary Rx.pm »