1TAP::Parser::ResultFactUosreyr(3C)ontributed Perl DocumeTnAtPa:t:iPoanrser::ResultFactory(3)
2
3
4
6 TAP::Parser::ResultFactory - Factory for creating TAP::Parser output
7 objects
8
10 use TAP::Parser::ResultFactory;
11 my $token = {...};
12 my $factory = TAP::Parser::ResultFactory->new;
13 my $result = $factory->make_result( $token );
14
16 Version 3.42
17
18 DESCRIPTION
19 This is a simple factory class which returns a TAP::Parser::Result
20 subclass representing the current bit of test data from TAP (usually a
21 single line). It is used primarily by TAP::Parser::Grammar. Unless
22 you're subclassing, you probably won't need to use this module
23 directly.
24
25 METHODS
26 Class Methods
27 "new"
28
29 Creates a new factory class. Note: You currently don't need to
30 instantiate a factory in order to use it.
31
32 "make_result"
33
34 Returns an instance the appropriate class for the test token passed in.
35
36 my $result = TAP::Parser::ResultFactory->make_result($token);
37
38 Can also be called as an instance method.
39
40 "class_for"
41
42 Takes one argument: $type. Returns the class for this $type, or
43 "croak"s with an error.
44
45 "register_type"
46
47 Takes two arguments: $type, $class
48
49 This lets you override an existing type with your own custom type, or
50 register a completely new type, eg:
51
52 # create a custom result type:
53 package MyResult;
54 use strict;
55 use base 'TAP::Parser::Result';
56
57 # register with the factory:
58 TAP::Parser::ResultFactory->register_type( 'my_type' => __PACKAGE__ );
59
60 # use it:
61 my $r = TAP::Parser::ResultFactory->( { type => 'my_type' } );
62
63 Your custom type should then be picked up automatically by the
64 TAP::Parser.
65
67 Please see "SUBCLASSING" in TAP::Parser for a subclassing overview.
68
69 There are a few things to bear in mind when creating your own
70 "ResultFactory":
71
72 1. The factory itself is never instantiated (this may change in the
73 future). This means that "_initialize" is never called.
74
75 2. "TAP::Parser::Result->new" is never called, $tokens are reblessed.
76 This will change in a future version!
77
78 3. TAP::Parser::Result subclasses will register themselves with
79 TAP::Parser::ResultFactory directly:
80
81 package MyFooResult;
82 TAP::Parser::ResultFactory->register_type( foo => __PACKAGE__ );
83
84 Of course, it's up to you to decide whether or not to ignore them.
85
86 Example
87 package MyResultFactory;
88
89 use strict;
90
91 use MyResult;
92
93 use base 'TAP::Parser::ResultFactory';
94
95 # force all results to be 'MyResult'
96 sub class_for {
97 return 'MyResult';
98 }
99
100 1;
101
103 TAP::Parser, TAP::Parser::Result, TAP::Parser::Grammar
104
105
106
107perl v5.30.1 2020-01-30 TAP::Parser::ResultFactory(3)