Compare/Condition.pm

filter: Statementstmt 100% 46 / 46 Branchbran 75.0% 15 / 20 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 12 / 12 Podpod 80.0% 4 / 5 totaltotal 90.7% 78 / 86 CC 12 SCAR 10.2
CC
12
Cov
91%
_render_bool
4.1
run
4.1
verify
4.0
CRAP 2.8
↑ Summary Tools/Condition.pm »
1 package Test2::Compare::Condition;
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 ▶use base 'Test2::Compare::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Test2::Util::HashBase qw/code/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Overloads '!' for us.
12 2 ▶use Test2::Compare::Negatable;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 11 ▶sub init {
Subroutine init: called CC=2 SCAR=7.1
Pod undocumented
15 11 my $self = shift;
16  
17 11 ▶ croak "'code' must be a code reference" unless ref $self->{+CODE} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"code"} eq "CODE" 0 11 11
18  
19 11 $self->SUPER::init();
20 }
21  
22 2 ▶sub operator {
Subroutine operator: called CC=2 SCAR=6.9
Pod documented
23 2 my $self = shift;
24 2 ▶ return '!=' if $self->{+NEGATE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"negate"} 1 1 2
25 1 return '==';
26 }
27  
28 2 ▶sub name { '<CONDITION>' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
29  
30 13 ▶sub verify {
Subroutine verify: called CC=4 SCAR=13.9
Pod documented
31 13 my $self = shift;
32 13 my %params = @_;
33 13 my ($got, $exists) = @params{qw/got exists/};
34  
35 13 ▶ return 0 unless $params{exists};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"exists"} 0 13 13
36  
37 13 local $_ = $got;
38 13 my $cond = $self->{+CODE}->();
39 13 ▶ $cond = $cond ? 0 : 1 if $self->{+NEGATE};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"negate"} 3 10 13
$cond ? : 1 2 3
40  
41 13 return $cond;
42 }
43  
44 13 ▶sub run {
Subroutine run: called CC=4 SCAR=14.0
Pod documented
45 13 my $self = shift;
46 13 ▶ my $delta = $self->SUPER::run(@_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $delta = $self->SUPER::run(@_) or return 4 9 13
47  
48 4 ▶ my $dne = $delta->dne || "";
Condition50%1/2
$delta->dne || ''
l!l
04
MC/DC0%0/1
$delta->dne || ''
$delta->dne
Truth table50%1/2
A
A= $delta->dne
Aresult
11
00
49 4 ▶ unless ($dne eq 'got') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dne eq "got") 4 0 4
50 4 my $got = $delta->got;
51 4 $delta->set_got(_render_bool($got));
52 }
53  
54 4 return $delta;
55 }
56  
57 4 ▶sub _render_bool {
Subroutine _render_bool: called CC=4 SCAR=14.1
58 4 my $bool = shift;
59 4 ▶ my $name = $bool ? 'TRUE' : 'FALSE';
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 2 2 4
60 4 ▶ my $val = defined $bool ? $bool : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $bool ? : 4 0 4
61 4 ▶ $val = "''" unless length($val);
Branch: 1 branch
BranchTrueFalseTotal
unless length $val 0 4 4
62  
63 4 return "<$name ($val)>";
64 }
65  
66 2 1;
↑ Summary Tools/Condition.pm »