line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Compare::Object; |
2
|
168
|
|
|
168
|
|
1326
|
use strict; |
|
168
|
|
|
|
|
353
|
|
|
168
|
|
|
|
|
5073
|
|
3
|
168
|
|
|
168
|
|
801
|
use warnings; |
|
168
|
|
|
|
|
320
|
|
|
168
|
|
|
|
|
4434
|
|
4
|
|
|
|
|
|
|
|
5
|
168
|
|
|
168
|
|
944
|
use Test2::Util qw/try/; |
|
168
|
|
|
|
|
885
|
|
|
168
|
|
|
|
|
7140
|
|
6
|
|
|
|
|
|
|
|
7
|
168
|
|
|
168
|
|
916
|
use Test2::Compare::Meta(); |
|
168
|
|
|
|
|
384
|
|
|
168
|
|
|
|
|
3017
|
|
8
|
|
|
|
|
|
|
|
9
|
168
|
|
|
168
|
|
750
|
use base 'Test2::Compare::Base'; |
|
168
|
|
|
|
|
311
|
|
|
168
|
|
|
|
|
19550
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.000153'; |
12
|
|
|
|
|
|
|
|
13
|
168
|
|
|
168
|
|
1124
|
use Test2::Util::HashBase qw/calls meta refcheck ending/; |
|
168
|
|
|
|
|
368
|
|
|
168
|
|
|
|
|
1054
|
|
14
|
|
|
|
|
|
|
|
15
|
168
|
|
|
168
|
|
41915
|
use Carp qw/croak confess/; |
|
168
|
|
|
|
|
341
|
|
|
168
|
|
|
|
|
8264
|
|
16
|
168
|
|
|
168
|
|
976
|
use Scalar::Util qw/reftype blessed/; |
|
168
|
|
|
|
|
327
|
|
|
168
|
|
|
|
|
147903
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub init { |
19
|
2214
|
|
|
2214
|
0
|
31963
|
my $self = shift; |
20
|
2214
|
|
100
|
|
|
10523
|
$self->{+CALLS} ||= []; |
21
|
2214
|
|
|
|
|
6174
|
$self->SUPER::init(); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
18
|
|
|
18
|
1
|
50
|
sub name { ' |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
5
|
1
|
24
|
sub meta_class { 'Test2::Compare::Meta' } |
27
|
29
|
|
|
29
|
1
|
111
|
sub object_base { 'UNIVERSAL' } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub verify { |
30
|
2232
|
|
|
2232
|
1
|
3818
|
my $self = shift; |
31
|
2232
|
|
|
|
|
6697
|
my %params = @_; |
32
|
2232
|
|
|
|
|
5120
|
my ($got, $exists) = @params{qw/got exists/}; |
33
|
|
|
|
|
|
|
|
34
|
2232
|
100
|
|
|
|
4441
|
return 0 unless $exists; |
35
|
2231
|
100
|
|
|
|
4038
|
return 0 unless defined $got; |
36
|
2230
|
100
|
|
|
|
4497
|
return 0 unless ref($got); |
37
|
2227
|
100
|
|
|
|
6295
|
return 0 unless blessed($got); |
38
|
2225
|
100
|
|
|
|
6634
|
return 0 unless $got->isa($self->object_base); |
39
|
2224
|
|
|
|
|
6597
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add_prop { |
43
|
3004
|
|
|
3004
|
1
|
6374
|
my $self = shift; |
44
|
3004
|
100
|
|
|
|
9494
|
$self->{+META} = $self->meta_class->new unless defined $self->{+META}; |
45
|
3004
|
|
|
|
|
11695
|
$self->{+META}->add_prop(@_); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub add_field { |
49
|
78
|
|
|
78
|
1
|
298
|
my $self = shift; |
50
|
78
|
100
|
|
|
|
198
|
$self->{+REFCHECK} = Test2::Compare::Hash->new unless defined $self->{+REFCHECK}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
croak "Underlying reference does not have fields" |
53
|
78
|
100
|
|
|
|
488
|
unless $self->{+REFCHECK}->can('add_field'); |
54
|
|
|
|
|
|
|
|
55
|
77
|
|
|
|
|
182
|
$self->{+REFCHECK}->add_field(@_); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_item { |
59
|
8
|
|
|
8
|
1
|
81
|
my $self = shift; |
60
|
8
|
100
|
|
|
|
32
|
$self->{+REFCHECK} = Test2::Compare::Array->new unless defined $self->{+REFCHECK}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
croak "Underlying reference does not have items" |
63
|
8
|
100
|
|
|
|
136
|
unless $self->{+REFCHECK}->can('add_item'); |
64
|
|
|
|
|
|
|
|
65
|
7
|
|
|
|
|
22
|
$self->{+REFCHECK}->add_item(@_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub add_call { |
69
|
1852
|
|
|
1852
|
1
|
7351
|
my $self = shift; |
70
|
1852
|
|
|
|
|
3704
|
my ($meth, $check, $name, $context) = @_; |
71
|
1852
|
100
|
66
|
|
|
9337
|
$name ||= ref $meth eq 'ARRAY' ? $meth->[0] |
|
|
100
|
|
|
|
|
|
72
|
|
|
|
|
|
|
: ref $meth eq 'CODE' ? '\&CODE' |
73
|
|
|
|
|
|
|
: $meth; |
74
|
1852
|
|
100
|
|
|
2706
|
push @{$self->{+CALLS}} => [$meth, $check, $name, $context || 'scalar']; |
|
1852
|
|
|
|
|
10563
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub deltas { |
78
|
2225
|
|
|
2225
|
1
|
3911
|
my $self = shift; |
79
|
2225
|
|
|
|
|
5974
|
my %params = @_; |
80
|
2225
|
|
|
|
|
4591
|
my ($got, $convert, $seen) = @params{qw/got convert seen/}; |
81
|
|
|
|
|
|
|
|
82
|
2225
|
|
|
|
|
3231
|
my @deltas; |
83
|
2225
|
|
|
|
|
4496
|
my $meta = $self->{+META}; |
84
|
2225
|
|
|
|
|
3638
|
my $refcheck = $self->{+REFCHECK}; |
85
|
|
|
|
|
|
|
|
86
|
2225
|
100
|
|
|
|
9636
|
push @deltas => $meta->deltas(%params) if defined $meta; |
87
|
|
|
|
|
|
|
|
88
|
2225
|
|
|
|
|
4111
|
for my $call (@{$self->{+CALLS}}) { |
|
2225
|
|
|
|
|
6491
|
|
89
|
1942
|
|
|
|
|
5739
|
my ($meth, $check, $name, $context)= @$call; |
90
|
1942
|
|
50
|
|
|
5832
|
$context ||= 'scalar'; |
91
|
|
|
|
|
|
|
|
92
|
1942
|
|
|
|
|
4486
|
$check = $convert->($check); |
93
|
|
|
|
|
|
|
|
94
|
1942
|
|
|
|
|
4295
|
my @args; |
95
|
1942
|
100
|
|
|
|
4336
|
if (ref($meth) eq 'ARRAY') { |
96
|
26
|
|
|
|
|
33
|
($meth,@args) = @{$meth}; |
|
26
|
|
|
|
|
63
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1942
|
|
100
|
|
|
9381
|
my $exists = ref($meth) || $got->can($meth); |
100
|
1942
|
|
|
|
|
2988
|
my $val; |
101
|
|
|
|
|
|
|
my ($ok, $err) = try { |
102
|
1942
|
100
|
|
1942
|
|
25787
|
$val = $exists |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
103
|
|
|
|
|
|
|
? ( $context eq 'list' ? [ $got->$meth(@args) ] : |
104
|
|
|
|
|
|
|
$context eq 'hash' ? { $got->$meth(@args) } : |
105
|
|
|
|
|
|
|
$got->$meth(@args) |
106
|
|
|
|
|
|
|
) |
107
|
|
|
|
|
|
|
: undef; |
108
|
1942
|
|
|
|
|
11128
|
}; |
109
|
|
|
|
|
|
|
|
110
|
1942
|
100
|
|
|
|
29756
|
if (!$ok) { |
111
|
2
|
|
|
|
|
20
|
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
|
1940
|
100
|
|
|
|
8497
|
push @deltas => $check->run( |
121
|
|
|
|
|
|
|
id => [METHOD => $name], |
122
|
|
|
|
|
|
|
convert => $convert, |
123
|
|
|
|
|
|
|
seen => $seen, |
124
|
|
|
|
|
|
|
exists => $exists, |
125
|
|
|
|
|
|
|
$exists ? (got => $val) : (), |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
2225
|
100
|
|
|
|
6951
|
return @deltas unless defined $refcheck; |
131
|
|
|
|
|
|
|
|
132
|
1268
|
|
|
|
|
5112
|
$refcheck->set_ending($self->{+ENDING}); |
133
|
|
|
|
|
|
|
|
134
|
1268
|
100
|
|
|
|
10291
|
if ($refcheck->verify(%params)) { |
135
|
1265
|
|
|
|
|
4485
|
push @deltas => $refcheck->deltas(%params); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else { |
138
|
3
|
|
|
|
|
13
|
push @deltas => $self->delta_class->new( |
139
|
|
|
|
|
|
|
verified => undef, |
140
|
|
|
|
|
|
|
id => [META => 'Object Ref'], |
141
|
|
|
|
|
|
|
got => $got, |
142
|
|
|
|
|
|
|
check => $refcheck, |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
1268
|
|
|
|
|
4165
|
return @deltas; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |