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: "ModPerl::Reg‐
16       istry", "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           create the class's object, bless it and return it
34
35             my $obj = $class->new($r);
36
37           $class -- the registry class, usually "__PACKAGE__" can be used.
38
39           $r -- "Apache2::Request" object.
40
41           default: new()
42
43       * init()
44           initializes the data object's fields: "REQ", "FILENAME", "URI".
45           Called from the new().
46
47           default: init()
48
49       * default_handler()
50           default:  default_handler()
51
52       * run()
53           default: run()
54
55       * can_compile()
56           default: can_compile()
57
58       * make_namespace()
59           default: make_namespace()
60
61       * namespace_root()
62           default: namespace_root()
63
64       * namespace_from()
65           If "namespace_from_uri" is used and the script is called from the
66           virtual host, by default the virtual host name is prepended to the
67           uri when package name for the compiled script is created. Sometimes
68           this behavior is undesirable, e.g., when the same (physical) script
69           is accessed using the same path_info but different virtual hosts.
70           In that case you can make the script compiled only once for all
71           vhosts, by specifying:
72
73             $ModPerl::RegistryCooker::NameWithVirtualHost = 0;
74
75           The drawback is that it affects the global environment and all
76           other scripts will be compiled ignoring virtual hosts.
77
78           default: namespace_from()
79
80       * is_cached()
81           default: is_cached()
82
83       * should_compile()
84           default: should_compile()
85
86       * flush_namespace()
87           default: flush_namespace()
88
89       * cache_table()
90           default: cache_table()
91
92       * cache_it()
93           default: cache_it()
94
95       * read_script()
96           default: read_script()
97
98       * shebang_to_perl()
99           default: shebang_to_perl()
100
101       * get_script_name()
102           default: get_script_name()
103
104       * chdir_file()
105           default: chdir_file()
106
107       * get_mark_line()
108           default: get_mark_line()
109
110       * compile()
111           default: compile()
112
113       * error_check()
114           default: error_check()
115
116       * strip_end_data_segment()
117           default: strip_end_data_segment()
118
119       * convert_script_to_compiled_handler()
120           default: convert_script_to_compiled_handler()
121
122       Special Predefined Functions
123
124       The following functions are implemented as constants.
125
126       * NOP()
127           Use when the function shouldn't do anything.
128
129       * TRUE()
130           Use when a function should always return a true value.
131
132       * FALSE()
133           Use when a function should always return a false value.
134

Sub-classing Techniques

136       To override the default "ModPerl::RegistryCooker" methods, first, sub-
137       class "ModPerl::RegistryCooker" or one of its existing sub-classes,
138       using "use base". Second, override the methods.
139
140       Those methods that weren't overridden will be resolved at run time when
141       used for the first time and cached for the future requests. One way to
142       to shortcut this first run resolution is to use the symbol aliasing
143       feature. For example to alias "ModPerl::MyRegistry::flush_namespace" as
144       "ModPerl::RegistryCooker::flush_namespace", you can do:
145
146         package ModPerl::MyRegistry;
147         use base qw(ModPerl::RegistryCooker);
148         *ModPerl::MyRegistry::flush_namespace =
149             \&ModPerl::RegistryCooker::flush_namespace;
150         1;
151
152       In fact, it's a good idea to explicitly alias all the methods so you
153       know exactly what functions are used, rather then relying on the
154       defaults. For that purpose "ModPerl::RegistryCooker" class method
155       install_aliases() can be used. Simply prepare a hash with method names
156       in the current package as keys and corresponding fully qualified meth‐
157       ods to be aliased for as values and pass it to install_aliases(). Con‐
158       tinuing our example we could do:
159
160         package ModPerl::MyRegistry;
161         use base qw(ModPerl::RegistryCooker);
162         my %aliases = (
163             flush_namespace => 'ModPerl::RegistryCooker::flush_namespace',
164         );
165         __PACKAGE__->install_aliases(\%aliases);
166         1;
167
168       The values use fully qualified packages so you can mix methods from
169       different classes.
170

Examples

172       The best examples are existing core registry modules: "ModPerl::Reg‐
173       istry", "ModPerl::Registry" and "ModPerl::RegistryBB". Look at the
174       source code and their manpages to see how they subclass "ModPerl::Reg‐
175       istryCooker".
176
177       For example by default "ModPerl::Registry" uses the script's path when
178       creating a package's namespace. If for example you want to use a uri
179       instead you can override it with:
180
181         *ModPerl::MyRegistry::namespace_from =
182             \&ModPerl::RegistryCooker::namespace_from_uri;
183         1;
184
185       Since the "namespace_from_uri" component already exists in "Mod‐
186       Perl::RegistryCooker". If you want to write your own method, e.g., that
187       creates a namespace based on the inode, you can do:
188
189         sub namespace_from_inode {
190             my $self = shift;
191             return (stat $self->[FILENAME])[1];
192         }
193
194       META: when $r->finfo will be ported it'll be more effecient.  (stat
195       $r->finfo)[1]
196

Authors

198       Doug MacEachern
199
200       Stas Bekman
201

See Also

203       "ModPerl::Registry", "ModPerl::RegistryBB" and "ModPerl::PerlRun".
204
205
206
207perl v5.8.8                       2006-11-d1o9cs::api::ModPerl::RegistryCooker(3)
Impressum