1TAP::Parser::IteratorFaUcsteorryC(o3n)tributed Perl DocuTmAePn:t:aPtairosner::IteratorFactory(3)
2
3
4
6 TAP::Parser::IteratorFactory - Figures out which SourceHandler objects
7 to use for a given Source
8
10 Version 3.42
11
13 use TAP::Parser::IteratorFactory;
14 my $factory = TAP::Parser::IteratorFactory->new({ %config });
15 my $iterator = $factory->make_iterator( $filename );
16
18 This is a factory class that takes a TAP::Parser::Source and runs it
19 through all the registered TAP::Parser::SourceHandlers to see which one
20 should handle the source.
21
22 If you're a plugin author, you'll be interested in how to
23 "register_handler"s, how "detect_source" works.
24
26 Class Methods
27 "new"
28
29 Creates a new factory class:
30
31 my $sf = TAP::Parser::IteratorFactory->new( $config );
32
33 $config is optional. If given, sets "config" and calls
34 "load_handlers".
35
36 "register_handler"
37
38 Registers a new TAP::Parser::SourceHandler with this factory.
39
40 __PACKAGE__->register_handler( $handler_class );
41
42 "handlers"
43
44 List of handlers that have been registered.
45
46 Instance Methods
47 "config"
48
49 my $cfg = $sf->config;
50 $sf->config({ Perl => { %config } });
51
52 Chaining getter/setter for the configuration of the available source
53 handlers. This is a hashref keyed on handler class whose values
54 contain config to be passed onto the handlers during detection &
55 creation. Class names may be fully qualified or abbreviated, eg:
56
57 # these are equivalent
58 $sf->config({ 'TAP::Parser::SourceHandler::Perl' => { %config } });
59 $sf->config({ 'Perl' => { %config } });
60
61 "load_handlers"
62
63 $sf->load_handlers;
64
65 Loads the handler classes defined in "config". For example, given a
66 config:
67
68 $sf->config({
69 MySourceHandler => { some => 'config' },
70 });
71
72 "load_handlers" will attempt to load the "MySourceHandler" class by
73 looking in @INC for it in this order:
74
75 TAP::Parser::SourceHandler::MySourceHandler
76 MySourceHandler
77
78 "croak"s on error.
79
80 "make_iterator"
81
82 my $iterator = $src_factory->make_iterator( $source );
83
84 Given a TAP::Parser::Source, finds the most suitable
85 TAP::Parser::SourceHandler to use to create a TAP::Parser::Iterator
86 (see "detect_source"). Dies on error.
87
88 "detect_source"
89
90 Given a TAP::Parser::Source, detects what kind of source it is and
91 returns one TAP::Parser::SourceHandler (the most confident one). Dies
92 on error.
93
94 The detection algorithm works something like this:
95
96 for (@registered_handlers) {
97 # ask them how confident they are about handling this source
98 $confidence{$handler} = $handler->can_handle( $source )
99 }
100 # choose the most confident handler
101
102 Ties are handled by choosing the first handler.
103
105 Please see "SUBCLASSING" in TAP::Parser for a subclassing overview.
106
107 Example
108 If we've done things right, you'll probably want to write a new source,
109 rather than sub-classing this (see TAP::Parser::SourceHandler for
110 that).
111
112 But in case you find the need to...
113
114 package MyIteratorFactory;
115
116 use strict;
117
118 use base 'TAP::Parser::IteratorFactory';
119
120 # override source detection algorithm
121 sub detect_source {
122 my ($self, $raw_source_ref, $meta) = @_;
123 # do detective work, using $meta and whatever else...
124 }
125
126 1;
127
129 Steve Purkis
130
132 Originally ripped off from Test::Harness.
133
134 Moved out of TAP::Parser & converted to a factory class to support
135 extensible TAP source detective work by Steve Purkis.
136
138 TAP::Object, TAP::Parser, TAP::Parser::SourceHandler,
139 TAP::Parser::SourceHandler::File, TAP::Parser::SourceHandler::Perl,
140 TAP::Parser::SourceHandler::RawTAP, TAP::Parser::SourceHandler::Handle,
141 TAP::Parser::SourceHandler::Executable
142
143
144
145perl v5.32.1 2021-01-27 TAP::Parser::IteratorFactory(3)