| 1 | package Test2::Compare::OrderedSubset; | ||||||||||||
| 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/inref items/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 176 | ▶ | use Carp qw/croak/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 176 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 38 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 15 | 38 | my $self = shift; | |||||||||||
| 16 | |||||||||||||
| 17 | 38 | ▶ | if(my $ref = $self->{+INREF}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 18 | 3 | ▶ | croak "Cannot specify both 'inref' and 'items'" if $self->{+ITEMS}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | 3 | ▶ | croak "'inref' must be an array reference, got '$ref'" unless reftype($ref) eq 'ARRAY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 2 | $self->{+ITEMS} = [@{$self->{+INREF}}]; | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | 37 | ▶ | $self->{+ITEMS} ||= []; | ||||||||||
|
Condition100%2/2
$self->{"items"} ||= []
MC/DC100%1/1
$self->{"items"} ||= []
$self->{"items"}
Truth table100%2/2
A
A= $self->{"items"}
| |||||||||||||
| 24 | |||||||||||||
| 25 | 37 | $self->SUPER::init(); | |||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | 1 | ▶ | sub name { '<ORDERED SUBSET>' } | ||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 29 | |||||||||||||
| 30 | 38 | ▶ | sub verify { | ||||||||||
|
Subroutine
verify: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||
| 31 | 38 | my $self = shift; | |||||||||||
| 32 | 38 | my %params = @_; | |||||||||||
| 33 | |||||||||||||
| 34 | 38 | ▶ | return 0 unless $params{exists}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 37 | ▶ | defined( my $got = $params{got} ) || return 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | 36 | ▶ | return 0 unless ref($got); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 33 | ▶ | return 0 unless reftype($got) eq 'ARRAY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 32 | return 1; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 53 | ▶ | sub add_item { | ||||||||||
|
Subroutine
add_item: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 42 | 53 | my $self = shift; | |||||||||||
| 43 | 53 | my $check = pop; | |||||||||||
| 44 | |||||||||||||
| 45 | 53 | push @{$self->{+ITEMS}} => $check; | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 35 | ▶ | sub deltas { | ||||||||||
|
Subroutine
deltas: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||
| 49 | 35 | my $self = shift; | |||||||||||
| 50 | 35 | my %params = @_; | |||||||||||
| 51 | 35 | my ($got, $convert, $seen) = @params{qw/got convert seen/}; | |||||||||||
| 52 | |||||||||||||
| 53 | 35 | my @deltas; | |||||||||||
| 54 | 35 | my $state = 0; | |||||||||||
| 55 | 35 | my $items = $self->{+ITEMS}; | |||||||||||
| 56 | |||||||||||||
| 57 | 35 | my $idx = 0; | |||||||||||
| 58 | |||||||||||||
| 59 | 35 | for my $item (@$items) { | |||||||||||
| 60 | 56 | my $check = $convert->($item); | |||||||||||
| 61 | |||||||||||||
| 62 | 56 | my $i = $idx; | |||||||||||
| 63 | 56 | my $found; | |||||||||||
| 64 | 56 | ▶ | while($i < @$got) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 57 | my $val = $got->[$i++]; | |||||||||||
| 66 | 57 | ▶ | next if $check->run( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | id => [ARRAY => $i], | ||||||||||||
| 68 | convert => $convert, | ||||||||||||
| 69 | seen => $seen, | ||||||||||||
| 70 | exists => 1, | ||||||||||||
| 71 | got => $val, | ||||||||||||
| 72 | ); | ||||||||||||
| 73 | |||||||||||||
| 74 | 54 | $idx = $i; | |||||||||||
| 75 | 54 | $found++; | |||||||||||
| 76 | 54 | last; | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | 56 | ▶ | next if $found; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | |||||||||||||
| 81 | 2 | push @deltas => Test2::Compare::Delta->new( | |||||||||||
| 82 | verified => 0, | ||||||||||||
| 83 | id => ['ARRAY', '?'], | ||||||||||||
| 84 | check => $check, | ||||||||||||
| 85 | dne => 'got', | ||||||||||||
| 86 | ); | ||||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 35 | return @deltas; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 176 | 1; | |||||||||||
| 93 | |||||||||||||
| 94 | __END__ | ||||||||||||