Type/Tiny/NumEqu.pm

filter: Statementstmt 91.8% 45 / 49 Branchbran 66.6% 16 / 24 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 12 / 15 Podpod 100% 6 / 6 totaltotal 80.8% 80 / 99 CC 14 SCAR 14.0
CC
14
Cov
82%
new
8.5
__ANON__
6.0
inline_check
3.0
CRAP 4.1
« Type/Tiny/NumEq.pm ↑ Summary Type/Tiny/Equ.pm »
1 package Type::Tiny::NumEqu;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = "0.03";
6  
7 2 ▶use parent qw( Type::Tiny );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
Subroutine _croak: called CC=1 SCAR=0.0
10  
11 5 ▶sub new {
Subroutine new: called CC=8 SCAR=21.4
Pod documented
12 5 my $class = shift;
13  
14 0 ▶ my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 5 5
15  
16 _croak "NumEqu type constraints cannot have a parent constraint passed to the constructor"
17 5 ▶ if exists $opts{parent};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"parent"} 0 5 5
18  
19 _croak "NumEqu type constraints cannot have a constraint coderef passed to the constructor"
20 5 ▶ if exists $opts{constraint};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"constraint"} 0 5 5
21  
22 _croak "NumEqu type constraints cannot have a inlining coderef passed to the constructor"
23 5 ▶ if exists $opts{inlined};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"inlined"} 0 5 5
24  
25 5 ▶ _croak "Need to supply value" unless exists $opts{value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"value"} 0 5 5
26  
27 5 ▶ if (defined $opts{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"value"}) 3 2 5
28 2 ▶ use warnings FATAL => 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 eval {
30 3 $opts{value} = $opts{value} + 0; # numify
31 };
32 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 2 3
33 1 _croak sprintf("`%s` is not number. NumEqu value must be number.", $opts{value});
34 }
35 }
36  
37 4 return $class->SUPER::new( %opts );
38 }
39  
40 16 ▶sub value { $_[0]{value} }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
41  
42 4 ▶sub _build_display_name {
Subroutine _build_display_name: called CC=2 SCAR=6.9
43 4 my $self = shift;
44  
45 4 ▶ defined $self->value
Branch: 1 branch
BranchTrueFalseTotal
defined $self->value ? : 2 2 4
46 ? sprintf( "NumEqu[%s]", $self->value )
47 : "NumEqu[Undef]";
48 }
49  
50 0 ▶sub has_parent {
Subroutine has_parent: not called CC=1 SCAR=6.9
Pod documented
51 0 !!0;
52 }
53  
54 4 ▶sub constraint { $_[0]{constraint} ||= $_[0]->_build_constraint }
Subroutine constraint: called CC=2 SCAR=9.2
Pod documented
Condition33%1/3
$_[0]{"constraint"} ||= $_[0]->_build_constraint
l!l&&r!l&&!r
040
MC/DC0%0/2
$_[0]{"constraint"} ||= $_[0]->_build_constraint
$_[0]{"constraint"} $_[0]->_build_constraint
Truth table33%1/3
A ||= B
A= $_[0]{"constraint"}B= $_[0]->_build_constraint
ABresult
1X1
011
000
55  
56 4 ▶sub _build_constraint {
Subroutine _build_constraint: called CC=2 SCAR=8.1
57 4 my $self = shift;
58  
59 4 ▶ if (defined $self->value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->value) { } 2 2 4
60 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
61 0 ▶ defined $_ && $_ == $self->value;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ == $self->value 0 0 0
62 2 };
63 }
64 else {
65 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 !defined $_;
67 2 };
68 }
69 }
70  
71 4 ▶sub can_be_inlined {
Subroutine can_be_inlined: called CC=1 SCAR=0.0
Pod documented
72 4 !!1;
73 }
74  
75 4 ▶sub inline_check {
Subroutine inline_check: called CC=3 SCAR=11.0
Pod documented
76 4 my $self = shift;
77  
78 4 my $value = $self->value;
79  
80 4 my $code;
81 4 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 2 2 4
82 2 $code = "(defined($_[0]) && $_[0] == $value)";
83 }
84 else {
85 2 $code = "!defined($_[0])";
86 }
87  
88 4 ▶ return "do { $Type::Tiny::SafePackage $code }"
Branch: 1 branch
BranchTrueFalseTotal
if $Type::Tiny::AvoidCallbacks 0 4 4
89 if $Type::Tiny::AvoidCallbacks; ## no critic (Variables::ProhibitPackageVars)
90 4 return $code;
91 }
92  
93 2 1;
94 __END__
« Type/Tiny/NumEq.pm ↑ Summary Type/Tiny/Equ.pm »