1docs::api::ModPerl::RegUissetrryCCoonotkreirb(u3t)ed PerdlocDso:c:uampein:t:aMtoidoPnerl::RegistryCooker(3)
2
3
4

NAME

6       ModPerl::RegistryCooker - Cook mod_perl 2.0 Registry Modules
7

Synopsis

9         # shouldn't be used as-is but sub-classed first
10         # see ModPerl::Registry for an example
11

Description

13       "ModPerl::RegistryCooker" is used to create flexible and overridable
14       registry modules which emulate mod_cgi for Perl scripts. The concepts
15       are discussed in the manpage of the following modules:
16       "ModPerl::Registry", "ModPerl::Registry" and "ModPerl::RegistryBB".
17
18       "ModPerl::RegistryCooker" has two purposes:
19
20       ·   Provide ingredients that can be used by registry sub-classes
21
22       ·   Provide a default behavior, which can be overriden in sub-classed
23
24           META: in the future this functionality may move into a separate
25           class.
26
27       Here are the current overridable methods:
28
29       META: these are all documented in RegistryCooker.pm, though not using
30       pod. please help to port these to pod and move the descriptions here.
31
32       ·   new()
33
34           create the class's object, bless it and return it
35
36             my $obj = $class->new($r);
37
38           $class -- the registry class, usually "__PACKAGE__" can be used.
39
40           $r -- "Apache2::Request" object.
41
42           default: new()
43
44       ·   init()
45
46           initializes the data object's fields: "REQ", "FILENAME", "URI".
47           Called from the new().
48
49           default: init()
50
51       ·   default_handler()
52
53           default:  default_handler()
54
55       ·   run()
56
57           default: run()
58
59       ·   can_compile()
60
61           default: can_compile()
62
63       ·   make_namespace()
64
65           default: make_namespace()
66
67       ·   namespace_root()
68
69           default: namespace_root()
70
71       ·   namespace_from()
72
73           If "namespace_from_uri" is used and the script is called from the
74           virtual host, by default the virtual host name is prepended to the
75           uri when package name for the compiled script is created. Sometimes
76           this behavior is undesirable, e.g., when the same (physical) script
77           is accessed using the same path_info but different virtual hosts.
78           In that case you can make the script compiled only once for all
79           vhosts, by specifying:
80
81             $ModPerl::RegistryCooker::NameWithVirtualHost = 0;
82
83           The drawback is that it affects the global environment and all
84           other scripts will be compiled ignoring virtual hosts.
85
86           default: namespace_from()
87
88       ·   is_cached()
89
90           default: is_cached()
91
92       ·   should_compile()
93
94           default: should_compile()
95
96       ·   flush_namespace()
97
98           default: flush_namespace()
99
100       ·   cache_table()
101
102           default: cache_table()
103
104       ·   cache_it()
105
106           default: cache_it()
107
108       ·   read_script()
109
110           default: read_script()
111
112       ·   shebang_to_perl()
113
114           default: shebang_to_perl()
115
116       ·   get_script_name()
117
118           default: get_script_name()
119
120       ·   chdir_file()
121
122           default: chdir_file()
123
124       ·   get_mark_line()
125
126           default: get_mark_line()
127
128       ·   compile()
129
130           default: compile()
131
132       ·   error_check()
133
134           default: error_check()
135
136       ·   strip_end_data_segment()
137
138           default: strip_end_data_segment()
139
140       ·   convert_script_to_compiled_handler()
141
142           default: convert_script_to_compiled_handler()
143
144   Special Predefined Functions
145       The following functions are implemented as constants.
146
147       ·   NOP()
148
149           Use when the function shouldn't do anything.
150
151       ·   TRUE()
152
153           Use when a function should always return a true value.
154
155       ·   FALSE()
156
157           Use when a function should always return a false value.
158

Sub-classing Techniques

160       To override the default "ModPerl::RegistryCooker" methods, first, sub-
161       class "ModPerl::RegistryCooker" or one of its existing sub-classes,
162       using "use base". Second, override the methods.
163
164       Those methods that weren't overridden will be resolved at run time when
165       used for the first time and cached for the future requests. One way to
166       to shortcut this first run resolution is to use the symbol aliasing
167       feature. For example to alias "ModPerl::MyRegistry::flush_namespace" as
168       "ModPerl::RegistryCooker::flush_namespace", you can do:
169
170         package ModPerl::MyRegistry;
171         use base qw(ModPerl::RegistryCooker);
172         *ModPerl::MyRegistry::flush_namespace =
173             \&ModPerl::RegistryCooker::flush_namespace;
174         1;
175
176       In fact, it's a good idea to explicitly alias all the methods so you
177       know exactly what functions are used, rather then relying on the
178       defaults. For that purpose "ModPerl::RegistryCooker" class method
179       install_aliases() can be used. Simply prepare a hash with method names
180       in the current package as keys and corresponding fully qualified
181       methods to be aliased for as values and pass it to install_aliases().
182       Continuing our example we could do:
183
184         package ModPerl::MyRegistry;
185         use base qw(ModPerl::RegistryCooker);
186         my %aliases = (
187             flush_namespace => 'ModPerl::RegistryCooker::flush_namespace',
188         );
189         __PACKAGE__->install_aliases(\%aliases);
190         1;
191
192       The values use fully qualified packages so you can mix methods from
193       different classes.
194

Examples

196       The best examples are existing core registry modules:
197       "ModPerl::Registry", "ModPerl::Registry" and "ModPerl::RegistryBB".
198       Look at the source code and their manpages to see how they subclass
199       "ModPerl::RegistryCooker".
200
201       For example by default "ModPerl::Registry" uses the script's path when
202       creating a package's namespace. If for example you want to use a uri
203       instead you can override it with:
204
205         *ModPerl::MyRegistry::namespace_from =
206             \&ModPerl::RegistryCooker::namespace_from_uri;
207         1;
208
209       Since the "namespace_from_uri" component already exists in
210       "ModPerl::RegistryCooker". If you want to write your own method, e.g.,
211       that creates a namespace based on the inode, you can do:
212
213         sub namespace_from_inode {
214             my $self = shift;
215             return (stat $self->[FILENAME])[1];
216         }
217
218       META: when $r->finfo will be ported it'll be more effecient.  (stat
219       $r->finfo)[1]
220

Authors

222       Doug MacEachern
223
224       Stas Bekman
225

See Also

227       "ModPerl::Registry", "ModPerl::RegistryBB" and "ModPerl::PerlRun".
228
229
230
231perl v5.30.0                      2019-10-d0o7cs::api::ModPerl::RegistryCooker(3)
Impressum