TAP::Pa...Handler(3pm)
okay bestie, welcome to the TAP::Parser::SourceHandler(3pm) page โ from the Perl Programmers Reference Guide. The header squeezes the name down to TAP::Pa...Handler(3pm) because terminal columns are rude ๐
. This is the abstract base class page, and weโre gonna get through it together, fr fr.
๐ธ NAME ๐ธ
TAP::Parser::SourceHandler โ Base class for different TAP source handlers. ๐
๐ VERSION ๐
Version 3.50 โ periodt.
โจ SYNOPSIS โจ
# abstract class - don't use directly!
# see TAP::Parser::IteratorFactory for general usage
# must be sub-classed for use
package MySourceHandler;
use base 'TAP::Parser::SourceHandler';
sub can_handle { return $confidence_level }
sub make_iterator { return $iterator }
# see example below for more details
๐ฆ DESCRIPTION ๐ฆ
This is an abstract base class for TAP::Parser::Source handlers / handlers. (Yes, it says โhandlers / handlersโ โ we keep the lore exact, bestie ๐.)
A TAP::Parser::SourceHandler does whatever is necessary to produce & capture a stream of TAP from the raw source, and package it up in a TAP::Parser::Iterator for the parser to consume. Obsessed with that pipeline, honestly.
SourceHandlers must implement the source detection & handling interface used by TAP::Parser::IteratorFactory. At 2 methods, the interface is pretty simple: can_handle and make_source. (Thatโs what the page says, and weโre not editing the source material, iykyk.)
Unless youโre writing a new TAP::Parser::SourceHandler, a plugin, or subclassing TAP::Parser, you probably wonโt need to use this module directly. Lowkey a โfor builders onlyโ vibe.
๐ฅ METHODS ๐ฅ
๐ Class Methods ๐
can_handle
Abstract method. No cap.
my $vote = $class->can_handle( $source );
$source is a TAP::Parser::Source.
Returns a number between 0 & 1 reflecting how confidently the raw source can be handled. For example, 0 means the source cannot handle it, 0.5 means it may be able to, and 1 means it definitely can. See "detect_source" in TAP::Parser::IteratorFactory for details on how this is used. The confidence scale is giving very โrate me from 0 to 1โ energy ๐
.
make_iterator
Abstract method. Another one, bestie.
my $iterator = $class->make_iterator( $source );
$source is a TAP::Parser::Source.
Returns a new TAP::Parser::Iterator object for use by the TAP::Parser. It "croak"s on error โ so if it goes sideways, it croaks, dramatic but valid ๐ญ.
๐ SUBCLASSING ๐
Please see "SUBCLASSING" in TAP::Parser for a subclassing overview, and any of the subclasses that ship with this module as an example. What follows is a quick overview. ๐ซถ
Start by familiarizing yourself with TAP::Parser::Source and TAP::Parser::IteratorFactory. TAP::Parser::SourceHandler::RawTAP is the easiest sub-class to use as an example.
Itโs important to point out that if you want your subclass to be automatically used by TAP::Parser youโll have to โ and make sure it gets loaded somehow. If youโre using prove you can write an App::Prove plugin. If youโre using TAP::Parser or TAP::Harness directly (e.g. through a custom script, ExtUtils::MakeMaker, or Module::Build) you can use the "config" option which will cause "load_sources" in TAP::Parser::IteratorFactory to load your subclass. Yes, thatโs a whole lot of module names โ main character energy for build tooling, honestly.
Donโt forget to register your class with "register_handler" in TAP::Parser::IteratorFactory.
Example
This is the example from the page โ code stays exact, obviously ๐:
package MySourceHandler;
use strict;
use MySourceHandler; # see TAP::Parser::SourceHandler
use TAP::Parser::IteratorFactory;
use base 'TAP::Parser::SourceHandler';
TAP::Parser::IteratorFactory->register_handler( __PACKAGE__ );
sub can_handle {
my ( $class, $src ) = @_;
my $meta = $src->meta;
my $config = $src->config_for( $class );
if ($config->{accept_all}) {
return 1.0;
} elsif (my $file = $meta->{file}) {
return 0.0 unless $file->{exists};
return 1.0 if $file->{lc_ext} eq '.tap';
return 0.9 if $file->{shebang} && $file->{shebang} =~ /^#!.+tap/;
return 0.5 if $file->{text};
return 0.1 if $file->{binary};
} elsif ($meta->{scalar}) {
return 0.8 if $$raw_source_ref =~ /\d\.\.\d/;
return 0.6 if $meta->{has_newlines};
} elsif ($meta->{array}) {
return 0.8 if $meta->{size} < 5;
return 0.6 if $raw_source_ref->[0] =~ /foo/;
return 0.5;
} elsif ($meta->{hash}) {
return 0.6 if $raw_source_ref->{foo};
return 0.2;
}
return 0;
}
sub make_iterator {
my ($class, $source) = @_;
# this is where you manipulate the source and
# capture the stream of TAP in an iterator
# either pick a TAP::Parser::Iterator::* or write your own...
my $iterator = TAP::Parser::Iterator::Array->new([ 'foo', 'bar' ]);
return $iterator;
}
1;
๐ AUTHORS ๐
TAPx Developers.- Source detection stuff added by Steve Purkis
โญ SEE ALSO โญ
TAP::ObjectTAP::ParserTAP::Parser::SourceTAP::Parser::IteratorTAP::Parser::IteratorFactoryTAP::Parser::SourceHandler::ExecutableTAP::Parser::SourceHandler::PerlTAP::Parser::SourceHandler::FileTAP::Parser::SourceHandler::HandleTAP::Parser::SourceHandler::RawTAP
Thatโs the whole page, bestie ๐. It comes from perl v5.42.3, dated 2026-11-03 โ mwah, go build something iconic ๐ซถโจ.
๐ฆ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms