.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mason::Interp 3pm" .TH Mason::Interp 3pm "2014-02-01" "perl v5.18.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mason::Interp \- Mason Interpreter .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 6 \& my $interp = Mason\->new( \& comp_root => \*(Aq/path/to/comps\*(Aq, \& data_dir => \*(Aq/path/to/data\*(Aq, \& ... \& ); \& my $output = $interp\->run( \*(Aq/request/path\*(Aq, foo => 5 )\->output(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Interp is the central Mason object, returned from \f(CW\*(C`Mason\->new\*(C'\fR. It is responsible for creating new requests, compiling components, and maintaining the cache of loaded components. .SH "PARAMETERS TO THE \fInew()\fP CONSTRUCTOR" .IX Header "PARAMETERS TO THE new() CONSTRUCTOR" .IP "allow_globals (varnames)" 4 .IX Item "allow_globals (varnames)" List of one or more global variable names that will be available in all components, like \f(CW$m\fR is by default. .Sp .Vb 1 \& allow_globals => [qw($dbh)] .Ve .Sp As in any programming environment, globals should be created sparingly (if at all) and only when other mechanisms (parameter passing, attributes, singletons) will not suffice. Catalyst::View::Mason2, for example, creates a \f(CW$c\fR global set to the context object in each request. .Sp Set the values of globals with set_global. .IP "autobase_names" 4 .IX Item "autobase_names" Array reference of autobase filenames to check in order when determining a component's superclass. Default is \f(CW\*(C`["Base.mp", "Base.mc"]\*(C'\fR. .IP "autoextend_request_path" 4 .IX Item "autoextend_request_path" Whether to automatically add the top level extensions (by default \*(L".mp\*(R" and \*(L".mc\*(R") to the request path when searching for a matching page component. Defaults to true. .IP "class_header" 4 .IX Item "class_header" Perl code to be added at the top of the compiled class for every component, e.g. to bring in common features or import common methods. Default is the empty string. .Sp .Vb 11 \& # Add to the top of every component class: \& # use Modern::Perl; \& # use JSON::XS qw(encode_json decode_json); \& # \& my $mason = Mason\->new( \& ... \& class_header => qq( \& use Modern::Perl; \& use JSON::XS qw(encode_json decode_json); \& ), \& ); .Ve .Sp This is used by Mason::Compilation::output_class_header. For more advanced usage you can override that method in a subclass or plugin. .IP "comp_root" 4 .IX Item "comp_root" Required. The component root marks the top of your component hierarchy and defines how component paths are translated into real file paths. For example, if your component root is \fI/usr/local/httpd/docs\fR, a component path of \&\fI/products/sales.mc\fR translates to the file \&\fI/usr/local/httpd/docs/products/sales.mc\fR. .Sp This parameter may be either a single path or an array reference of paths. If it is an array reference, the paths will be searched in the provided order whenever a component path is resolved, much like Perl's \f(CW@INC\fR. .IP "component_class_prefix" 4 .IX Item "component_class_prefix" Prefix to use in generated component classnames. Defaults to '\s-1MC\s0' plus the interpreter's count, e.g. \s-1MC0.\s0 So a component '/foo/bar' would get a classname like 'MC0::foo::bar'. .IP "data_dir" 4 .IX Item "data_dir" The data directory is a writable directory that Mason uses for various features and optimizations: for example, component object files and data cache files. Mason will create the directory on startup if necessary. .Sp Defaults to a temporary directory that will be cleaned up at process end. This will hurt performance as Mason will have to recompile components on each run. .IP "dhandler_names" 4 .IX Item "dhandler_names" Array reference of dhandler file names to check in order when resolving a top-level path. Default is \f(CW\*(C`["dhandler.mp", "dhandler.mc"]\*(C'\fR. An empty list disables this feature. .IP "index_names" 4 .IX Item "index_names" Array reference of index file names to check in order when resolving a top-level path. Default is \f(CW\*(C`["index.mp", "index.mc"]\*(C'\fR. An empty list disables this feature. .IP "no_source_line_numbers" 4 .IX Item "no_source_line_numbers" Do not put in source line number comments when generating code. Setting this to true will cause error line numbers to reflect the real object file, rather than the source component. .IP "object_file_extension" 4 .IX Item "object_file_extension" Extension to add to the end of object files. Default is \*(L".mobj\*(R". .IP "plugins" 4 .IX Item "plugins" A list of plugins and/or plugin bundles: .Sp .Vb 7 \& plugins => [ \& \*(AqOnePlugin\*(Aq, \& \*(AqAnotherPlugin\*(Aq, \& \*(Aq+My::Mason::Plugin::AThirdPlugin\*(Aq, \& \*(Aq@APluginBundle\*(Aq, \& \*(Aq\-DontLikeThisPlugin\*(Aq, \& ]); .Ve .Sp See Mason::Manual::Plugins. .IP "out_method" 4 .IX Item "out_method" Default out_method passed to each new request. .IP "pure_perl_extensions" 4 .IX Item "pure_perl_extensions" A listref of file extensions of components to be considered as pure perl (see Pure Perl Components). Default is \&\f(CW\*(C`[\*(Aq.mp\*(Aq]\*(C'\fR. If an empty list is specified, then no components will be considered pure perl. .IP "static_source" 4 .IX Item "static_source" True or false, default is false. When false, Mason checks the timestamp of the component source file each time the component is used to see if it has changed. This provides the instant feedback for source changes that is expected for development. However it does entail a file stat for each component executed. .Sp When true, Mason assumes that the component source tree is unchanging: it will not check component source files to determine if the memory cache or object file has expired. This can save many file stats per request. However, in order to get Mason to recognize a component source change, you must touch the static_source_touch_file. .Sp We recommend turning this mode on in your production sites if possible, if performance is of any concern. .IP "static_source_touch_file" 4 .IX Item "static_source_touch_file" Specifies a filename that Mason will check once at the beginning of every request when in static_source mode. When the file timestamp changes (indicating that a component has changed), Mason will clear its in-memory component cache and recheck existing object files. .IP "top_level_extensions" 4 .IX Item "top_level_extensions" A listref of file extensions of components to be considered \*(L"top level\*(R", accessible directly from \f(CW\*(C`$interp\->run\*(C'\fR or a web request. Default is \f(CW\*(C`[\*(Aq.mp\*(Aq, \*(Aq.mc\*(Aq]\*(C'\fR. If an empty list is specified, then there will be \fIno\fR restriction; that is, \fIall\fR components will be considered top level. .SH "CUSTOM MASON CLASSES" .IX Header "CUSTOM MASON CLASSES" These parameters specify alternate classes to use instead of the default Mason:: classes. .PP For example, to use your own Compilation base class: .PP .Vb 1 \& my $interp = Mason\->new(base_compilation_class => \*(AqMyApp::Mason::Compilation\*(Aq, ...); .Ve .PP Relevant plugins, if any, will applied to this class to create a final class, which you can get with .PP .Vb 1 \& $interp\->compilation_class .Ve .IP "base_code_cache_class" 4 .IX Item "base_code_cache_class" Specify alternate to Mason::CodeCache .IP "base_compilation_class" 4 .IX Item "base_compilation_class" Specify alternate to Mason::Compilation .IP "base_component_class" 4 .IX Item "base_component_class" Specify alternate to Mason::Component .IP "base_component_moose_class" 4 .IX Item "base_component_moose_class" Specify alternate to Mason::Component::Moose .IP "base_component_class_meta_class" 4 .IX Item "base_component_class_meta_class" Specify alternate to Mason::Component::ClassMeta .IP "base_component_import_class" 4 .IX Item "base_component_import_class" Specify alternate to Mason::Component::Import .IP "base_request_class" 4 .IX Item "base_request_class" Specify alternate to Mason::Request .IP "base_result_class" 4 .IX Item "base_result_class" Specify alternate to Mason::Result .SH "PUBLIC METHODS" .IX Header "PUBLIC METHODS" .IP "all_paths ([dir_path])" 4 .IX Item "all_paths ([dir_path])" Returns a list of distinct component paths under \fIdir_path\fR, which defaults to \&'/' if not provided. For example, .Sp .Vb 2 \& $interp\->all_paths(\*(Aq/foo/bar\*(Aq) \& => (\*(Aq/foo/bar/baz.mc\*(Aq, \*(Aq/foo/bar/blargh.mc\*(Aq) .Ve .Sp Note that these are all component paths, not filenames, and all component roots are searched if there are multiple ones. .IP "comp_exists (path)" 4 .IX Item "comp_exists (path)" Returns a boolean indicating whether a component exists for the absolute component \fIpath\fR. .IP "count" 4 .IX Item "count" Returns the number of this interpreter, a monotonically increasing integer for the process starting at 0. .IP "flush_code_cache" 4 .IX Item "flush_code_cache" Empties the component cache and removes all component classes. .IP "glob_paths (pattern)" 4 .IX Item "glob_paths (pattern)" Returns a list of all component paths matching the glob \fIpattern\fR. e.g. .Sp .Vb 2 \& $interp\->glob_paths(\*(Aq/foo/b*.mc\*(Aq) \& => (\*(Aq/foo/bar.mc\*(Aq, \*(Aq/foo/baz.mc\*(Aq) .Ve .Sp Note that these are all component paths, not filenames, and all component roots are searched if there are multiple ones. .IP "load (path)" 4 .IX Item "load (path)" Returns the component object corresponding to an absolute component \fIpath\fR, or undef if none exists. Dies with an error if the component fails to load because of a syntax error. .IP "object_dir" 4 .IX Item "object_dir" Returns the directory containing component object files. .IP "run ([request params], path, args...)" 4 .IX Item "run ([request params], path, args...)" Creates a new Mason::Request object for the given \fIpath\fR and \&\fIargs\fR, and executes it. Returns a Mason::Result object, which is generally accessed to get the output. e.g. .Sp .Vb 1 \& my $output = $interp\->run(\*(Aq/foo/bar\*(Aq, baz => 5)\->output; .Ve .Sp The first argument may optionally be a hashref of request parameters, which are passed to the Mason::Request constructor. e.g. this tells the request to output to standard output: .Sp .Vb 1 \& $interp\->run({out_method => sub { print $_[0] }}, \*(Aq/foo/bar\*(Aq, baz => 5); .Ve .IP "set_global (varname, value)" 4 .IX Item "set_global (varname, value)" Set the global \fIvarname\fR to \fIvalue\fR. This will be visible in all components loaded by this interpreter. The variables must be on the allow_globals list. .Sp .Vb 2 \& $interp\->set_global(\*(Aq$scalar\*(Aq, 5); \& $interp\->set_global(\*(Aq$scalar2\*(Aq, $some_object); .Ve .Sp See also set_global. .SH "MODIFIABLE METHODS" .IX Header "MODIFIABLE METHODS" These methods are not intended to be called externally, but may be useful to modify with method modifiers in plugins and subclasses. Their APIs will be kept as stable as possible. .IP "is_pure_perl_comp_path ($path)" 4 .IX Item "is_pure_perl_comp_path ($path)" Determines whether \fI\f(CI$path\fI\fR is a pure Perl component \- by default, uses pure_perl_extensions. .IP "is_top_level_comp_path ($path)" 4 .IX Item "is_top_level_comp_path ($path)" Determines whether \fI\f(CI$path\fI\fR is a valid top-level component \- by default, uses top_level_extensions. .ie n .IP "modify_loaded_class ( $compc )" 4 .el .IP "modify_loaded_class ( \f(CW$compc\fR )" 4 .IX Item "modify_loaded_class ( $compc )" An opportunity to modify loaded component class \fI\f(CI$compc\fI\fR (e.g. add additional methods or apply roles) before it is made immutable. .ie n .IP "write_object_file ($object_file, $object_contents)" 4 .el .IP "write_object_file ($object_file, \f(CW$object_contents\fR)" 4 .IX Item "write_object_file ($object_file, $object_contents)" Write compiled component \fI\f(CI$object_contents\fI\fR to \fI\f(CI$object_file\fI\fR. This is an opportunity to modify \fI\f(CI$object_contents\fI\fR before it is written, or \&\fI\f(CI$object_file\fI\fR after it is written. .SH "SEE ALSO" .IX Header "SEE ALSO" Mason .SH "AUTHOR" .IX Header "AUTHOR" Jonathan Swartz .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2012 by Jonathan Swartz. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.