Debian Codegraph @

upstream/mageia-cauldron/man3pm/TAP::Parser::IteratorFactory.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "TAP::Parser::IteratorFactory 3pm"
61 .TH TAP::Parser::IteratorFactory 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 TAP::Parser::IteratorFactory \- Figures out which SourceHandler objects to use for a given Source
68 .SH VERSION
69 .IX Header "VERSION"
70 Version 3.50
71 .SH SYNOPSIS
72 .IX Header "SYNOPSIS"
73 .Vb 3
74 \& use TAP::Parser::IteratorFactory;
75 \& my $factory = TAP::Parser::IteratorFactory\->new({ %config });
76 \& my $iterator = $factory\->make_iterator( $filename );
77 .Ve
78 .SH DESCRIPTION
79 .IX Header "DESCRIPTION"
80 This is a factory class that takes a TAP::Parser::Source and runs it through all the
81 registered TAP::Parser::SourceHandlers to see which one should handle the source.
82 .PP
83 If you\*(Aqre a plugin author, you\*(Aqll be interested in how to "register_handler"s,
84 how "detect_source" works.
85 .SH METHODS
86 .IX Header "METHODS"
87 .SS "Class Methods"
88 .IX Subsection "Class Methods"
89 \fR\f(CI\*(C`new\*(C'\fR\fI\fR
90 .IX Subsection "new"
91 .PP
92 Creates a new factory class:
93 .PP
94 .Vb 1
95 \& my $sf = TAP::Parser::IteratorFactory\->new( $config );
96 .Ve
97 .PP
98 \&\f(CW$config\fR is optional. If given, sets "config" and calls "load_handlers".
99 .PP
100 \fR\f(CI\*(C`register_handler\*(C'\fR\fI\fR
101 .IX Subsection "register_handler"
102 .PP
103 Registers a new TAP::Parser::SourceHandler with this factory.
104 .PP
105 .Vb 1
106 \& _\|_PACKAGE_\|_\->register_handler( $handler_class );
107 .Ve
108 .PP
109 \fR\f(CI\*(C`handlers\*(C'\fR\fI\fR
110 .IX Subsection "handlers"
111 .PP
112 List of handlers that have been registered.
113 .SS "Instance Methods"
114 .IX Subsection "Instance Methods"
115 \fR\f(CI\*(C`config\*(C'\fR\fI\fR
116 .IX Subsection "config"
117 .PP
118 .Vb 2
119 \& my $cfg = $sf\->config;
120 \& $sf\->config({ Perl => { %config } });
121 .Ve
122 .PP
123 Chaining getter/setter for the configuration of the available source handlers.
124 This is a hashref keyed on handler class whose values contain config to be passed
125 onto the handlers during detection & creation. Class names may be fully qualified
126 or abbreviated, eg:
127 .PP
128 .Vb 3
129 \& # these are equivalent
130 \& $sf\->config({ \*(AqTAP::Parser::SourceHandler::Perl\*(Aq => { %config } });
131 \& $sf\->config({ \*(AqPerl\*(Aq => { %config } });
132 .Ve
133 .PP
134 \fR\f(CI\*(C`load_handlers\*(C'\fR\fI\fR
135 .IX Subsection "load_handlers"
136 .PP
137 .Vb 1
138 \& $sf\->load_handlers;
139 .Ve
140 .PP
141 Loads the handler classes defined in "config". For example, given a config:
142 .PP
143 .Vb 3
144 \& $sf\->config({
145 \& MySourceHandler => { some => \*(Aqconfig\*(Aq },
146 \& });
147 .Ve
148 .PP
149 \&\f(CW\*(C`load_handlers\*(C'\fR will attempt to load the \f(CW\*(C`MySourceHandler\*(C'\fR class by looking in
150 \&\f(CW@INC\fR for it in this order:
151 .PP
152 .Vb 2
153 \& TAP::Parser::SourceHandler::MySourceHandler
154 \& MySourceHandler
155 .Ve
156 .PP
157 \&\f(CW\*(C`croak\*(C'\fRs on error.
158 .PP
159 \fR\f(CI\*(C`make_iterator\*(C'\fR\fI\fR
160 .IX Subsection "make_iterator"
161 .PP
162 .Vb 1
163 \& my $iterator = $src_factory\->make_iterator( $source );
164 .Ve
165 .PP
166 Given a TAP::Parser::Source, finds the most suitable TAP::Parser::SourceHandler
167 to use to create a TAP::Parser::Iterator (see "detect_source"). Dies on error.
168 .PP
169 \fR\f(CI\*(C`detect_source\*(C'\fR\fI\fR
170 .IX Subsection "detect_source"
171 .PP
172 Given a TAP::Parser::Source, detects what kind of source it is and
173 returns \fIone\fR TAP::Parser::SourceHandler (the most confident one). Dies
174 on error.
175 .PP
176 The detection algorithm works something like this:
177 .PP
178 .Vb 5
179 \& for (@registered_handlers) {
180 \& # ask them how confident they are about handling this source
181 \& $confidence{$handler} = $handler\->can_handle( $source )
182 \& }
183 \& # choose the most confident handler
184 .Ve
185 .PP
186 Ties are handled by choosing the first handler.
187 .SH SUBCLASSING
188 .IX Header "SUBCLASSING"
189 Please see "SUBCLASSING" in TAP::Parser for a subclassing overview.
190 .SS Example
191 .IX Subsection "Example"
192 If we\*(Aqve done things right, you\*(Aqll probably want to write a new source,
193 rather than sub\-classing this (see TAP::Parser::SourceHandler for that).
194 .PP
195 But in case you find the need to...
196 .PP
197 .Vb 1
198 \& package MyIteratorFactory;
199 \&
200 \& use strict;
201 \&
202 \& use base \*(AqTAP::Parser::IteratorFactory\*(Aq;
203 \&
204 \& # override source detection algorithm
205 \& sub detect_source {
206 \& my ($self, $raw_source_ref, $meta) = @_;
207 \& # do detective work, using $meta and whatever else...
208 \& }
209 \&
210 \& 1;
211 .Ve
212 .SH AUTHORS
213 .IX Header "AUTHORS"
214 Steve Purkis
215 .SH ATTRIBUTION
216 .IX Header "ATTRIBUTION"
217 Originally ripped off from Test::Harness.
218 .PP
219 Moved out of TAP::Parser & converted to a factory class to support
220 extensible TAP source detective work by Steve Purkis.
221 .SH "SEE ALSO"
222 .IX Header "SEE ALSO"
223 TAP::Object,
224 TAP::Parser,
225 TAP::Parser::SourceHandler,
226 TAP::Parser::SourceHandler::File,
227 TAP::Parser::SourceHandler::Perl,
228 TAP::Parser::SourceHandler::RawTAP,
229 TAP::Parser::SourceHandler::Handle,
230 TAP::Parser::SourceHandler::Executable