1HTML::Mason::Interp(3)User Contributed Perl DocumentationHTML::Mason::Interp(3)
2
3
4

NAME

6       HTML::Mason::Interp - Mason Component Interpreter
7

SYNOPSIS

9           my $i = HTML::Mason::Interp->new (data_dir=>'/usr/local/mason',
10                                             comp_root=>'/usr/local/www/htdocs/',
11                                             ...other params...);
12

DESCRIPTION

14       Interp is the Mason workhorse, executing components and routing their
15       output and errors to all the right places. In a mod_perl environment,
16       Interp objects are handed off immediately to an ApacheHandler object
17       which internally calls the Interp implementation methods. In that case
18       the only user method is the new() constructor.
19

PARAMETERS TO THE new() CONSTRUCTOR

21       autohandler_name
22           File name used for autohandlers. Default is "autohandler".  If this
23           is set to an empty string ("") then autohandlers are turned off
24           entirely.
25
26       buffer_preallocate_size
27           Number of bytes to preallocate in the output buffer for each
28           request.  Defaults to 0. Setting this to, say, your maximum page
29           size (or close to it) can reduce the number of reallocations Perl
30           performs as components add to the output buffer.
31
32       code_cache_max_size
33           Specifies the maximum number of components that should be held in
34           the in-memory code cache. The default is 'unlimited', meaning no
35           components will ever be discarded; Mason can perform certain
36           optimizations in this mode. Setting this to zero disables the code
37           cache entirely. See the code cache section of the administrator's
38           manual for further details.
39
40       comp_root
41           The component root marks the top of your component hierarchy and
42           defines how component paths are translated into real file paths.
43           For example, if your component root is /usr/local/httpd/docs, a
44           component path of /products/index.html translates to the file
45           /usr/local/httpd/docs/products/index.html.
46
47           Under Apache and CGI, comp_root defaults to the server's document
48           root. In standalone mode comp_root defaults to the current working
49           directory.
50
51           This parameter may be either a scalar or an array reference.  If it
52           is a scalar, it should be a filesystem path indicating the
53           component root. If it is an array reference, it should be of the
54           following form:
55
56            [ [ foo => '/usr/local/foo' ],
57              [ bar => '/usr/local/bar' ] ]
58
59           This is an array of two-element array references, not a hash.  The
60           "keys" for each path must be unique and their "values" must be
61           filesystem paths.  These paths will be searched in the provided
62           order whenever a component path is resolved. For example, given the
63           above component roots and a component path of /products/index.html,
64           Mason would search first for /usr/local/foo/products/index.html,
65           then for /usr/local/bar/products/index.html.
66
67           The keys are used in several ways. They help to distinguish
68           component caches and object files between different component
69           roots, and they appear in the "title()" of a component.
70
71           When you specify a single path for a component root, this is
72           actually translated into
73
74             [ [ MAIN => path ] ]
75
76           If you have turned on dynamic_comp_root, you may modify the
77           component root(s) of an interpreter between requests by calling
78           "$interp->comp_root" with a value. However, the path associated
79           with any given key may not change between requests. For example, if
80           the initial component root is
81
82            [ [ foo => '/usr/local/foo' ],
83              [ bar => '/usr/local/bar' ], ]
84
85           then it may not be changed to
86
87            [ [ foo => '/usr/local/bar' ],
88              [ bar => '/usr/local/baz' ],
89
90           but it may be changed to
91
92            [ [ foo   => '/usr/local/foo' ],
93              [ blarg => '/usr/local/blarg' ] ]
94
95           In other words, you may add or remove key/path pairs but not modify
96           an already-used key/path pair. The reason for this restriction is
97           that the interpreter maintains a component cache per key that would
98           become invalid if the associated paths were to change.
99
100       compiler
101           The Compiler object to associate with this Interpreter.  By default
102           a new object of class compiler_class will be created.
103
104       compiler_class
105           The class to use when creating a compiler. Defaults to
106           HTML::Mason::Compiler.
107
108       data_dir
109           The data directory is a writable directory that Mason uses for
110           various features and optimizations: for example, component object
111           files and data cache files. Mason will create the directory on
112           startup, if necessary, and set its permissions according to the web
113           server User/Group.
114
115           Under Apache, data_dir defaults to a directory called "mason" under
116           the Apache server root. You will need to change this on certain
117           systems that assign a high-level server root such as /usr!
118
119           In non-Apache environments, data_dir has no default. If it is left
120           unspecified, Mason will not use object files, and the default data
121           cache class will be "MemoryCache" instead of "FileCache".
122
123       dynamic_comp_root
124           True or false, defaults to false. Indicates whether the comp_root
125           can be modified on this interpreter between requests. Mason can
126           perform a few optimizations with a fixed component root, so you
127           should only set this to true if you actually need it.
128
129       escape_flags
130           A hash reference of escape flags to set for this object.  See the
131           section on the set_escape method for more details.
132
133       ignore_warnings_expr
134           Regular expression indicating which warnings to ignore when loading
135           components. Any warning that is not ignored will prevent the
136           component from being loaded and executed. For example:
137
138               ignore_warnings_expr =>
139                   'Global symbol.*requires explicit package'
140
141           If set to undef, all warnings are heeded. If set to '.', warnings
142           are turned off completely as a specially optimized case.
143
144           By default, this is set to 'Subroutine .* redefined'.  This allows
145           you to declare global subroutines inside <%once> sections and not
146           receive an error when the component is reloaded.
147
148       object_file_extension
149           Extension to add to the end of object files. Default is ".obj".
150
151       preloads
152           A list of component paths, optionally with glob wildcards, to load
153           when the interpreter initializes. e.g.
154
155               preloads => ['/foo/index.html','/bar/*.pl']
156
157           Default is the empty list.  For maximum performance, this should
158           only be used for components that are frequently viewed and rarely
159           updated.  See the preloading components section of the
160           administrator's manual for further details.
161
162           As mentioned in the developer's manual, a component's "<%once>"
163           section is executed when it is loaded.  For preloaded components,
164           this means that this section will be executed before a Mason or
165           Apache request exist, so preloading a component that uses $m or $r
166           in a "<%once>" section will fail.
167
168       request_class
169           The class to use when creating requests. Defaults to
170           HTML::Mason::Request.
171
172       resolver
173           The Resolver object to associate with this Compiler. By default a
174           new object of class resolver_class will be created.
175
176       resolver_class
177           The class to use when creating a resolver. Defaults to
178           HTML::Mason::Resolver::File.
179
180       static_source
181           True or false, default is false. When false, Mason checks the
182           timestamp of the component source file each time the component is
183           used to see if it has changed. This provides the instant feedback
184           for source changes that is expected for development.  However it
185           does entail a file stat for each component executed.
186
187           When true, Mason assumes that the component source tree is
188           unchanging: it will not check component source files to determine
189           if the memory cache or object file has expired.  This can save many
190           file stats per request. However, in order to get Mason to recognize
191           a component source change, you must flush the memory cache and
192           remove object files.  See static_source_touch_file for one easy way
193           to arrange this.
194
195           We recommend turning this mode on in your production sites if
196           possible, if performance is of any concern.
197
198       static_source_touch_file
199           Specifies a filename that Mason will check once at the beginning of
200           of every request. When the file timestamp changes, Mason will (1)
201           clear its in-memory component cache, and (2) remove object files if
202           they have not already been deleted by another process.
203
204           This provides a convenient way to implement static_source mode.
205           All you need to do is make sure that a single file gets touched
206           whenever components change. For Mason's part, checking a single
207           file at the beginning of a request is much cheaper than checking
208           every component file when static_source=0.
209
210       use_object_files
211           True or false, default is true.  Specifies whether Mason creates
212           object files to save the results of component parsing. You may want
213           to turn off object files for disk space reasons, but otherwise this
214           should be left alone.
215

ACCESSOR METHODS

217       All of the above properties have standard accessor methods of the same
218       name. Only comp_root and ignore_warnings_expr can be modified in an
219       existing interpreter; the rest are read-only.
220

ESCAPE FLAG METHODS

222       apply_escapes ($text, $flags, [more flags...])
223           This method applies a one or more escapes to a piece of text.  The
224           escapes are specified by giving their flag.  Each escape is applied
225           to the text in turn, after which the now-modified text is returned.
226
227       remove_escape ($name)
228           Given an escape name, this removes that escape from the
229           interpreter's known escapes.  If the name is not recognized, it is
230           simply ignored.
231
232       set_escape ($name => see below])
233           This method is called to add an escape flag to the list of known
234           escapes for the interpreter.  The flag may only consist of the
235           characters matching "\w" and the dash (-).  It must start with an
236           alpha character or an underscore (_).
237
238           The right hand side may be one of several things.  It can be a
239           subroutine reference.  It can also be a string match "/^\w+$/", in
240           which case it is assumed to be the name of a subroutine in the
241           "HTML::Mason::Escapes" module.  Finally, if it is a string that
242           does not match the above regex, then it is assumed to be "eval"able
243           code, which will return a subroutine reference.
244
245           When setting these with "PerlSetVar" directives in an Apache
246           configuration file, you can set them like this:
247
248             PerlSetVar  MasonEscapeFlags  "h => \&HTML::Mason::Escapes::basic_html_escape"
249             PerlSetVar  MasonEscapeFlags  "flag  => \&subroutine"
250             PerlSetVar  MasonEscapeFlags  "uc    => sub { ${$_[0]} = uc ${$_[0]}; }"
251             PerlAddVar  MasonEscapeFlags  "thing => other_thing"
252

OTHER METHODS

254       comp_exists (path)
255           Given an absolute component path, this method returns a boolean
256           value indicating whether or not a component exists for that path.
257
258       exec (comp, args...)
259           Creates a new HTML::Mason::Request object for the given comp and
260           args, and executes it. The return value is the return value of
261           comp, if any.
262
263           This is useful for running Mason outside of a web environment.  See
264           "using Mason from a standalone script" in HTML::Mason::Admin for
265           examples.
266
267           This method isn't generally useful in a mod_perl environment; see
268           subrequests instead.
269
270       flush_code_cache
271           Empties the component cache. When using Perl 5.00503 or earlier,
272           you should call this when finished with an interpreter, in order to
273           remove circular references that would prevent the interpreter from
274           being destroyed.
275
276       load (path)
277           Returns the component object corresponding to an absolute component
278           "path", or undef if none exists. Dies with an error if the
279           component fails to load because of a syntax error.
280
281       make_component (comp_source => ... )
282       make_component (comp_file => ... )
283           This method compiles Mason component source code and returns a
284           Component object.  The source may be passed in as a string in
285           "comp_source", or as a filename in "comp_file".  When using
286           "comp_file", the filename is specified as a path on the file
287           system, not as a path relative to Mason's component root (see
288           $m->fetch_comp for that).
289
290           If Mason encounters an error during processing, an exception will
291           be thrown.
292
293           Example of usage:
294
295               # Make an anonymous component
296               my $anon_comp =
297                 eval { $interp->make_component
298                          ( comp_source => '<%perl>my $name = "World";</%perl>Hello <% $name %>!' ) };
299               die $@ if $@;
300
301               $m->comp($anon_comp);
302
303       make_request (@request_params)
304           This method creates a Mason request object. The arguments to be
305           passed are the same as those for the "HTML::Mason::Request->new"
306           constructor or its relevant subclass. This method will likely only
307           be of interest to those attempting to write new handlers or to
308           subclass "HTML::Mason::Interp".  If you want to create a
309           subrequest, see subrequests instead.
310
311       purge_code_cache ()
312           Called during request execution in order to clear out the code
313           cache. Mainly useful to subclasses that may want to take some
314           custom action upon clearing the cache.
315
316       set_global ($varname, [values...])
317           This method sets a global to be used in components. "varname" is a
318           variable name, optionally preceded with a prefix ("$", "@", or
319           "%"); if the prefix is omitted then "$" is assumed. "varname" is
320           followed by a value, in the case of a scalar, or by one or more
321           values in the case of a list or hash.  For example:
322
323               # Set a global variable $dbh containing the database handle
324               $interp->set_global(dbh => DBI->connect(...));
325
326               # Set a global hash %session from a local hash
327               $interp->set_global('%session', %s);
328
329           The global is set in the package that components run in: usually
330           "HTML::Mason::Commands", although this can be overridden via the
331           in_package parameter.  The lines above, for example, are equivalent
332           to:
333
334               $HTML::Mason::Commands::dbh = DBI->connect(...);
335               %HTML::Mason::Commands::session = %s;
336
337           assuming that in_package has not been changed.
338
339           Any global that you set should also be registered with the
340           allow_globals parameter; otherwise you'll get warnings from
341           "strict".
342
343
344
345perl v5.30.1                      2020-01-30            HTML::Mason::Interp(3)
Impressum