Type/Tiny/NumEq.pm

filter: Statementstmt 93.1% 41 / 44 Branchbran 55.5% 10 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 12 / 14 Podpod 100% 6 / 6 totaltotal 80.4% 70 / 87 CC 11 SCAR 14.3
CC
11
Cov
80%
new
8.5
__ANON__
6.0
constraint
2.5
CRAP 4.2
↑ Summary Type/Tiny/NumEqu.pm »
1 package Type::Tiny::NumEq;
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 2 ▶sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
Subroutine _croak: called CC=1 SCAR=0.0
10  
11 4 ▶sub new {
Subroutine new: called CC=8 SCAR=21.4
Pod documented
12 4 my $class = shift;
13  
14 0 ▶ my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 4 4
15  
16 _croak "NumEq type constraints cannot have a parent constraint passed to the constructor"
17 4 ▶ if exists $opts{parent};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"parent"} 0 4 4
18  
19 _croak "NumEq type constraints cannot have a constraint coderef passed to the constructor"
20 4 ▶ if exists $opts{constraint};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"constraint"} 0 4 4
21  
22 _croak "NumEq type constraints cannot have a inlining coderef passed to the constructor"
23 4 ▶ if exists $opts{inlined};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"inlined"} 0 4 4
24  
25 4 ▶ _croak "Need to supply value" unless exists $opts{value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"value"} 0 4 4
26  
27 4 ▶ _croak "NumEq value must be defined" unless defined $opts{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"value"} 1 3 4
28  
29 {
30 2 ▶ use warnings FATAL => 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 eval {
32 3 $opts{value} = $opts{value} + 0; # numify
33 };
34 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 2 3
35 1 _croak sprintf("`%s` is not number. NumEq value must be number.", $opts{value});
36 }
37 }
38  
39 2 return $class->SUPER::new( %opts );
40 }
41  
42 6 ▶sub value { $_[0]{value} }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
43  
44 2 ▶sub _build_display_name {
Subroutine _build_display_name: called CC=1 SCAR=0.0
45 2 my $self = shift;
46 2 sprintf( "NumEq[%s]", $self->value );
47 }
48  
49 0 ▶sub has_parent {
Subroutine has_parent: not called CC=1 SCAR=6.9
Pod documented
50 0 !!0;
51 }
52  
53 2 ▶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
020
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
54  
55 2 ▶sub _build_constraint {
Subroutine _build_constraint: called CC=1 SCAR=2.0
56 2 my $self = shift;
57 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
58 0 ▶ defined $_ && $_ == $self->value;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ == $self->value 0 0 0
59 2 };
60 }
61  
62 2 ▶sub can_be_inlined {
Subroutine can_be_inlined: called CC=1 SCAR=0.0
Pod documented
63 2 !!1;
64 }
65  
66 2 ▶sub inline_check {
Subroutine inline_check: called CC=2 SCAR=7.0
Pod documented
67 2 my $self = shift;
68  
69 2 my $value = $self->value;
70 2 my $code = "(defined($_[0]) && $_[0] == $value)";
71  
72 2 ▶ return "do { $Type::Tiny::SafePackage $code }"
Branch: 1 branch
BranchTrueFalseTotal
if $Type::Tiny::AvoidCallbacks 0 2 2
73 if $Type::Tiny::AvoidCallbacks; ## no critic (Variables::ProhibitPackageVars)
74 2 return $code;
75 }
76  
77 2 1;
78 __END__
↑ Summary Type/Tiny/NumEqu.pm »