<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package TAP::Formatter::Console::ParallelSession;

use strict;
use warnings;
use File::Spec;
use File::Path;
use Carp;

use base 'TAP::Formatter::Console::Session';

use constant WIDTH =&gt; 72;    # Because Eric says

my %shared;

sub _initialize {
    my ( $self, $arg_for ) = @_;

    $self-&gt;SUPER::_initialize($arg_for);
    my $formatter = $self-&gt;formatter;

    # Horrid bodge. This creates our shared context per harness. Maybe
    # TAP::Harness should give us this?
    my $context = $shared{$formatter} ||= $self-&gt;_create_shared_context;
    push @{ $context-&gt;{active} }, $self;

    return $self;
}

sub _create_shared_context {
    my $self = shift;
    return {
        active =&gt; [],
        tests  =&gt; 0,
        fails  =&gt; 0,
    };
}

=head1 NAME

TAP::Formatter::Console::ParallelSession - Harness output delegate for parallel console output

=head1 VERSION

Version 3.44

=cut

our $VERSION = '3.44';

=head1 DESCRIPTION

This provides console orientated output formatting for L&lt;TAP::Harness&gt;
when run with multiple L&lt;TAP::Harness/jobs&gt;.

=head1 SYNOPSIS

=cut

=head1 METHODS

=head2 Class Methods

=head3 C&lt;header&gt;

Output test preamble

=cut

sub header {
}

sub _clear_ruler {
    my $self = shift;
    $self-&gt;formatter-&gt;_output( "\r" . ( ' ' x WIDTH ) . "\r" );
}

my $now = 0;
my $start;

my $trailer     = '... )===';
my $chop_length = WIDTH - length $trailer;

sub _output_ruler {
    my ( $self, $refresh ) = @_;
    my $new_now = time;
    return if $new_now == $now and !$refresh;
    $now = $new_now;
    $start ||= $now;
    my $formatter = $self-&gt;formatter;
    return if $formatter-&gt;really_quiet;

    my $context = $shared{$formatter};

    my $ruler = sprintf '===( %7d;%d  ', $context-&gt;{tests}, $now - $start;

    for my $active ( @{ $context-&gt;{active} } ) {
        my $parser  = $active-&gt;parser;
        my $tests   = $parser-&gt;tests_run;
        my $planned = $parser-&gt;tests_planned || '?';

        $ruler .= sprintf '%' . length($planned) . "d/$planned  ", $tests;
    }
    chop $ruler;    # Remove a trailing space
    $ruler .= ')===';

    if ( length $ruler &gt; WIDTH ) {
        $ruler =~ s/(.{$chop_length}).*/$1$trailer/o;
    }
    else {
        $ruler .= '=' x ( WIDTH - length($ruler) );
    }
    $formatter-&gt;_output("\r$ruler");
}

=head3 C&lt;result&gt;

  Called by the harness for each line of TAP it receives .

=cut

sub result {
    my ( $self, $result ) = @_;
    my $formatter = $self-&gt;formatter;

    # my $really_quiet = $formatter-&gt;really_quiet;
    # my $show_count   = $self-&gt;_should_show_count;

    if ( $result-&gt;is_test ) {
        my $context = $shared{$formatter};
        $context-&gt;{tests}++;

        my $active = $context-&gt;{active};
        if ( @$active == 1 ) {

            # There is only one test, so use the serial output format.
            return $self-&gt;SUPER::result($result);
        }

        $self-&gt;_output_ruler( $self-&gt;parser-&gt;tests_run == 1 );
    }
    elsif ( $result-&gt;is_bailout ) {
        $formatter-&gt;_failure_output(
                "Bailout called.  Further testing stopped:  "
              . $result-&gt;explanation
              . "\n" );
    }
}

=head3 C&lt;clear_for_close&gt;

=cut

sub clear_for_close {
    my $self      = shift;
    my $formatter = $self-&gt;formatter;
    return if $formatter-&gt;really_quiet;
    my $context = $shared{$formatter};
    if ( @{ $context-&gt;{active} } == 1 ) {
        $self-&gt;SUPER::clear_for_close;
    }
    else {
        $self-&gt;_clear_ruler;
    }
}

=head3 C&lt;close_test&gt;

=cut

sub close_test {
    my $self      = shift;
    my $name      = $self-&gt;name;
    my $parser    = $self-&gt;parser;
    my $formatter = $self-&gt;formatter;
    my $context   = $shared{$formatter};

    $self-&gt;SUPER::close_test;

    my $active = $context-&gt;{active};

    my @pos = grep { $active-&gt;[$_]-&gt;name eq $name } 0 .. $#$active;

    die "Can't find myself" unless @pos;
    splice @$active, $pos[0], 1;

    if ( @$active &gt; 1 ) {
        $self-&gt;_output_ruler(1);
    }
    elsif ( @$active == 1 ) {

        # Print out "test/name.t ...."
        $active-&gt;[0]-&gt;SUPER::header;
    }
    else {

        # $self-&gt;formatter-&gt;_output("\n");
        delete $shared{$formatter};
    }
}

1;
</pre></body></html>