blib/lib/Test2/Compare/Object.pm

filter: Statementstmt 100% 86 / 86 Branchbran 100% 42 / 42 Conditioncond 83.3% 10 / 12 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 100% 19 / 19 Podpod 90.0% 9 / 10 totaltotal 96.5% 170 / 176 CC 28 SCAR 15.4
CC
28
Cov
99%
deltas
10.0
verify
6.0
add_call
5.0
CRAP 4.7
« lib/Test/Tester/Capture.pm ↑ Summary blib/lib/Test2/Util/Table.pm »
1 package Test2::Compare::Object;
2 176 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 176 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 176 ▶use Test2::Util qw/try/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 176 ▶use Test2::Compare::Meta();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 176 ▶use base 'Test2::Compare::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 176 our $VERSION = '1.302226';
12  
13 176 ▶use Test2::Util::HashBase qw/calls meta refcheck ending/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 176 ▶use Carp qw/croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 176 ▶use Scalar::Util qw/reftype blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1867 ▶sub init {
Subroutine init: called CC=2 SCAR=6.9
Pod undocumented
19 1867 my $self = shift;
20 1867 ▶ $self->{+CALLS} ||= [];
Condition100%2/2
$self->{"calls"} ||= []
l!l
11866
MC/DC100%1/1
$self->{"calls"} ||= []
$self->{"calls"}
Truth table100%2/2
A
A= $self->{"calls"}
Aresult
11
00
21 1867 $self->SUPER::init();
22 }
23  
24 18 ▶sub name { '<OBJECT>' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
25  
26 5 ▶sub meta_class { 'Test2::Compare::Meta' }
Subroutine meta_class: called CC=1 SCAR=0.0
Pod documented
27 29 ▶sub object_base { 'UNIVERSAL' }
Subroutine object_base: called CC=1 SCAR=0.0
Pod documented
28  
29 1884 ▶sub verify {
Subroutine verify: called CC=6 SCAR=17.9
Pod documented
30 1884 my $self = shift;
31 1884 my %params = @_;
32 1884 my ($got, $exists) = @params{qw/got exists/};
33  
34 1884 ▶ return 0 unless $exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 1 1883 1884
35 1883 ▶ return 0 unless defined $got;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $got 1 1882 1883
36 1882 ▶ return 0 unless ref($got);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $got 3 1879 1882
37 1879 ▶ return 0 unless blessed($got);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($got) 2 1877 1879
38 1877 ▶ return 0 unless $got->isa($self->object_base);
Branch: 1 branch
BranchTrueFalseTotal
unless $got->isa($self->object_base) 1 1876 1877
39 1876 return 1;
40 }
41  
42 1946 ▶sub add_prop {
Subroutine add_prop: called CC=2 SCAR=6.9
Pod documented
43 1946 my $self = shift;
44 1946 ▶ $self->{+META} = $self->meta_class->new unless defined $self->{+META};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"meta"} 1849 97 1946
45 1946 $self->{+META}->add_prop(@_);
46 }
47  
48 78 ▶sub add_field {
Subroutine add_field: called CC=3 SCAR=11.0
Pod documented
49 78 my $self = shift;
50 78 ▶ $self->{+REFCHECK} = Test2::Compare::Hash->new unless defined $self->{+REFCHECK};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"refcheck"} 35 43 78
51  
52 croak "Underlying reference does not have fields"
53 78 ▶ unless $self->{+REFCHECK}->can('add_field');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"refcheck"}->can("add_field") 1 77 78
54  
55 77 $self->{+REFCHECK}->add_field(@_);
56 }
57  
58 8 ▶sub add_item {
Subroutine add_item: called CC=3 SCAR=11.0
Pod documented
59 8 my $self = shift;
60 8 ▶ $self->{+REFCHECK} = Test2::Compare::Array->new unless defined $self->{+REFCHECK};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"refcheck"} 4 4 8
61  
62 croak "Underlying reference does not have items"
63 8 ▶ unless $self->{+REFCHECK}->can('add_item');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"refcheck"}->can("add_item") 1 7 8
64  
65 7 $self->{+REFCHECK}->add_item(@_);
66 }
67  
68 826 ▶sub add_call {
Subroutine add_call: called CC=5 SCAR=16.1
Pod documented
69 826 my $self = shift;
70 826 my ($meth, $check, $name, $context) = @_;
71 826 ▶ $name ||= ref $meth eq 'ARRAY' ? $meth->[0]
Branch: 2 branches
BranchTrueFalseTotal
ref $meth eq 'ARRAY' ? : 8 815 823
ref $meth eq 'CODE' ? : 1 814 815
Condition66%2/3
$name ||= ref $meth eq "ARRAY" ? $meth->[0] : (ref $meth eq "CODE" ? "\\&CODE" : $meth)
l!l&&r!l&&!r
38230
MC/DC0%0/2
$name ||= ref $meth eq "ARRAY" ? $meth->[0] : (ref $meth eq "CODE" ? "\\&CODE" : $meth)
$name ref $meth eq "ARRAY" ? $meth->[0] : (ref $meth eq "CODE" ? "\\&CODE" : $meth)
Truth table66%2/3
A ||= B
A= $nameB= ref $meth eq "ARRAY" ? $meth->[0] : (ref $meth eq "CODE" ? "\\&CODE" : $meth)
ABresult
1X1
011
000
72 : ref $meth eq 'CODE' ? '\&CODE'
73 : $meth;
74 826 ▶ push @{$self->{+CALLS}} => [$meth, $check, $name, $context || 'scalar'];
Condition100%2/2
$context || 'scalar'
l!l
8188
MC/DC100%1/1
$context || 'scalar'
$context
Truth table100%2/2
A
A= $context
Aresult
11
00
75 }
76  
77 1877 ▶sub deltas {
Subroutine deltas: called CC=10 SCAR=23.0
Pod documented
78 1877 my $self = shift;
79 1877 my %params = @_;
80 1877 my ($got, $convert, $seen) = @params{qw/got convert seen/};
81  
82 1877 my @deltas;
83 1877 my $meta = $self->{+META};
84 1877 my $refcheck = $self->{+REFCHECK};
85  
86 1877 ▶ push @deltas => $meta->deltas(%params) if defined $meta;
Branch: 1 branch
BranchTrueFalseTotal
if defined $meta 1859 18 1877
87  
88 1877 for my $call (@{$self->{+CALLS}}) {
89 915 my ($meth, $check, $name, $context)= @$call;
90 915 ▶ $context ||= 'scalar';
Condition50%1/2
$context ||= "scalar"
l!l
9150
MC/DC0%0/1
$context ||= "scalar"
$context
Truth table50%1/2
A
A= $context
Aresult
11
00
91  
92 915 $check = $convert->($check);
93  
94 915 my @args;
95 915 ▶ if (ref($meth) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meth eq "ARRAY") 26 889 915
96 26 ($meth,@args) = @{$meth};
97 }
98  
99 915 ▶ my $exists = ref($meth) || $got->can($meth);
Condition100%3/3
ref $meth || $got->can($meth)
l!l&&r!l&&!r
390210
MC/DC100%2/2
ref $meth || $got->can($meth)
ref $meth $got->can($meth)
Truth table100%3/3
A || B
A= ref $methB= $got->can($meth)
ABresult
1X1
011
000
100 915 my $val;
101 915 ▶ my ($ok, $err) = try {
Subroutine __ANON__: called CC=4 SCAR=13.9
102 915 ▶ $val = $exists
Branch: 3 branches
BranchTrueFalseTotal
$exists ? : 905 10 915
$context eq 'list' ? : 24 881 905
$context eq 'hash' ? : 24 857 881
103 ? ( $context eq 'list' ? [ $got->$meth(@args) ] :
104 $context eq 'hash' ? { $got->$meth(@args) } :
105 $got->$meth(@args)
106 )
107 : undef;
108 915 };
109  
110 915 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok) { } 2 913 915
111 2 push @deltas => $self->delta_class->new(
112 verified => undef,
113 id => [METHOD => $name],
114 got => undef,
115 check => $check,
116 exception => $err,
117 );
118 }
119 else {
120 913 ▶ push @deltas => $check->run(
Branch: 1 branch
BranchTrueFalseTotal
$exists ? : 903 10 913
121 id => [METHOD => $name],
122 convert => $convert,
123 seen => $seen,
124 exists => $exists,
125 $exists ? (got => $val) : (),
126 );
127 }
128 }
129  
130 1877 ▶ return @deltas unless defined $refcheck;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $refcheck 605 1272 1877
131  
132 1272 $refcheck->set_ending($self->{+ENDING});
133  
134 1272 ▶ if ($refcheck->verify(%params)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refcheck->verify(%params)) { } 1269 3 1272
135 1269 push @deltas => $refcheck->deltas(%params);
136 }
137 else {
138 3 push @deltas => $self->delta_class->new(
139 verified => undef,
140 id => [META => 'Object Ref'],
141 got => $got,
142 check => $refcheck,
143 );
144 }
145  
146 1272 return @deltas;
147 }
148  
149 176 1;
150  
151 __END__
« lib/Test/Tester/Capture.pm ↑ Summary blib/lib/Test2/Util/Table.pm »