# perldoc > TAP::Parser::Multiplexer

---
type: CommandReference
command: TAP::Parser::Multiplexer
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `my $mux = TAP::Parser::Multiplexer->new` — create a new multiplexer
- `$mux->add($parser, $stash)` — add a parser with optional stash
- `my ($parser, $stash, $result) = $mux->next` — get next result from any parser
- `$mux->parsers` — returns number of parsers (decrements as parsers are exhausted)
- When `$result` is undef, that parser is exhausted; when all parsers exhausted, `next` returns empty list.

## Name

Multiplex multiple TAP::Parsers

## Synopsis

perl
use TAP::Parser::Multiplexer;

my $mux = TAP::Parser::Multiplexer->new;
$mux->add( $parser1, $stash1 );
$mux->add( $parser2, $stash2 );
while ( my ( $parser, $stash, $result ) = $mux->next ) {
    # do stuff
}
## Description

TAP::Parser::Multiplexer gathers input from multiple TAP::Parsers. Internally it calls `select` on the input file handles for those parsers to wait for one or more of them to have input available. See [TAP::Harness](https://perldoc.perl.org/TAP::Harness) for an example of its use.

## Methods

### Class Methods

- `new` — `my $mux = TAP::Parser::Multiplexer->new;` Returns a new multiplexer object.

### Instance Methods

- `add($parser, $stash)` — Add a [TAP::Parser](https://perldoc.perl.org/TAP::Parser) to the multiplexer. `$stash` is an optional opaque reference that will be returned from `next` along with the parser and the next result.

- `parsers` — `my $count = $mux->parsers;` Returns the number of parsers. Parsers are removed from the multiplexer when their input is exhausted.

- `next` — Return a result from the next available parser. Returns a list containing the parser, the stash, and the result. If `$result` is undefined, the corresponding parser has reached the end of its input (and will automatically be removed). When all parsers are exhausted, an empty list is returned.

perl
if ( my ( $parser, $stash, $result ) = $mux->next ) {
    if ( ! defined $result ) {
        # End of this parser
    }
    else {
        # Process result
    }
}
else {
    # All parsers finished
}
## See Also

- [TAP::Parser](https://perldoc.perl.org/TAP::Parser)
- [TAP::Harness](https://perldoc.perl.org/TAP::Harness)