<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Test2::Compare::OrderedSubset;
use strict;
use warnings;

use base 'Test2::Compare::Base';

our $VERSION = '0.000162';

use Test2::Util::HashBase qw/inref items/;

use Carp qw/croak/;
use Scalar::Util qw/reftype/;

sub init {
    my $self = shift;

    if(my $ref = $self-&gt;{+INREF}) {
        croak "Cannot specify both 'inref' and 'items'" if $self-&gt;{+ITEMS};
        croak "'inref' must be an array reference, got '$ref'" unless reftype($ref) eq 'ARRAY';
        $self-&gt;{+ITEMS} = [@{$self-&gt;{+INREF}}];
    }

    $self-&gt;{+ITEMS} ||= [];

    $self-&gt;SUPER::init();
}

sub name { '&lt;ORDERED SUBSET&gt;' }

sub verify {
    my $self = shift;
    my %params = @_;

    return 0 unless $params{exists};
    defined( my $got = $params{got} ) || return 0;
    return 0 unless ref($got);
    return 0 unless reftype($got) eq 'ARRAY';
    return 1;
}

sub add_item {
    my $self = shift;
    my $check = pop;

    push @{$self-&gt;{+ITEMS}} =&gt; $check;
}

sub deltas {
    my $self = shift;
    my %params = @_;
    my ($got, $convert, $seen) = @params{qw/got convert seen/};

    my @deltas;
    my $state = 0;
    my $items = $self-&gt;{+ITEMS};

    my $idx = 0;

    for my $item (@$items) {
        my $check = $convert-&gt;($item);

        my $i = $idx;
        my $found;
        while($i &lt; @$got) {
            my $val = $got-&gt;[$i++];
            next if $check-&gt;run(
                id      =&gt; [ARRAY =&gt; $i],
                convert =&gt; $convert,
                seen    =&gt; $seen,
                exists  =&gt; 1,
                got     =&gt; $val,
            );

            $idx = $i;
            $found++;
            last;
        }

        next if $found;

        push @deltas =&gt; Test2::Compare::Delta-&gt;new(
            verified =&gt; 0,
            id       =&gt; ['ARRAY', '?'],
            check    =&gt; $check,
            dne      =&gt; 'got',
        );
    }

    return @deltas;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Test2::Compare::OrderedSubset - Internal representation of an ordered subset.

=head1 DESCRIPTION

This module is used to ensure an array has all the expected items int he
expected order. It ignores any unexpected items mixed into the array. It only
cares that all the expected values are present, and in order, everything else
is noise.

=head1 METHODS

=over 4

=item $ref = $arr-&gt;inref()

If the instance was constructed from an actual array, this will have the
reference to that array.

=item $arrayref = $arr-&gt;items()

=item $arr-&gt;set_items($arrayref)

All the expected items, in order.

=item $name = $arr-&gt;name()

Always returns the string C&lt;&lt; "&lt;ORDERED SUBSET&gt;" &gt;&gt;.

=item $bool = $arr-&gt;verify(got =&gt; $got, exists =&gt; $bool)

Check if C&lt;$got&gt; is an array reference or not.

=item $arr-&gt;add_item($item)

Add an item to the list of values to check.

=item @deltas = $arr-&gt;deltas(got =&gt; $got, convert =&gt; \&amp;convert, seen =&gt; \%seen)

Find the differences between the expected array values and those in the C&lt;$got&gt;
arrayref.

=back

=head1 SOURCE

The source code repository for Test2-Suite can be found at
F&lt;https://github.com/Test-More/Test2-Suite/&gt;.

=head1 MAINTAINERS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 AUTHORS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 COPYRIGHT

Copyright 2018 Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

See F&lt;http://dev.perl.org/licenses/&gt;

=cut
</pre></body></html>