| 1 | package Test2::Compare::Bag; | ||||||||||||||||||||||||||||
| 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/ending meta items for_each/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 176 | ▶ | use Carp qw/croak confess/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 176 | ▶ | use Scalar::Util qw/reftype looks_like_number/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 442 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 442 | my $self = shift; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 442 | ▶ | $self->{+ITEMS} ||= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"items"} ||= []
MC/DC100%1/1
$self->{"items"} ||= []
$self->{"items"}
Truth table100%2/2
A
A= $self->{"items"}
| |||||||||||||||||||||||||||||
| 18 | 442 | ▶ | $self->{+FOR_EACH} ||= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"for_each"} ||= []
MC/DC0%0/1
$self->{"for_each"} ||= []
$self->{"for_each"}
Truth table50%1/2
A
A= $self->{"for_each"}
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 442 | $self->SUPER::init(); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | ▶ | sub name { '<BAG>' } | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | sub meta_class { 'Test2::Compare::Meta' } | ||||||||||||||||||||||||||
|
Subroutine
meta_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 450 | ▶ | sub verify { | ||||||||||||||||||||||||||
|
Subroutine
verify: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 450 | my $self = shift; | |||||||||||||||||||||||||||
| 29 | 450 | my %params = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 450 | ▶ | return 0 unless $params{exists}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 449 | ▶ | my $got = $params{got} || return 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$params{'got'} || (return 0)
MC/DC100%1/1
$params{'got'} || (return 0)
$params{'got'}
Truth table100%2/2
A
A= $params{'got'}
| |||||||||||||||||||||||||||||
| 33 | 446 | ▶ | return 0 unless ref($got); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 442 | ▶ | return 0 unless reftype($got) eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 440 | return 1; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | ▶ | sub add_prop { | ||||||||||||||||||||||||||
|
Subroutine
add_prop: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 4 | ▶ | $self->{+META} = $self->meta_class->new unless defined $self->{+META}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 4 | $self->{+META}->add_prop(@_); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1351 | ▶ | sub add_item { | ||||||||||||||||||||||||||
|
Subroutine
add_item: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 1351 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | 1351 | my $check = pop; | |||||||||||||||||||||||||||
| 47 | 1351 | my ($idx) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1351 | push @{$self->{+ITEMS}}, $check; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 10 | ▶ | sub add_for_each { | ||||||||||||||||||||||||||
|
Subroutine
add_for_each: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 54 | 10 | push @{$self->{+FOR_EACH}} => @_; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 436 | ▶ | sub verify_build { | ||||||||||||||||||||||||||
|
Subroutine
verify_build: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 436 | my $self = shift; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 436 | ▶ | return unless @{$self->{+FOR_EACH}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 10 | ▶ | return unless $self->{+ENDING}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 5 | ▶ | return if @{$self->{+ITEMS}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | $self->throw_build_error("'end' with no items specified requires an empty bag, which discards the 'all_items' checks; use 'etc' instead of 'end' to check every item without bounding the bag"); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 448 | ▶ | sub deltas { | ||||||||||||||||||||||||||
|
Subroutine
deltas: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 448 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | 448 | my %params = @_; | |||||||||||||||||||||||||||
| 70 | 448 | my ($got, $convert, $seen) = @params{qw/got convert seen/}; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 448 | my @deltas; | |||||||||||||||||||||||||||
| 73 | 448 | my $state = 0; | |||||||||||||||||||||||||||
| 74 | 448 | my @items = @{$self->{+ITEMS}}; | |||||||||||||||||||||||||||
| 75 | 448 | my @for_each = @{$self->{+FOR_EACH}}; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Make a copy that we can munge as needed. | ||||||||||||||||||||||||||||
| 78 | 448 | my @list = @$got; | |||||||||||||||||||||||||||
| 79 | 448 | my %unmatched = map { $_ => $list[$_] } 0..$#list; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 448 | my $meta = $self->{+META}; | |||||||||||||||||||||||||||
| 82 | 448 | ▶ | push @deltas => $meta->deltas(%params) if defined $meta; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 448 | ▶ | while (@items) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 1380 | my $item = shift @items; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1380 | my $check = $convert->($item); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1380 | my $match = 0; | |||||||||||||||||||||||||||
| 90 | 1380 | for my $idx (0..$#list) { | |||||||||||||||||||||||||||
| 91 | 4923 | ▶ | next unless exists $unmatched{$idx}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 3378 | my $val = $list[$idx]; | |||||||||||||||||||||||||||
| 93 | 3378 | my $deltas = $check->run( | |||||||||||||||||||||||||||
| 94 | id => [ARRAY => $idx], | ||||||||||||||||||||||||||||
| 95 | convert => $convert, | ||||||||||||||||||||||||||||
| 96 | seen => $seen, | ||||||||||||||||||||||||||||
| 97 | exists => 1, | ||||||||||||||||||||||||||||
| 98 | got => $val, | ||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 3378 | ▶ | unless ($deltas) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 1370 | $match++; | |||||||||||||||||||||||||||
| 103 | 1370 | delete $unmatched{$idx}; | |||||||||||||||||||||||||||
| 104 | 1370 | last; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 1380 | ▶ | unless ($match) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 10 | push @deltas => $self->delta_class->new( | |||||||||||||||||||||||||||
| 109 | dne => 'got', | ||||||||||||||||||||||||||||
| 110 | verified => undef, | ||||||||||||||||||||||||||||
| 111 | id => [ARRAY => '*'], | ||||||||||||||||||||||||||||
| 112 | got => undef, | ||||||||||||||||||||||||||||
| 113 | check => $check, | ||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 448 | ▶ | if (@for_each) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 7 | my @checks = map { $convert->($_) } @for_each; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 7 | for my $idx (0..$#list) { | |||||||||||||||||||||||||||
| 122 | 19 | my $val = $list[$idx]; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 19 | for my $check (@checks) { | |||||||||||||||||||||||||||
| 125 | 19 | push @deltas => $check->run( | |||||||||||||||||||||||||||
| 126 | id => [ARRAY => $idx], | ||||||||||||||||||||||||||||
| 127 | convert => $convert, | ||||||||||||||||||||||||||||
| 128 | seen => $seen, | ||||||||||||||||||||||||||||
| 129 | exists => 1, | ||||||||||||||||||||||||||||
| 130 | got => $val, | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # if elements are left over, and ending is true, we have a problem! | ||||||||||||||||||||||||||||
| 137 | 448 | ▶ | if($self->{+ENDING} && keys %unmatched) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"ending"} and keys %unmatched
MC/DC100%2/2
$self->{"ending"} and keys %unmatched
$self->{"ending"}
keys %unmatched
Truth table100%3/3
A and B
A= $self->{"ending"}B= keys %unmatched
| |||||||||||||||||||||||||||||
| 138 | 5 | for my $idx (sort keys %unmatched) { | |||||||||||||||||||||||||||
| 139 | 9 | my $elem = $list[$idx]; | |||||||||||||||||||||||||||
| 140 | push @deltas => $self->delta_class->new( | ||||||||||||||||||||||||||||
| 141 | dne => 'check', | ||||||||||||||||||||||||||||
| 142 | verified => undef, | ||||||||||||||||||||||||||||
| 143 | id => [ARRAY => $idx], | ||||||||||||||||||||||||||||
| 144 | got => $elem, | ||||||||||||||||||||||||||||
| 145 | check => undef, | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 9 | ▶ | $self->{+ENDING} eq 'implicit' ? (note => 'implicit end') : (), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 448 | return @deltas; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 176 | 1; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||