line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Compare::Object; |
2
|
169
|
|
|
169
|
|
1467
|
use strict; |
|
169
|
|
|
|
|
355
|
|
|
169
|
|
|
|
|
5411
|
|
3
|
169
|
|
|
169
|
|
857
|
use warnings; |
|
169
|
|
|
|
|
372
|
|
|
169
|
|
|
|
|
4567
|
|
4
|
|
|
|
|
|
|
|
5
|
169
|
|
|
169
|
|
928
|
use Test2::Util qw/try/; |
|
169
|
|
|
|
|
333
|
|
|
169
|
|
|
|
|
7315
|
|
6
|
|
|
|
|
|
|
|
7
|
169
|
|
|
169
|
|
966
|
use Test2::Compare::Meta(); |
|
169
|
|
|
|
|
316
|
|
|
169
|
|
|
|
|
2822
|
|
8
|
|
|
|
|
|
|
|
9
|
169
|
|
|
169
|
|
884
|
use base 'Test2::Compare::Base'; |
|
169
|
|
|
|
|
354
|
|
|
169
|
|
|
|
|
18489
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.000156'; |
12
|
|
|
|
|
|
|
|
13
|
169
|
|
|
169
|
|
1125
|
use Test2::Util::HashBase qw/calls meta refcheck ending/; |
|
169
|
|
|
|
|
357
|
|
|
169
|
|
|
|
|
1092
|
|
14
|
|
|
|
|
|
|
|
15
|
169
|
|
|
169
|
|
44683
|
use Carp qw/croak confess/; |
|
169
|
|
|
|
|
375
|
|
|
169
|
|
|
|
|
9405
|
|
16
|
169
|
|
|
169
|
|
1082
|
use Scalar::Util qw/reftype blessed/; |
|
169
|
|
|
|
|
396
|
|
|
169
|
|
|
|
|
163133
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub init { |
19
|
2226
|
|
|
2226
|
0
|
32951
|
my $self = shift; |
20
|
2226
|
|
100
|
|
|
10841
|
$self->{+CALLS} ||= []; |
21
|
2226
|
|
|
|
|
6672
|
$self->SUPER::init(); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
18
|
|
|
18
|
1
|
67
|
sub name { ' |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
5
|
1
|
34
|
sub meta_class { 'Test2::Compare::Meta' } |
27
|
29
|
|
|
29
|
1
|
117
|
sub object_base { 'UNIVERSAL' } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub verify { |
30
|
2244
|
|
|
2244
|
1
|
3972
|
my $self = shift; |
31
|
2244
|
|
|
|
|
6456
|
my %params = @_; |
32
|
2244
|
|
|
|
|
5328
|
my ($got, $exists) = @params{qw/got exists/}; |
33
|
|
|
|
|
|
|
|
34
|
2244
|
100
|
|
|
|
4623
|
return 0 unless $exists; |
35
|
2243
|
100
|
|
|
|
4382
|
return 0 unless defined $got; |
36
|
2242
|
100
|
|
|
|
4565
|
return 0 unless ref($got); |
37
|
2239
|
100
|
|
|
|
6391
|
return 0 unless blessed($got); |
38
|
2237
|
100
|
|
|
|
6929
|
return 0 unless $got->isa($self->object_base); |
39
|
2236
|
|
|
|
|
6769
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add_prop { |
43
|
3016
|
|
|
3016
|
1
|
5948
|
my $self = shift; |
44
|
3016
|
100
|
|
|
|
9013
|
$self->{+META} = $self->meta_class->new unless defined $self->{+META}; |
45
|
3016
|
|
|
|
|
12365
|
$self->{+META}->add_prop(@_); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub add_field { |
49
|
78
|
|
|
78
|
1
|
357
|
my $self = shift; |
50
|
78
|
100
|
|
|
|
239
|
$self->{+REFCHECK} = Test2::Compare::Hash->new unless defined $self->{+REFCHECK}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
croak "Underlying reference does not have fields" |
53
|
78
|
100
|
|
|
|
570
|
unless $self->{+REFCHECK}->can('add_field'); |
54
|
|
|
|
|
|
|
|
55
|
77
|
|
|
|
|
239
|
$self->{+REFCHECK}->add_field(@_); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_item { |
59
|
8
|
|
|
8
|
1
|
63
|
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
|
|
|
|
151
|
unless $self->{+REFCHECK}->can('add_item'); |
64
|
|
|
|
|
|
|
|
65
|
7
|
|
|
|
|
23
|
$self->{+REFCHECK}->add_item(@_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub add_call { |
69
|
1860
|
|
|
1860
|
1
|
6803
|
my $self = shift; |
70
|
1860
|
|
|
|
|
3622
|
my ($meth, $check, $name, $context) = @_; |
71
|
1860
|
100
|
66
|
|
|
9156
|
$name ||= ref $meth eq 'ARRAY' ? $meth->[0] |
|
|
100
|
|
|
|
|
|
72
|
|
|
|
|
|
|
: ref $meth eq 'CODE' ? '\&CODE' |
73
|
|
|
|
|
|
|
: $meth; |
74
|
1860
|
|
100
|
|
|
2209
|
push @{$self->{+CALLS}} => [$meth, $check, $name, $context || 'scalar']; |
|
1860
|
|
|
|
|
9077
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub deltas { |
78
|
2237
|
|
|
2237
|
1
|
4026
|
my $self = shift; |
79
|
2237
|
|
|
|
|
6479
|
my %params = @_; |
80
|
2237
|
|
|
|
|
4860
|
my ($got, $convert, $seen) = @params{qw/got convert seen/}; |
81
|
|
|
|
|
|
|
|
82
|
2237
|
|
|
|
|
3172
|
my @deltas; |
83
|
2237
|
|
|
|
|
4350
|
my $meta = $self->{+META}; |
84
|
2237
|
|
|
|
|
3936
|
my $refcheck = $self->{+REFCHECK}; |
85
|
|
|
|
|
|
|
|
86
|
2237
|
100
|
|
|
|
10742
|
push @deltas => $meta->deltas(%params) if defined $meta; |
87
|
|
|
|
|
|
|
|
88
|
2237
|
|
|
|
|
3859
|
for my $call (@{$self->{+CALLS}}) { |
|
2237
|
|
|
|
|
6654
|
|
89
|
1950
|
|
|
|
|
6074
|
my ($meth, $check, $name, $context)= @$call; |
90
|
1950
|
|
50
|
|
|
3911
|
$context ||= 'scalar'; |
91
|
|
|
|
|
|
|
|
92
|
1950
|
|
|
|
|
4272
|
$check = $convert->($check); |
93
|
|
|
|
|
|
|
|
94
|
1950
|
|
|
|
|
4466
|
my @args; |
95
|
1950
|
100
|
|
|
|
4522
|
if (ref($meth) eq 'ARRAY') { |
96
|
26
|
|
|
|
|
49
|
($meth,@args) = @{$meth}; |
|
26
|
|
|
|
|
83
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1950
|
|
100
|
|
|
10254
|
my $exists = ref($meth) || $got->can($meth); |
100
|
1950
|
|
|
|
|
3159
|
my $val; |
101
|
|
|
|
|
|
|
my ($ok, $err) = try { |
102
|
1950
|
100
|
|
1950
|
|
27182
|
$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
|
1950
|
|
|
|
|
12173
|
}; |
109
|
|
|
|
|
|
|
|
110
|
1950
|
100
|
|
|
|
32480
|
if (!$ok) { |
111
|
2
|
|
|
|
|
12
|
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
|
1948
|
100
|
|
|
|
8591
|
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
|
2237
|
100
|
|
|
|
8613
|
return @deltas unless defined $refcheck; |
131
|
|
|
|
|
|
|
|
132
|
1272
|
|
|
|
|
5106
|
$refcheck->set_ending($self->{+ENDING}); |
133
|
|
|
|
|
|
|
|
134
|
1272
|
100
|
|
|
|
10185
|
if ($refcheck->verify(%params)) { |
135
|
1269
|
|
|
|
|
4553
|
push @deltas => $refcheck->deltas(%params); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else { |
138
|
3
|
|
|
|
|
28
|
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
|
|
|
|
|
4309
|
return @deltas; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |