YAFT/Cmp.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 95 CC 4 SCAR 11.3
CC
4
Cov
0%
_overload_binary_minus
6.0
init
6.0
complementary
6.0
CRAP 3.1
1  
2 use v5.14;
3 use warnings;
4  
5 use Syntax::Construct qw (package-block package-version);
6  
7 package Test::YAFT::Cmp v1.0.4 {
8 use parent qw (Test::Deep::Cmp);
9  
10 require overload;
11 require Safe::Isa;
12  
13 require Test::YAFT::Cmp::Complement;
14  
15 BEGIN {
16 Test::Deep::Cmp->overload::OVERLOAD (
17 q (+) => \& Test::Deep::Cmp::make_all,
18 q (-) => \& _overload_binary_minus,
19 q (!) => \& _overload_complement,
20 q (~) => \& _overload_complement,
21 q (neg) => \& _overload_complement,
22 );
23 }
24  
25 sub _create_complement {
26 my ($self) = @_;
27  
28 return Test::YAFT::Cmp::Complement::->new ($self);
29 }
30  
31 sub _overload_binary_minus {
32 my ($lhs, $rhs, $swap) = @_;
33  
34 if ($swap) {
35 $rhs = expect_value ($rhs);
36 ($lhs, $rhs) = ($rhs, $lhs);
37 }
38  
39 return $lhs + ! $rhs;
40 }
41  
42 sub _overload_complement {
43 my ($expectation) = @_;
44  
45 my $builder = $expectation->can (q (_create_complement))
46 // \ &_create_complement
47 ;
48  
49 $builder->($expectation);
50 }
51  
52 sub init {
53 my ($self, $val) = @_;
54  
55 $self->{val} = $val
56 if @_ > 1
57 ;
58 }
59  
60 sub _val {
61 $_[0]->{val};
62 }
63  
64 sub _render_value {
65 my ($self, $value) = @_;
66  
67 Test::Deep::render_val ($value);
68 }
69  
70 sub complementary {
71 my ($self, @values) = @_;
72  
73 my $class = ref ($self) || $self;
74  
75 my $instance = $class->new (@values);
76 $instance->{_complement} = $self->is_complement ? 0 : 1;
77  
78 return $instance;
79 }
80  
81 sub descend {
82 my ($self, $got) = @_;
83  
84 Test::Deep::descend ($got, $self->_val);
85 }
86  
87 sub is_complement {
88 my ($self) = @_;
89  
90 return $self->{_complement};
91 }
92  
93 sub renderGot {
94 my ($self, $got) = @_;
95  
96 $self->_render_value ($got);
97 }
98  
99 sub renderExp {
100 my ($self) = @_;
101  
102 $self->_render_value ($self->_val);
103 }
104  
105 1;
106 };
107  
108 __END__