| 1 | package Test2::Compare::Set; | ||||||||||||||||||||||||||||||||||||||||||
| 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 base 'Test2::Compare::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 176 | our $VERSION = '1.302226'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 176 | ▶ | use Test2::Util::HashBase qw/checks _reduction/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 176 | ▶ | use Test2::Compare::Delta(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 176 | ▶ | use Carp qw/croak confess/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 176 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 26 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 26 | ▶ | my $reduction = delete $self->{reduction} || 'any'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $self->{'reduction'} || 'any'
MC/DC100%1/1
delete $self->{'reduction'} || 'any'
delete $self->{'reduction'}
Truth table100%2/2
A
A= delete $self->{'reduction'}
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 26 | ▶ | $self->{+CHECKS} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"checks"} ||= []
MC/DC100%1/1
$self->{"checks"} ||= []
$self->{"checks"}
Truth table100%2/2
A
A= $self->{"checks"}
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 26 | $self->set_reduction($reduction); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 25 | $self->SUPER::init(); | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | sub name { '<CHECK-SET>' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | ▶ | sub operator { $_[0]->{+_REDUCTION} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
operator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | sub reduction { $_[0]->{+_REDUCTION} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reduction: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 176 | my %VALID = (any => 1, all => 1, none => 1); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 45 | ▶ | sub set_reduction { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_reduction: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 45 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 45 | my ($redu) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | croak "'$redu' is not a valid set reduction" | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 45 | ▶ | unless $VALID{$redu}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 43 | $self->{+_REDUCTION} = $redu; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 23 | ▶ | sub verify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 23 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 23 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 23 | ▶ | sub add_check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_check: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 23 | push @{$self->{+CHECKS}} => @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 36 | ▶ | sub deltas { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deltas: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 36 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 36 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 36 | my $checks = $self->{+CHECKS}; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 36 | my $reduction = $self->{+_REDUCTION}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 36 | my $convert = $params{convert}; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 36 | ▶ | unless ($checks && @$checks) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$checks and @$checks
MC/DC100%2/2
$checks and @$checks
$checks
@$checks
Truth table100%3/3
A and B
A= $checksB= @$checks
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 8 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 8 | my $lines = $self->lines; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 8 | my $extra = ""; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | ▶ | if ($file and $lines and @$lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$file and $lines and @$lines
$file and $lines
MC/DC66%2/3
$file and $lines and @$lines
$file
$lines
@$lines
Truth table75%3/4
A and B and C
A= $fileB= $linesC= @$lines
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | my $lns = (@$lines > 1 ? 'lines ' : 'line ' ) . join ', ', @$lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | $extra = " (Set defined in $file $lns)"; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | die "No checks defined for set$extra\n"; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 28 | my @deltas; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 28 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 28 | for my $check (@$checks) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | 64 | my $c = $convert->($check); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 64 | my $id = [META => "Check " . $i++]; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 64 | my @d = $c->run(%params, id => $id); | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 64 | ▶ | if ($reduction eq 'any') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 31 | ▶ | return () unless @d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 19 | push @deltas => @d; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | elsif ($reduction eq 'all') { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 22 | push @deltas => @d; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | elsif ($reduction eq 'none') { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | push @deltas => Test2::Compare::Delta->new( | ||||||||||||||||||||||||||||||||||||||||||
| 91 | verified => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | got => $params{got}, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 11 | ▶ | check => $c, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | ) unless @d; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | die "Invalid reduction: $reduction\n"; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 16 | return @deltas; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 176 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||||||||||||||||