| 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"} ||= []
MC/DC100%1/1
$self->{"calls"} ||= []
$self->{"calls"}
Truth table100%2/2
A
A= $self->{"calls"}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 35 | 1883 | ▶ | return 0 unless defined $got; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | 1882 | ▶ | return 0 unless ref($got); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | 1879 | ▶ | return 0 unless blessed($got); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 1877 | ▶ | return 0 unless $got->isa($self->object_base); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | croak "Underlying reference does not have fields" | ||||||||||||||||||||||||||||||||
| 53 | 78 | ▶ | unless $self->{+REFCHECK}->can('add_field'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | croak "Underlying reference does not have items" | ||||||||||||||||||||||||||||||||
| 63 | 8 | ▶ | unless $self->{+REFCHECK}->can('add_item'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$name ||= ref $meth eq "ARRAY" ? $meth->[0] : (ref $meth eq "CODE" ? "\\&CODE" : $meth)
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)
| |||||||||||||||||||||||||||||||||
| 72 | : ref $meth eq 'CODE' ? '\&CODE' | ||||||||||||||||||||||||||||||||
| 73 | : $meth; | ||||||||||||||||||||||||||||||||
| 74 | 826 | ▶ | push @{$self->{+CALLS}} => [$meth, $check, $name, $context || 'scalar']; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$context || 'scalar'
MC/DC100%1/1
$context || 'scalar'
$context
Truth table100%2/2
A
A= $context
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$context ||= "scalar"
$context
Truth table50%1/2
A
A= $context
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 915 | $check = $convert->($check); | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 915 | my @args; | |||||||||||||||||||||||||||||||
| 95 | 915 | ▶ | if (ref($meth) eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 26 | ($meth,@args) = @{$meth}; | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 915 | ▶ | my $exists = ref($meth) || $got->can($meth); | ||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $meth || $got->can($meth)
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)
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | 1272 | $refcheck->set_ending($self->{+ENDING}); | |||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 1272 | ▶ | if ($refcheck->verify(%params)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||