1TAP::Parser::IteratorFaUcsteorryC(o3n)tributed Perl DocuTmAePn:t:aPtairosner::IteratorFactory(3)
2
3
4

NAME

6       TAP::Parser::IteratorFactory - Figures out which SourceHandler objects
7       to use for a given Source
8

VERSION

10       Version 3.28
11

SYNOPSIS

13         use TAP::Parser::IteratorFactory;
14         my $factory = TAP::Parser::IteratorFactory->new({ %config });
15         my $iterator  = $factory->make_iterator( $filename );
16

DESCRIPTION

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

METHODS

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

SUBCLASSING

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         use vars '@ISA';
118
119         use TAP::Parser::IteratorFactory;
120
121         @ISA = qw( TAP::Parser::IteratorFactory );
122
123         # override source detection algorithm
124         sub detect_source {
125           my ($self, $raw_source_ref, $meta) = @_;
126           # do detective work, using $meta and whatever else...
127         }
128
129         1;
130

AUTHORS

132       Steve Purkis
133

ATTRIBUTION

135       Originally ripped off from Test::Harness.
136
137       Moved out of TAP::Parser & converted to a factory class to support
138       extensible TAP source detective work by Steve Purkis.
139

SEE ALSO

141       TAP::Object, TAP::Parser, TAP::Parser::SourceHandler,
142       TAP::Parser::SourceHandler::File, TAP::Parser::SourceHandler::Perl,
143       TAP::Parser::SourceHandler::RawTAP, TAP::Parser::SourceHandler::Handle,
144       TAP::Parser::SourceHandler::Executable
145
146
147
148perl v5.16.3                      2013-05-02   TAP::Parser::IteratorFactory(3)
Impressum