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

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

our $VERSION = '0.000162';

use Test2::Util::HashBase qw/checks _reduction/;

use Test2::Compare::Delta();

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

sub init {
    my $self = shift;

    my $reduction = delete $self-&gt;{reduction} || 'any';

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

    $self-&gt;set_reduction($reduction);

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

sub name      { '&lt;CHECK-SET&gt;' }
sub operator  { $_[0]-&gt;{+_REDUCTION} }
sub reduction { $_[0]-&gt;{+_REDUCTION} }

my %VALID = (any =&gt; 1, all =&gt; 1, none =&gt; 1);
sub set_reduction {
    my $self = shift;
    my ($redu) = @_;

    croak "'$redu' is not a valid set reduction"
        unless $VALID{$redu};

    $self-&gt;{+_REDUCTION} = $redu;
}

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

sub add_check {
    my $self = shift;
    push @{$self-&gt;{+CHECKS}} =&gt; @_;
}

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

    my $checks    = $self-&gt;{+CHECKS};
    my $reduction = $self-&gt;{+_REDUCTION};
    my $convert   = $params{convert};

    unless ($checks &amp;&amp; @$checks) {
        my $file = $self-&gt;file;
        my $lines = $self-&gt;lines;

        my $extra = "";
        if ($file and $lines and @$lines) {
            my $lns = (@$lines &gt; 1 ? 'lines ' : 'line ' ) .  join ', ', @$lines;
            $extra = " (Set defined in $file $lns)";
        }

        die "No checks defined for set$extra\n";
    }

    my @deltas;
    my $i = 0;
    for my $check (@$checks) {
        my $c = $convert-&gt;($check);
        my $id = [META =&gt; "Check " . $i++];
        my @d = $c-&gt;run(%params, id =&gt; $id);

        if ($reduction eq 'any') {
            return () unless @d;
            push @deltas =&gt; @d;
        }
        elsif ($reduction eq 'all') {
            push @deltas =&gt; @d;
        }
        elsif ($reduction eq 'none') {
            push @deltas =&gt; Test2::Compare::Delta-&gt;new(
                verified =&gt; 0,
                id       =&gt; $id,
                got      =&gt; $params{got},
                check    =&gt; $c,
            ) unless @d;
        }
        else {
            die "Invalid reduction: $reduction\n";
        }
    }

    return @deltas;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Test2::Compare::Set - Allows a field to be matched against a set of
checks.

=head1 DESCRIPTION

This module is used by the C&lt;check_set&gt; function in the
L&lt;Test2::Tools::Compare&gt; plugin.

=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>