TAP::P...actory(3perl)
π NAME π
TAP::Parser::IteratorFactory β ok so bestie, this one figures out which SourceHandler objects to use for a given Source. That's literally the whole job. It's the matchmaker of the TAP::Parser world. π
β¨ VERSION β¨
Version 3.52. Slay. Not a drill.
πΈ SYNOPSIS πΈ
use TAP::Parser::IteratorFactory;
my $factory = TAP::Parser::IteratorFactory->new({ %config });
my $iterator = $factory->make_iterator( $filename );
That's it. That's the vibe. You build a factory, you ask it for an iterator, it handles the rest. π¦
π DESCRIPTION π
Okay so picture this: it's a factory class. You hand it a TAP::Parser::Source, and it runs that source through all the registered TAP::Parser::SourceHandlers to see which one should handle the source. Like a casting call but for source handlers. π
And if you're a plugin author?? Omg. You are going to be so interested in how to register_handler and how detect_source works. That's your whole lore. β¨
π₯ METHODS π₯
β Class Methods β
π new
Creates a new factory class, iconic behaviour:
my $sf = TAP::Parser::IteratorFactory->new( $config );
$config is optional, ngl. If given, it sets config and calls load_handlers. That's it, that's the constructor. π
π¦ register_handler
Registers a new TAP::Parser::SourceHandler with this factory. Giving it a little home.
__PACKAGE__->register_handler( $handler_class );
π handlers
List of handlers that have been registered. Justβ¦ the list. The roster. The squad. π«Ά
π Instance Methods π
π config
my $cfg = $sf->config;
$sf->config({ Perl => { %config } });
Chaining getter/setter for the configuration of the available source handlers. It's a hashref keyed on handler class, and the values contain config to be passed onto the handlers during detection & creation. β¨
Class names may be fully qualified or abbreviated, bestie:
# these are equivalent
$sf->config({ 'TAP::Parser::SourceHandler::Perl' => { %config } });
$sf->config({ 'Perl' => { %config } });
Look at that. Same thing. No cap. π
π§ load_handlers
$sf->load_handlers;
Loads the handler classes defined in config. So for example, given a config like:
$sf->config({
MySourceHandler => { some => 'config' },
});
load_handlers will attempt to load the MySourceHandler class by looking in @INC for it, and it checks in this order:
TAP::Parser::SourceHandler::MySourceHandler
MySourceHandler
It croaks on error. Like, it will yell at you. π«
π make_iterator
my $iterator = $src_factory->make_iterator( $source );
Given a TAP::Parser::Source, it finds the most suitable TAP::Parser::SourceHandler to use to create a TAP::Parser::Iterator (see detect_source). Dies on error. Periodt. π
π detect_source
Given a TAP::Parser::Source, this detects what kind of source it is and returns one TAP::Parser::SourceHandler β the most confident one. Dies on error. π
The detection algorithm works something like this:
for (@registered_handlers) {
# ask them how confident they are about handling this source
$confidence{$handler} = $handler->can_handle( $source )
}
# choose the most confident handler
Ties are handled by choosing the first handler. First come, first served, main character energy. π
π SUBCLASSING π
Please see SUBCLASSING in TAP::Parser for a subclassing overview. Go read it, it's giving required reading. π
πΈ Example πΈ
If we've done things right, you'll probably want to write a new source, rather than sub-classing this (see TAP::Parser::SourceHandler for that). That's the intended path, bestie. π«Ά
But in case you find the need toβ¦
package MyIteratorFactory;
use strict;
use base 'TAP::Parser::IteratorFactory';
# override source detection algorithm
sub detect_source {
my ($self, $raw_source_ref, $meta) = @_;
# do detective work, using $meta and whatever else...
}
1;
Do the detective work. Get the magnifying glass out. πβ¨
π AUTHORS π
Steve Purkis. The icon. The moment. The blueprint. π
β ATTRIBUTION β
Originally ripped off from Test::Harness. π
Moved out of TAP::Parser & converted to a factory class to support extensible TAP source detective work by Steve Purkis. That's the origin story and honestly? We love it here. π
π¦ SEE ALSO π¦
TAP::ObjectTAP::ParserTAP::Parser::SourceHandlerTAP::Parser::SourceHandler::FileTAP::Parser::SourceHandler::PerlTAP::Parser::SourceHandler::RawTAPTAP::Parser::SourceHandler::HandleTAP::Parser::SourceHandler::Executable
Go read all of them, they're a whole friend group. π«Ά
okay bye bestie, that's the page!! this was TAP::P...actory from the Perl Programmers Reference Guide, perl v5.44.0, dated 2026-10-17 β bookmark it, screenshot it, put it on your fridge. πβ¨ππ¦πΈπ
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms