| 1 | package Test2::Compare::Base; | ||||||||||||||||||||||||||||
| 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 | our $VERSION = '1.302226'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 176 | ▶ | use Carp qw/confess croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 176 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 176 | ▶ | use Test2::Util::Sub qw/sub_info/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 176 | ▶ | use Test2::Compare::Delta(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub MAX_CYCLES() { 75 } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 176 | ▶ | use Test2::Util::HashBase qw{builder _file _lines _info called}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 176 | ▶ | use Test2::Util::Ref qw/render_ref/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||
| 19 | 176 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 176 | *set_lines = \&set__lines; | |||||||||||||||||||||||||||
| 21 | 176 | *set_file = \&set__file; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 250 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 250 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | 250 | my $class = blessed($self); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Shallow copy is good enough for all the current compare types. | ||||||||||||||||||||||||||||
| 29 | 250 | return bless({%$self}, $class); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 19480 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 19480 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 19480 | ▶ | $self->{+_LINES} = delete $self->{lines} if exists $self->{lines}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 19480 | ▶ | $self->{+_FILE} = delete $self->{file} if exists $self->{file}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 96 | ▶ | sub file { | ||||||||||||||||||||||||||
|
Subroutine
file: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 96 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 96 | ▶ | return $self->{+_FILE} if $self->{+_FILE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 83 | ▶ | if ($self->{+BUILDER}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 43 | 56 | ▶ | $self->{+_INFO} ||= sub_info($self->{+BUILDER}); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_info"} ||= sub_info($self->{"builder"})
MC/DC0%0/2
$self->{"_info"} ||= sub_info($self->{"builder"})
$self->{"_info"}
sub_info($self->{"builder"})
Truth table66%2/3
A ||= B
A= $self->{"_info"}B= sub_info($self->{"builder"})
| |||||||||||||||||||||||||||||
| 44 | 56 | return $self->{+_INFO}->{file}; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | elsif ($self->{+CALLED}) { | ||||||||||||||||||||||||||||
| 47 | 0 | return $self->{+CALLED}->[1]; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 27 | return undef; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 445 | ▶ | sub lines { | ||||||||||||||||||||||||||
|
Subroutine
lines: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 445 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 445 | ▶ | return $self->{+_LINES} if $self->{+_LINES}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 188 | ▶ | if ($self->{+BUILDER}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 118 | ▶ | $self->{+_INFO} ||= sub_info($self->{+BUILDER}); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_info"} ||= sub_info($self->{"builder"})
MC/DC0%0/2
$self->{"_info"} ||= sub_info($self->{"builder"})
$self->{"_info"}
sub_info($self->{"builder"})
Truth table66%2/3
A ||= B
A= $self->{"_info"}B= sub_info($self->{"builder"})
| |||||||||||||||||||||||||||||
| 59 | 118 | ▶ | return $self->{+_INFO}->{lines} if @{$self->{+_INFO}->{lines}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 70 | ▶ | if ($self->{+CALLED}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1 | return [$self->{+CALLED}->[2]]; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 69 | return []; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2480 | ▶ | sub delta_class { 'Test2::Compare::Delta' } | ||||||||||||||||||||||||||
|
Subroutine
delta_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 8177 | ▶ | sub deltas { () } | ||||||||||||||||||||||||||
|
Subroutine
deltas: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 296 | ▶ | sub got_lines { () } | ||||||||||||||||||||||||||
|
Subroutine
got_lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 544 | ▶ | sub verify_build { } | ||||||||||||||||||||||||||
|
Subroutine
verify_build: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 12 | ▶ | sub throw_build_error { | ||||||||||||||||||||||||||
|
Subroutine
throw_build_error: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | 12 | my ($msg) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 12 | ▶ | my $file = $self->file || 'unknown file'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->file || 'unknown file'
MC/DC100%1/1
$self->file || 'unknown file'
$self->file
Truth table100%2/2
A
A= $self->file
| |||||||||||||||||||||||||||||
| 79 | 12 | my $lines = $self->lines; | |||||||||||||||||||||||||||
| 80 | 12 | ▶ | my $line = $lines && @$lines ? $lines->[0] : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$lines and @$lines
MC/DC50%1/2
$lines and @$lines
$lines
@$lines
Truth table66%2/3
A and B
A= $linesB= @$lines
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 12 | die "$msg at $file line $line.\n"; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 441 | ▶ | sub stringify_got { 0 } | ||||||||||||||||||||||||||
|
Subroutine
stringify_got: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 68 | ▶ | sub operator { '' } | ||||||||||||||||||||||||||
|
Subroutine
operator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | sub verify { confess "unimplemented" } | ||||||||||||||||||||||||||
|
Subroutine
verify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub name { confess "unimplemented" } | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 320 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 320 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | 320 | return $self->name; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 14824 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 14824 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 14824 | my %params = @_; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 14824 | my $id = $params{id}; | |||||||||||||||||||||||||||
| 101 | 14824 | ▶ | my $convert = $params{convert} or confess "no convert sub provided"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 14824 | ▶ | my $seen = $params{seen} ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$params{"seen"} ||= {}
MC/DC0%0/1
$params{"seen"} ||= {}
$params{"seen"}
Truth table50%1/2
A
A= $params{"seen"}
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | $params{exists} = exists $params{got} ? 1 : 0 | ||||||||||||||||||||||||||||
| 105 | 14824 | ▶ | unless exists $params{exists}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 14824 | my $exists = $params{exists}; | |||||||||||||||||||||||||||
| 108 | 14824 | ▶ | my $got = $exists ? $params{got} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 14824 | my $gotname = render_ref($got); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # Prevent infinite cycles | ||||||||||||||||||||||||||||
| 113 | 14824 | ▶ | if (defined($got) && ref $got) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $got and ref $got
MC/DC100%2/2
defined $got and ref $got
defined $got
ref $got
Truth table100%3/3
A and B
A= defined $gotB= ref $got
| |||||||||||||||||||||||||||||
| 114 | die "Cycle detected in comparison, aborting" | ||||||||||||||||||||||||||||
| 115 | 4437 | ▶ | if $seen->{$gotname} && $seen->{$gotname} >= MAX_CYCLES; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$seen->{$gotname} and $seen->{$gotname} >= 75
MC/DC0%0/2
$seen->{$gotname} and $seen->{$gotname} >= 75
$seen->{$gotname}
$seen->{$gotname} >= 75
Truth table66%2/3
A and B
A= $seen->{$gotname}B= $seen->{$gotname} >= 75
| |||||||||||||||||||||||||||||
| 116 | 4437 | $seen->{$gotname}++; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 14824 | my $ok = $self->verify(%params); | |||||||||||||||||||||||||||
| 120 | 14824 | ▶ | my @deltas = $ok ? $self->deltas(%params) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 14824 | ▶ | $seen->{$gotname}-- if defined $got && ref $got; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $got and ref $got
MC/DC100%2/2
defined $got and ref $got
defined $got
ref $got
Truth table100%3/3
A and B
A= defined $gotB= ref $got
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 14824 | ▶ | return if $ok && !@deltas; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ok and not @deltas
MC/DC100%2/2
$ok and not @deltas
$ok
not @deltas
Truth table100%3/3
A and not(B)
A= $okB= not @deltas
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 2435 | ▶ | return $self->delta_class->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | verified => $ok, | ||||||||||||||||||||||||||||
| 128 | id => $id, | ||||||||||||||||||||||||||||
| 129 | got => $got, | ||||||||||||||||||||||||||||
| 130 | check => $self, | ||||||||||||||||||||||||||||
| 131 | children => \@deltas, | ||||||||||||||||||||||||||||
| 132 | $exists ? () : (dne => 'got'), | ||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 176 | 1; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||