Type/Tiny/Equ.pm

filter: Statementstmt 85.7% 36 / 42 Branchbran 63.6% 14 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 10 / 14 Podpod 100% 6 / 6 totaltotal 75.2% 67 / 89 CC 13 SCAR 13.7
CC
13
Cov
76%
new
8.1
__ANON__
6.0
inline_check
3.0
CRAP 3.9
« Type/Tiny/NumEqu.pm ↑ Summary Type/Tiny/Eq.pm »
1 package Type::Tiny::Equ;
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 0 ▶sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
Subroutine _croak: not called CC=1 SCAR=6.9
10  
11 10 ▶sub new {
Subroutine new: called CC=7 SCAR=21.0
Pod documented
12 10 my $class = shift;
13  
14 0 ▶ my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 10 10
15  
16 _croak "Equ type constraints cannot have a parent constraint passed to the constructor"
17 10 ▶ if exists $opts{parent};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"parent"} 0 10 10
18  
19 _croak "Equ type constraints cannot have a constraint coderef passed to the constructor"
20 10 ▶ if exists $opts{constraint};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"constraint"} 0 10 10
21  
22 _croak "Equ type constraints cannot have a inlining coderef passed to the constructor"
23 10 ▶ if exists $opts{inlined};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"inlined"} 0 10 10
24  
25 10 ▶ _croak "Need to supply value" unless exists $opts{value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"value"} 0 10 10
26  
27 # stringify
28 10 ▶ $opts{value} = defined $opts{value} ? "$opts{value}" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $opts{'value'} ? : 5 5 10
29  
30 10 return $class->SUPER::new( %opts );
31 }
32  
33 41 ▶sub value { $_[0]{value} }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
34  
35 10 ▶sub _build_display_name {
Subroutine _build_display_name: called CC=2 SCAR=6.9
36 10 my $self = shift;
37 10 ▶ defined $self->value
Branch: 1 branch
BranchTrueFalseTotal
defined $self->value ? : 5 5 10
38 ? sprintf( "Equ['%s']", $self->value )
39 : "Equ[Undef]";
40 }
41  
42 0 ▶sub has_parent {
Subroutine has_parent: not called CC=1 SCAR=6.9
Pod documented
43 0 !!0;
44 }
45  
46 10 ▶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
0100
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
47  
48 10 ▶sub _build_constraint {
Subroutine _build_constraint: called CC=2 SCAR=8.1
49 10 my $self = shift;
50  
51 10 ▶ if (defined $self->value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->value) { } 5 5 10
52 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
53 0 ▶ defined $_ && $_ eq $self->value;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and $_ eq $self->value 0 0 0
54 5 };
55 }
56 else {
57 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 0 !defined $_;
59 5 };
60 }
61 }
62  
63 14 ▶sub can_be_inlined {
Subroutine can_be_inlined: called CC=1 SCAR=0.0
Pod documented
64 14 !!1;
65 }
66  
67 14 ▶sub inline_check {
Subroutine inline_check: called CC=3 SCAR=11.0
Pod documented
68 14 my $self = shift;
69  
70 14 my $value = $self->value;
71 14 my $code;
72 14 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 8 6 14
73 8 $code = "(defined($_[0]) && $_[0] eq '$value')";
74 }
75 else {
76 6 $code = "!defined($_[0])";
77 }
78  
79 14 ▶ return "do { $Type::Tiny::SafePackage $code }"
Branch: 1 branch
BranchTrueFalseTotal
if $Type::Tiny::AvoidCallbacks 0 14 14
80 if $Type::Tiny::AvoidCallbacks; ## no critic (Variables::ProhibitPackageVars)
81 14 return $code;
82 }
83  
84 2 1;
85 __END__
« Type/Tiny/NumEqu.pm ↑ Summary Type/Tiny/Eq.pm »