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::Object
  • TAP::Parser
  • TAP::Parser::SourceHandler
  • TAP::Parser::SourceHandler::File
  • TAP::Parser::SourceHandler::Perl
  • TAP::Parser::SourceHandler::RawTAP
  • TAP::Parser::SourceHandler::Handle
  • TAP::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