TAP::P...actory(3perl)

🌸 NAME 🌸

TAP::Parser::ResultFactory β€” the factory for creating TAP::Parser output objects, bestie. It's TAP::P...actory(3perl) from the Perl Programmers Reference Guide, and she's here to hand out result objects like party favors πŸ’–


✨ SYNOPSIS ✨

use TAP::Parser::ResultFactory;
my $token   = {...};
my $factory = TAP::Parser::ResultFactory->new;
my $result  = $factory->make_result( $token );

Like. That's it. That's the whole vibe. πŸ¦‹


πŸ’– VERSION πŸ’–

Version 3.52. Slay. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so this is a simple factory class, and what it does is return a TAP::Parser::Result subclass that represents the current little bit of test data from TAP β€” and usually that's just a single line, no cap. πŸ“

It's used primarily by TAP::Parser::Grammar, which is giving main character energy in this whole setup tbh. And unless you're subclassing, you probably won't need to use this module directly β€” like, she's the backstage crew, not the performer. But she ate regardless. πŸ’…


πŸ’… METHODS πŸ’…

🫢 Class Methods 🫢

new

Creates a new factory class. new said "I'm baby" πŸŽ€

Note: you currently don't need to instantiate a factory in order to use it. Fr fr. The class methods just work. It's giving low-maintenance queen.

make_result

Returns an instance the appropriate class for the test token passed in. (Yes, that's the original wording, keep up 😭) Like, you give her a token, she gives you back the right result class:

my $result = TAP::Parser::ResultFactory->make_result($token);

Can also be called as an instance method β€” so both flavors are valid, and she's flexible like that. 🧚

class_for

Takes one argument: $type. Returns the class for this $type, or croaks with an error. So if you hand her a type she doesn't recognize? She will literally croak at you. Not a drill. πŸ’€

register_type

Takes two arguments: $type, $class.

This lets you override an existing type with your own custom type, or register a completely new type, eg:

# create a custom result type:
package MyResult;
use strict;
use base 'TAP::Parser::Result';

# register with the factory:
TAP::Parser::ResultFactory->register_type( 'my_type' => __PACKAGE__ );

# use it:
my $r = TAP::Parser::ResultFactory->( { type => 'my_type' } );

Your custom type should then be picked up automatically by the TAP::Parser. No extra steps, she just knows. ✨


🌈 SUBCLASSING 🌈

Please see "SUBCLASSING" in TAP::Parser for a subclassing overview β€” go read that, I'll wait. πŸ“

There are a few things to bear in mind when creating your own "ResultFactory":

  1. The factory itself is never instantiated (this may change in the future). This means that "_initialize" is never called. So don't go looking for it, she's not coming. πŸ™ˆ
  2. "TAP::Parser::Result->new" is never called, $tokens are reblessed. This will change in a future version! So like, heads up for future-you. ⚠️
  3. TAP::Parser::Result subclasses will register themselves with TAP::Parser::ResultFactory directly:
package MyFooResult;
TAP::Parser::ResultFactory->register_type( foo => __PACKAGE__ );

Of course, it's up to you to decide whether or not to ignore them. Your call, your rules, your kingdom. πŸ‘‘

πŸŽ€ Example πŸŽ€

package MyResultFactory;

use strict;

use MyResult;

use base 'TAP::Parser::ResultFactory';

# force all results to be 'MyResult'
sub class_for {
  return 'MyResult';
}

1;

Look at her. Forcing every single result to be MyResult. That's main character energy and honestly? Respect. πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘

  • TAP::Parser
  • TAP::Parser::Result
  • TAP::Parser::Grammar

Okay bestie, that's the whole page β€” every flag, every method, every caveat, not one crumb left behind. 🫢 This was TAP::P...actory(3perl) from perl v5.44.0, dated 2026-10-17. Mwah, periodt. πŸ’…βœ¨

πŸ“¦ 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