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

our $VERSION = '0.000162';

use Test2::Workflow::Task::Group;

our @BUILD_FIELDS;

BEGIN {
    @BUILD_FIELDS = qw{
        primary         variant
        setup           teardown
        variant_setup   variant_teardown
        primary_setup   primary_teardown
        stash
    };
}

use base 'Test2::Workflow::Task';
use Test2::Util::HashBase @BUILD_FIELDS, qw/events defaults stack_stop/;

sub init {
    my $self = shift;

    {
        local $Carp::CarpLevel = $Carp::CarpLevel + 1;
        $self-&gt;SUPER::init();
    }

    $self-&gt;{$_} ||= [] for @BUILD_FIELDS;
    $self-&gt;{+DEFAULTS} ||= {};
}

for my $field (@BUILD_FIELDS) {
    my $code = sub {
        my $self = shift;
        push @{$self-&gt;{$field}} =&gt; @_;
    };
    no strict 'refs';
    *{"add_$field"} = $code;
}

sub populated {
    my $self = shift;
    for my $field (@BUILD_FIELDS) {
        return 1 if @{$self-&gt;{$field}};
    }
    return 0;
}

sub compile {
    my $self = shift;

    warn "Workflow build '$self-&gt;{+NAME}' is empty " . $self-&gt;debug . "\n"
        unless $self-&gt;populated || $self-&gt;{+SKIP};

    my ($primary_setup, $primary_teardown) = @_;
    $primary_setup    ||= [];
    $primary_teardown ||= [];

    my $variant          = $self-&gt;{+VARIANT};
    my $setup            = $self-&gt;{+SETUP};
    my $teardown         = $self-&gt;{+TEARDOWN};
    my $variant_setup    = $self-&gt;{+VARIANT_SETUP};
    my $variant_teardown = $self-&gt;{+VARIANT_TEARDOWN};

    $primary_setup = [@$primary_setup, @{$self-&gt;{+PRIMARY_SETUP}}];
    $primary_teardown = [@{$self-&gt;{+PRIMARY_TEARDOWN}}, @$primary_teardown];

    # Get primaries in order.
    my $primary = [
        map {
            $_-&gt;isa(__PACKAGE__)
                ? $_-&gt;compile($primary_setup, $primary_teardown)
                : $_;
        } @{$self-&gt;{+PRIMARY}},
    ];

    if (@$primary_setup || @$primary_teardown) {
        $primary = [
            map {
                my $p = $_-&gt;clone;
                $_-&gt;isa('Test2::Workflow::Task::Action') ? Test2::Workflow::Task::Group-&gt;new(
                    before  =&gt; $primary_setup,
                    primary =&gt; [ $p ],
                    take    =&gt; $p,
                    after   =&gt; $primary_teardown,
                ) : $_;
            } @$primary
        ];
    }

    # Build variants
    if (@$variant) {
        $primary = [
            map {
                my $v = $_-&gt;clone;
                Test2::Workflow::Task::Group-&gt;new(
                    before  =&gt; $variant_setup,
                    primary =&gt; $primary,
                    after   =&gt; $variant_teardown,
                    variant =&gt; $v,
                    take    =&gt; $v,
                );
            } @$variant
        ];
    }

    my %params = map { Test2::Workflow::Task::Group-&gt;can($_) ? ($_ =&gt; $self-&gt;{$_}) : () } keys %$self;
    delete $params{$_} for @BUILD_FIELDS;

    return Test2::Workflow::Task::Group-&gt;new(
        %params,
        before  =&gt; $setup,
        after   =&gt; $teardown,
        primary =&gt; $primary,
    );
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Test2::Workflow::Build - Represents a build in progress.

=head1 SOURCE

The source code repository for Test2-Workflow 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;exodist7@gmail.comE&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>