| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "TAP::Parser::IteratorFactory 3perl" |
| 58 |
.TH TAP::Parser::IteratorFactory 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
TAP::Parser::IteratorFactory \- Figures out which SourceHandler objects to use for a given Source |
| 65 |
.SH VERSION |
| 66 |
.IX Header "VERSION" |
| 67 |
Version 3.48 |
| 68 |
.SH SYNOPSIS |
| 69 |
.IX Header "SYNOPSIS" |
| 70 |
.Vb 3 |
| 71 |
\& use TAP::Parser::IteratorFactory; |
| 72 |
\& my $factory = TAP::Parser::IteratorFactory\->new({ %config }); |
| 73 |
\& my $iterator = $factory\->make_iterator( $filename ); |
| 74 |
.Ve |
| 75 |
.SH DESCRIPTION |
| 76 |
.IX Header "DESCRIPTION" |
| 77 |
This is a factory class that takes a TAP::Parser::Source and runs it through all the |
| 78 |
registered TAP::Parser::SourceHandlers to see which one should handle the source. |
| 79 |
.PP |
| 80 |
If you're a plugin author, you'll be interested in how to "register_handler"s, |
| 81 |
how "detect_source" works. |
| 82 |
.SH METHODS |
| 83 |
.IX Header "METHODS" |
| 84 |
.SS "Class Methods" |
| 85 |
.IX Subsection "Class Methods" |
| 86 |
\fR\f(CI\*(C`new\*(C'\fR\fI\fR |
| 87 |
.IX Subsection "new" |
| 88 |
.PP |
| 89 |
Creates a new factory class: |
| 90 |
.PP |
| 91 |
.Vb 1 |
| 92 |
\& my $sf = TAP::Parser::IteratorFactory\->new( $config ); |
| 93 |
.Ve |
| 94 |
.PP |
| 95 |
\&\f(CW$config\fR is optional. If given, sets "config" and calls "load_handlers". |
| 96 |
.PP |
| 97 |
\fR\f(CI\*(C`register_handler\*(C'\fR\fI\fR |
| 98 |
.IX Subsection "register_handler" |
| 99 |
.PP |
| 100 |
Registers a new TAP::Parser::SourceHandler with this factory. |
| 101 |
.PP |
| 102 |
.Vb 1 |
| 103 |
\& _\|_PACKAGE_\|_\->register_handler( $handler_class ); |
| 104 |
.Ve |
| 105 |
.PP |
| 106 |
\fR\f(CI\*(C`handlers\*(C'\fR\fI\fR |
| 107 |
.IX Subsection "handlers" |
| 108 |
.PP |
| 109 |
List of handlers that have been registered. |
| 110 |
.SS "Instance Methods" |
| 111 |
.IX Subsection "Instance Methods" |
| 112 |
\fR\f(CI\*(C`config\*(C'\fR\fI\fR |
| 113 |
.IX Subsection "config" |
| 114 |
.PP |
| 115 |
.Vb 2 |
| 116 |
\& my $cfg = $sf\->config; |
| 117 |
\& $sf\->config({ Perl => { %config } }); |
| 118 |
.Ve |
| 119 |
.PP |
| 120 |
Chaining getter/setter for the configuration of the available source handlers. |
| 121 |
This is a hashref keyed on handler class whose values contain config to be passed |
| 122 |
onto the handlers during detection & creation. Class names may be fully qualified |
| 123 |
or abbreviated, eg: |
| 124 |
.PP |
| 125 |
.Vb 3 |
| 126 |
\& # these are equivalent |
| 127 |
\& $sf\->config({ \*(AqTAP::Parser::SourceHandler::Perl\*(Aq => { %config } }); |
| 128 |
\& $sf\->config({ \*(AqPerl\*(Aq => { %config } }); |
| 129 |
.Ve |
| 130 |
.PP |
| 131 |
\fR\f(CI\*(C`load_handlers\*(C'\fR\fI\fR |
| 132 |
.IX Subsection "load_handlers" |
| 133 |
.PP |
| 134 |
.Vb 1 |
| 135 |
\& $sf\->load_handlers; |
| 136 |
.Ve |
| 137 |
.PP |
| 138 |
Loads the handler classes defined in "config". For example, given a config: |
| 139 |
.PP |
| 140 |
.Vb 3 |
| 141 |
\& $sf\->config({ |
| 142 |
\& MySourceHandler => { some => \*(Aqconfig\*(Aq }, |
| 143 |
\& }); |
| 144 |
.Ve |
| 145 |
.PP |
| 146 |
\&\f(CW\*(C`load_handlers\*(C'\fR will attempt to load the \f(CW\*(C`MySourceHandler\*(C'\fR class by looking in |
| 147 |
\&\f(CW@INC\fR for it in this order: |
| 148 |
.PP |
| 149 |
.Vb 2 |
| 150 |
\& TAP::Parser::SourceHandler::MySourceHandler |
| 151 |
\& MySourceHandler |
| 152 |
.Ve |
| 153 |
.PP |
| 154 |
\&\f(CW\*(C`croak\*(C'\fRs on error. |
| 155 |
.PP |
| 156 |
\fR\f(CI\*(C`make_iterator\*(C'\fR\fI\fR |
| 157 |
.IX Subsection "make_iterator" |
| 158 |
.PP |
| 159 |
.Vb 1 |
| 160 |
\& my $iterator = $src_factory\->make_iterator( $source ); |
| 161 |
.Ve |
| 162 |
.PP |
| 163 |
Given a TAP::Parser::Source, finds the most suitable TAP::Parser::SourceHandler |
| 164 |
to use to create a TAP::Parser::Iterator (see "detect_source"). Dies on error. |
| 165 |
.PP |
| 166 |
\fR\f(CI\*(C`detect_source\*(C'\fR\fI\fR |
| 167 |
.IX Subsection "detect_source" |
| 168 |
.PP |
| 169 |
Given a TAP::Parser::Source, detects what kind of source it is and |
| 170 |
returns \fIone\fR TAP::Parser::SourceHandler (the most confident one). Dies |
| 171 |
on error. |
| 172 |
.PP |
| 173 |
The detection algorithm works something like this: |
| 174 |
.PP |
| 175 |
.Vb 5 |
| 176 |
\& for (@registered_handlers) { |
| 177 |
\& # ask them how confident they are about handling this source |
| 178 |
\& $confidence{$handler} = $handler\->can_handle( $source ) |
| 179 |
\& } |
| 180 |
\& # choose the most confident handler |
| 181 |
.Ve |
| 182 |
.PP |
| 183 |
Ties are handled by choosing the first handler. |
| 184 |
.SH SUBCLASSING |
| 185 |
.IX Header "SUBCLASSING" |
| 186 |
Please see "SUBCLASSING" in TAP::Parser for a subclassing overview. |
| 187 |
.SS Example |
| 188 |
.IX Subsection "Example" |
| 189 |
If we've done things right, you'll probably want to write a new source, |
| 190 |
rather than sub-classing this (see TAP::Parser::SourceHandler for that). |
| 191 |
.PP |
| 192 |
But in case you find the need to... |
| 193 |
.PP |
| 194 |
.Vb 1 |
| 195 |
\& package MyIteratorFactory; |
| 196 |
\& |
| 197 |
\& use strict; |
| 198 |
\& |
| 199 |
\& use base \*(AqTAP::Parser::IteratorFactory\*(Aq; |
| 200 |
\& |
| 201 |
\& # override source detection algorithm |
| 202 |
\& sub detect_source { |
| 203 |
\& my ($self, $raw_source_ref, $meta) = @_; |
| 204 |
\& # do detective work, using $meta and whatever else... |
| 205 |
\& } |
| 206 |
\& |
| 207 |
\& 1; |
| 208 |
.Ve |
| 209 |
.SH AUTHORS |
| 210 |
.IX Header "AUTHORS" |
| 211 |
Steve Purkis |
| 212 |
.SH ATTRIBUTION |
| 213 |
.IX Header "ATTRIBUTION" |
| 214 |
Originally ripped off from Test::Harness. |
| 215 |
.PP |
| 216 |
Moved out of TAP::Parser & converted to a factory class to support |
| 217 |
extensible TAP source detective work by Steve Purkis. |
| 218 |
.SH "SEE ALSO" |
| 219 |
.IX Header "SEE ALSO" |
| 220 |
TAP::Object, |
| 221 |
TAP::Parser, |
| 222 |
TAP::Parser::SourceHandler, |
| 223 |
TAP::Parser::SourceHandler::File, |
| 224 |
TAP::Parser::SourceHandler::Perl, |
| 225 |
TAP::Parser::SourceHandler::RawTAP, |
| 226 |
TAP::Parser::SourceHandler::Handle, |
| 227 |
TAP::Parser::SourceHandler::Executable |