This is Info file pm.info, produced by Makeinfo version 1.68 from the input file bigpm.texi.  File: pm.info, Node: HTML/ElementGlob, Next: HTML/ElementRaw, Prev: HTML/Element/traverse, Up: Module List Perl extension for managing HTML::Element based objects as a single object. *************************************************************************** NAME ==== HTML::ElementGlob - Perl extension for managing HTML::Element based objects as a single object. SYNOPSIS ======== use HTML::ElementGlob; $element_a = new HTML::Element 'font', color => 'red'; $element_b = new HTML::Element 'font', color => 'blue'; $element_a->push_content('red'); $element_b->push_content('blue'); $p = new HTML::Element 'p'; $p->push_content($element_a, ' and ', $element_b, ' boo hoo hoo'); # Tag type of the glob is not really relevant unless # you plan on seeing the glob as_HTML() $eglob = new HTML::ElementGlob 'p'; $eglob->glob_push_content($element_a, $element_b); # Alter both elements at once $eglob->attr(size => 5); # They still belong to their original parent print $p->as_HTML; DESCRIPTION =========== HTML::ElementGlob is a managing object for multiple HTML::Element(3) style elements. The children of the glob element retain their original parental elements and have no knowledge of the glob that manipulates them. All methods that do not start with 'glob_' will be passed, sequentially, to all elements contained within the glob element. Methods starting with 'glob_' will operate on the glob itself, rather than being passed to its foster children. For example, $eglob->attr(size => 3) will invoke attr(size => 3) on all children contained by $eglob. $eglob->glob_attr(size => 3), on the other hand, will set the attr attribute on the glob itself. The tag type passed to HTML::Element::Glob is largely irrrelevant as far as how methods are passed to children. However, if you choose to invoke $eglob->as_HTML(), you might want to pick a tag that would sensibly contain the globbed children for debugging or display purposes. The 'glob_*' methods that operate on the glob itself are limited to those available in an HTML::Element(3). All other methods get passed blindly to the globbed children, which can be enhanced elements with arbitrary methods, such as HTML::ElementSuper(3). Element globs can contain other element globs. In such cases, the plain methods will cascade down to the leaf children. 'glob_*' methods, of course, will not be propogated to children globs. You will have to rely on glob_content() to access those glob children and access their 'glob_*' methods directly. REQUIRES ======== HTML::ElementSuper(3) AUTHOR ====== Matthew P. Sisk, <`sisk@mojotoad.com'> COPYRIGHT ========= Copyright (c) 1998-2000 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO ======== HTML::Element(3), HTML::ElementSuper, HTML::ElementRaw, HTML::Element::Table(3), perl(1).  File: pm.info, Node: HTML/ElementRaw, Next: HTML/ElementSuper, Prev: HTML/ElementGlob, Up: Module List Perl extension for HTML::Element(3). ************************************ NAME ==== HTML::ElementRaw - Perl extension for HTML::Element(3). SYNOPSIS ======== use HTML::ElementRaw; $er = new HTML::ElementRaw; $text = '

I would like this   HTML to not be encoded

'; $er->push_content($text); $h = new HTML::Element 'h2'; $h->push_content($er); # Now $text will appear as you typed it, non-escaped, # embedded in the HTML produced by $h. print $h->as_HTML; DESCRIPTION =========== Provides a way to graft raw HTML strings into your HTML::Element(3) structures. Since they represent raw text, these can only be leaves in your HTML element tree. The only methods that are of any real use in this degenerate element are push_content() and as_HTML(). The push_content() method will simply prepend the provided text to the current content. If you happen to pass an HTML::element to push_content, the output of the as_HTML() method in that element will be prepended. REQUIRES ======== HTML::Element(3) AUTHOR ====== Matthew P. Sisk, <`sisk@mojotoad.com'> COPYRIGHT ========= Copyright (c) 1998 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO ======== HTML::Element(3), HTML::ElementSuper(3), HTML::Element::Glob(3), HTML::ElementTable(3), perl(1).  File: pm.info, Node: HTML/ElementSuper, Next: HTML/ElementTable, Prev: HTML/ElementRaw, Up: Module List Perl extension for HTML::Element(3) *********************************** NAME ==== HTML::ElementSuper - Perl extension for HTML::Element(3) SYNOPSIS ======== use HTML::ElementSuper; ### Positional extension $e = new HTML::ElementSuper 'font'; $sibling_number = $e->addr(); $e2 = new HTML::ElementSuper 'p'; $e2->push_content($e); # @coords = $e->position(); $depth_in_pos_tree = $e->depth(); ### Replacer extension $er = new HTML::ElementSuper 'font'; # Tree beneath $er, if present, is dropped. $er->replace_content(new HTML::Element 'p'); ### Wrapper extension $ew = new HTML::ElementSuper; $ew->push_content("Tickle me, baby"); $ew->wrap_content(new HTML::Element 'font', color => 'pink'); print $ew->as_HTML(); ### Maskable extension $em = new HTML::ElementSuper 'td'; $em->mask(1); print $em->as_HTML; # nada $em->mask(0); print $em->as_HTML; # $e and its children are visible ### Cloning of own tree or another element's tree ### (is this the correct clomenature? :-) $a = new HTML::ElementSuper 'font', size => 2; $b = new HTML::ElementSuper 'font', color => 'red'; $a_clone = $a->clone; $b_clone = $a->clone($b); # Multiple elements can be cloned @clone_clones = $a_clone->clone($a_clone, $b_clone); DESCRIPTION =========== HTML::ElementSuper is an extension for HTML::Element(3) that provides several new methods to assist in element manipulation. An HTML::ElementSuper has the following additional properties: * report is coordinate position in a tree of its peers * replace its contents * wrap its contents in a new element * mask itself so that it and its descendants are invisible to traverse() * clone itself and other HTML::Element based object trees Note that these extensions were originally developed to assist in implementing the HTML::ElementTable(3) class, but were thought to be of general enough utility to warrant their own package. METHODS ======= new('tag', attr => 'value', ...) Return a new HTML::ElementSuper object. Exactly like the constructor for HTML::Element(3), takes a tag type and optional attributes. addr() Returns the position of this element in relation to its siblings based on the content of the parent, starting with 0. Returns undef if this element has no parent. In other words, this returns the index of this element in the content array of the parent. position() Returns the coordinates of this element in the tree it inhabits. This is accomplished by succesively calling addr() on ancestor elements until either a) an element that does not support these methods is found, or b) there are no more parents. The resulting list is the n-dimensional coordinates of the element in the tree. replace_content(@new_content) Simple shortcut method that deletes the current contents of the element before adding the new. wrap_content($wrapper_element) Wraps the existing content in the provided element. If the provided element happens to be a non-element, a push_content is performed instead. mask mask(mode) Toggles whether or not this element is visible to parental methods that visit the element tree using traverse(), such as as_HTML(). Valid arguments for mask() are 0 and 1. Returns the current setting without an argument. This might seem like a strange method to have, but it helps in managing dynamic tree structures. For example, in HTML::ElementTable(3), when you expand a table cell you simply mask what it covers rather than destroy it. Shrinking the table cell reveals that content to as_HTML() once again. clone clone(@elements) Returns a clone of elements and all of their descendants. Without arguments, the element clones itself, otherwise it clones the elements provided as arguments. Any element can be cloned as long as it is HTML::Element(3) based. This method is very handy for duplicating tree structures since an HTML::Element cannot have more than one parent at any given time...hence "tree". REQUIRES ======== HTML::Element(3), Data::Dumper(3) AUTHOR ====== Matthew P. Sisk, <`sisk@mojotoad.com'> COPYRIGHT ========= Copyright (c) 1998-2000 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO ======== HTML::Element(3), HTML::ElementGlob(3), HTML::ElementRaw(3), HTML::ElementTable(3), perl(1).  File: pm.info, Node: HTML/ElementTable, Next: HTML/Embperl/Mail, Prev: HTML/ElementSuper, Up: Module List Perl extension for manipulating a table composed of HTML::Element style components. *********************************************************************************** NAME ==== HTML::ElementTable - Perl extension for manipulating a table composed of HTML::Element style components. SYNOPSIS ======== use HTML::ElementTable; # Create a table 0..10 x 0..12 $t = new HTML::ElementTable maxrow => 10, maxcol => 12; # Populate cells with coordinates $t->table->push_position; # Manipulate tag $t->attr('cellspacing',0); $t->attr('border',1); $t->attr('bgcolor','#DDBB00'); # Manipulate entire table - optimize on or pass to all if possible) $t->row(0,2,4,6)->attr('bgcolor','#9999FF'); # Manipulate columns (all go to ) $t->box(7,1 => 10,3)->attr('bgcolor','magenta'); $t->box(7,7 => 10,5)->attr('bgcolor','magenta'); $t->box(8,9 => 9,11)->attr('bgcolor','magenta'); $t->box(7,10 => 10,10)->attr('bgcolor','magenta'); # individual element or the collected
$t->table->attr('align','left'); $t->table->attr('valign','top'); # Manipulate rows (optimizes on
tags within column) $t->col(0,4,8,12)->attr('bgcolor','#BBFFBB'); # Manipulate boxes (all go to elements # unless it contains full rows, then
or attributes $t->cell(8,6)->attr('bgcolor','#FFAAAA'); $t->cell(9,6)->attr('bgcolor','#FFAAAA'); $t->cell(7,9, 10,9, 7,11, 10,11)->attr('bgcolor','#FFAAAA'); # Take a look print $t->as_HTML; DESCRIPTION =========== HTML::ElementTable provides a highly enhanced HTML::ElementSuper structure with methods designed to easily manipulate table elements by using coordinates. Elements can be manipulated in bulk by individual cells, arbitrary groupings of cells, boxes, columns, rows, or the entire table. PUBLIC METHODS ============== Table coordinates start at 0,0 in the upper left cell. CONSTRUCTOR new() new(maxrow => row, maxcol => col) Return a new HTML::ElementTable object. If the number of rows and columns were provided, all elements required for the rows and columns will be initialized as well. See extent(). TABLE CONFIGURATION extent() extent(maxrow, maxcolumn) Set or return the extent of the current table. The *maxrow* and *maxcolumn* parameters indicate the maximum row and column coordinates you desire in the table. These are the coordinates of the lower right cell in the table, starting from (0,0) at the upper left. Providing a smaller extent than the current one will shrink the table with no ill effect, provided you do not mind losing the information in the clipped cells. maxrow() Set or return the coordinate of the last row. maxcol() Set or return the coordinate of the last column. ELEMENT ACCESS Unless accessing a single element, most table element access is accomplished through *globs*, which are collections of elements that behave as if they were a single element object. Whenever possible, globbed operations are optimized into the most appropriate element. For example, if you set an attribute for a row glob, the attribute will be set either on the
elements, whichever is appropriate. See `HTML::ElementGlob(3)' in this node for more information on element globs. cell(row,col,[row2,col2],[...]) Access an individual cell or collection of cells by their coordinates. row(row,[row2,...]) Access the contents of a row or collection of rows by row coordinate. col(col,[col2,...]) Access the contents of a column or collection of columns by column coordinate. box(row_a1,col_a1,row_a2,col_a2,[row_b1,col_b1,row_b2,col_b2],[...]) Access the contents of a span of cells, specified as a box consisting of two sets of coordinates. Multiple boxes can be specified. table() Access all cells in the table. This is different from manipulating the table object itself, which is reserved for such things as CELLSPACING and other attributes specific to the tag. However, since table() returns a glob of cells, if the attribute is more appropriate for the top level
tag, it will be placed there rather than in each tag or every
tag. ELEMENT/GLOB METHODS The interfaces to a single table element or a glob of elements are identical. All methods available from the HTML::ElementSuper class are also available to a table element or glob of elements. See `HTML::ElementSuper(3)' in this node for details on these methods. Briefly, here are some of the more useful methods provided by HTML::ElementSuper: attr() push_content() replace_content() wrap_content() clone([element]) mask([mode]) TABLE SPECIFIC EXTENSIONS blank_fill([mode]) Set or return the current fill mode for blank cells. The default is 0 for HTML::Element::Table elements. When most browsers render tables, if they are empty you will get a box the color of your browser background color rather than the BGCOLOR of that cell. When enabled, empty cells are provided with an ' ', or invisible content, which will trigger the rendering of the BGCOLOR for that cell. NOTES ON GLOBS ============== Globbing was a convenient way to treat arbitrary collections of table cells as if they were a single HTML element. Methods are generally passed blindly and sequentially to the elements they contain. Most of the time, this is fairly intuitive, such as when you are setting the attributes of the cells. Other times, it might be problematic, such as with push_content(). Do you push the same object to all of the cells? HTML::Element based classes only support one parent, so this breaks if you try to push the same element into multiple parental hopefuls. In the specific case of push_content() on globs, the elements that eventually get pushed are clones of the originally provided content. It works, but it is not necessarily what you expect. An incestuous HTML element tree is probably not what you want anyway. See `HTML::ElementGlob(3)' in this node for more details on how globs work. REQUIRES ======== HTML::ElementSuper, HTML::ElementGlob AUTHOR ====== Matthew P. Sisk, <`sisk@mojotoad.com'> ACKNOWLEDGEMENTS ================ Thanks to William R. Ward for some conceptual nudging. COPYRIGHT ========= Copyright (c) 1998-2000 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO ======== A useful page of HTML::ElementTable examples can be found at http://www.mojotoad.com/sisk/projects/HTML-Element-Extended/examples.html. HTML::ElementSuper(3), HTML::ElementGlob(3), HTML::Element(3), perl(1).  File: pm.info, Node: HTML/Embperl/Mail, Next: HTML/Embperl/Session, Prev: HTML/ElementTable, Up: Module List Sends results from Embperl via E-Mail ************************************* NAME ==== HTML::Embperl::Mail - Sends results from Embperl via E-Mail SYNOPSIS ======== use HTML::Embperl::Mail ; HTML::Embperl::Mail::Execute ({inputfile => 'template.epl', subject => 'Test HTML::Embperl::Mail::Execute', to => 'email@foo.org'}) ; DESCRIPTION =========== *HTML::Embperl::Mail* uses *HTML::Embperl* to process a page template and send the result out via EMail. Currently only plain text mails are supported. A later version may add support for HTML mails. Because of that fact, normal *Embperl* HTML processing is disabled per Default (see `options' in this node below). Execute ------- The Execute function can handle all the parameter that `HTML::Embperl::Execute' does. Addtionaly the following parameters are recognized: from gives the sender e-mail address to gives the recipient address(es). Multiply addresses can either be separated by semikolon or given as an array ref. cc gives the recipient address(es) which should receive a carbon copy. Multiply addresses can either be separated by semikolon or given as an array ref. bcc gives the recipient address(es) which should receive a blind carbon copy. Multiply addresses can either be separated by semikolon or given as an array ref. subject gives the subject line reply-to the given address is insert as reply address mailheaders Array ref of additional mail headers mailhost Specifies which host to use as SMTP server. Default is *localhost*. mailhelo Specifies which host/domain to use in the HELO/EHLO command. A reasonable default is normaly choosen by *Net::SMTP*, but depending on your installation it may neccessary to set it manualy. maildebug Set to 1 to enable debugging of mail transfer. options If no options are given the following are used per default: *optDisableHtmlScan*, *optRawInput*, *optKeepSpaces*, *optReturnError* escmode In contrast to normal *Embperl* escmode defaults to zero (no escape) errors As in `HTML::Embperl::Execute' you can specify an array ref, which returns all the error messages from template processing. If you don't specify this parameter Execute will die when an error occurs. Configuration ------------- Some default values could be setup via environement variables EMBPERL_MAILHOST ---------------- Specifies which host to use as SMTP server. Default is *localhost*. EMBPERL_MAILHELO ---------------- Specifies which host/domain to use in the HELO/EHLO command. A reasonable default is normaly choosen by *Net::SMTP*, but depending on your installation it may neccessary to set it manualy. EMBPERL_MAILFROM ---------------- Specifies which the email address that is used as sender. Default is *www-server@server_name*. EMBPERL_MAILDEBUG ----------------- Debug setting for Net::SMTP. Default is 0. Author ====== G. Richter (richter@dev.ecos.de) See Also ======== perl(1), HTML::Embperl, Net::SMTP  File: pm.info, Node: HTML/Embperl/Session, Next: HTML/EmbperlObject, Prev: HTML/Embperl/Mail, Up: Module List HTML::Embperl::Session ********************** NAME ==== HTML::Embperl::Session DESCRIPTION =========== An adaptation of Apache::Session to work with HTML::Embperl SYNOPSIS ======== Addtional Attributes for TIE ---------------------------- lazy By Specifing this attribute, you tell Apache::Session to not do any access to the object store, until the first read or write access to the tied hash. Otherwise the tie function will make sure the hash exist or creates a new one. create_unknown Setting this to one causes Apache::Session to create a new session with the given id (or a new id, depending on recreate_id) when the specified session id does not exists. Otherwise it will die. recreate_id Setting this to one causes Apache::Session to create a new session id when the specified session id does not exists. object_store Specify the class for the object store. (The Apache::Session:: prefix is optional) Only for Apache::Session 1.00. lock_manager Specify the class for the lock manager. (The Apache::Session:: prefix is optional) Only for Apache::Session 1.00. Store Specify the class for the object store. (The Apache::Session::Store prefix is optional) Only for Apache::Session 1.5x. Lock Specify the class for the lock manager. (The Apache::Session::Lock prefix is optional) Only for Apache::Session 1.5x. Generate Specify the class for the id generator. (The Apache::Session::Generate prefix is optional) Only for Apache::Session 1.5x. Serialize Specify the class for the data serializer. (The Apache::Session::Serialize prefix is optional) Only for Apache::Session 1.5x. Example using attrubtes to specfiy store and object classes instead of a derived class: use HTML::Embperl::Session; tie %session, 'HTML::Embperl::Session', undef, { object_store => 'DBIStore', lock_manager => 'SysVSemaphoreLocker', DataSource => 'dbi:Oracle:db' }; NOTE: HTML::Embperl::Session will require the nessecary additional perl modules for you. Addtional Methods ----------------- setid Set the session id for futher accesses. getid Get the session id. The difference to using $session{_session_id} is, that in lazy mode, getid will not create a new session id, if it doesn't exists. cleanup Writes any pending data, releases all locks and deletes all data from memory. AUTHORS ======= Gerald Richter is the current maintainer. This class was written by Jeffrey Baker (jeffrey@kathyandjeffrey.net) but it is taken wholesale from a patch that Gerald Richter (richter@ecos.de) sent me against Apache::Session.  File: pm.info, Node: HTML/EmbperlObject, Next: HTML/Entities, Prev: HTML/Embperl/Session, Up: Module List Extents HTML::Embperl for building whole website with reusable components and objects ************************************************************************************* NAME ==== HTML::EmbperlObject - Extents HTML::Embperl for building whole website with reusable components and objects SYNOPSIS ======== PerlSetEnv EMBPERL_OBJECT_BASE base.htm PerlSetEnv EMBPERL_FILESMATCH "\.htm.?|\.epl$" SetHandler perl-script PerlHandler HTML::EmbperlObject Options ExecCGI DESCRIPTION =========== *HTML::EmbperlObject* allows you to build object-oriented (OO) websites using HTML components which implement inheritance via subdirectories. This enables elegant architectures and encourages code reuse. The use of inheritance also enables a website-wide "look and feel" to be specified in a single HTML file, which is then used as a template for every other page on the site. This template can include other modules which can be overridden in subdirectories; even the template itself can be overridden. In a nutshell, EmbperlObject makes the design of large websites much more intuitive, allowing object-oriented concepts to be utilised to the fullest while staying within the "rapid application development" model of Perl and HTML. *HTML::EmbperlObject* is basicly a mod_perl handler or could be invoked offline and helps you to build a whole page out of smaller parts. Basicly it does the following: When a request comes in, a page, which name is specified by `EMBPERL_OBJECT_BASE' in this node, is searched in the same directory as the requested page. If the pages isn't found, EmbperlObject walking up the directory tree until it finds the page, or it reaches `DocumentRoot' or the directory specified by `EMBPERL_OBJECT_STOPDIR' in this node. This page is then called as frame for building the real page. Addtionaly EmbperlObject sets the search path to contain all directories it had to walk before finding that page. If `EMBPERL_OBJECT_STOPDIR' in this node is set the path contains all directories up to the in EMBPERL_OBJECT_STOPDIR specified one. This frame page can now include other pages, using the `HTML::Embperl::Execute' method. Because the search path is set by EmbperlObject the included files are searched in the directories starting at the directory of the original request walking up thru the directory which contains the base page. This means that you can have common files, like header, footer etc. in the base directory and override them as necessary in the subdirectory. To include the original requested file, you need to call Execute with a '*' as filename. To call the the same file, but in an upper directory you can use the special shortcut `../*'. Additionaly EmbperlObject sets up a inherence hierachie for you: The requested page inherit from the base page and the base page inherit from a class which could be specified by EMBPERL_OBJECT_HANDLER_CLASS, or if EMBPERL_OBJECT_HANDLER_CLASS is not set, from `HTML::Embperl::Req'. That allows you to define methods in base page and overwrite them as neccessary in the original requested files. For this purpose a request object, which is blessed into the package of the requested page, is given as first parameter to each page (in `$_[0]'). Because this request object is a hashref, you can also use it to store additional data, which should be available in all components. *Embperl* does not use this hash itself, so you are free to store whatever you want. Methods can be ordinary Perl sub's (defined with [! sub foo { ... } !] ) or Embperl sub's (defined with [$sub foo $] .... [$endsub $]) . Runtime configuration ===================== The runtime configuration is done by setting environment variables, in your web server's configuration file. EMBPERL_DECLINE --------------- Perl regex which files should be ignored by EmbperlObject EMBPERL_FILESMATCH ------------------ Perl regex which files should be processed by EmbperlObject EMBPERL_OBJECT_BASE ------------------- Name of the base page to search for EMBPERL_OBJECT_STOPDIR ---------------------- Directory where to stop searching for the base page EMBPERL_OBJECT_ADDPATH ---------------------- Additional directories where to search for pages. Directories are separated by `;' (on Unix : works also). This path is always appended to the searchpath. EMBPERL_OBJECT_FALLBACK ----------------------- If the requested file is not found the file given by EMBPERL_OBJECT_FALLBACK is displayed instead. If EMBPERL_OBJECT_FALLBACK isn't set a staus 404, NOT_FOUND is returned as usual. If the fileame given in EMBPERL_OBJECT_FALLBACK doesn't contain a path, it is searched thru the same directories as EMBPERL_OBJECT_BASE. EMBPERL_OBJECT_HANDLER_CLASS ---------------------------- If you specify this call the template base and the requested page inherit all methods from this class. This class must contain `HTML::Embperl::Req' in his @ISA array. Execute ======= You can use EmbperlObject also offline. You can do this by calling the function `HTML::EmbperlObject::Execute'. Execute takes a hashref as argument, which can contains the same parameters as the `HTML::Embperl::Execute' function. Additionaly you may specify the following parameters: object_base same as $ENV{EMBPERL_OBJECT_BASE} object_addpath same as $ENV{EMBPERL_OBJECT_ADDPATH} object_stopdir same as $ENV{EMBPERL_OBJECT_STOPDIR} object_fallback same as $ENV{EMBPERL_OBJECT_FALLBACK} object_handler_class same as $ENV{EMBPERL_OBJECT_HANDLER_CLASS} See also the object and isa parameters in Embperl's Execute function, on how to setup additional inherence and how to create Perl objects out of Embperl pages. Basic Example ============= With the following setup: PerlSetEnv EMBPERL_OBJECT_BASE base.htm PerlSetEnv EMBPERL_FILESMATCH "\.htm.?|\.epl$" SetHandler perl-script PerlHandler HTML::EmbperlObject Options ExecCGI *Directory Layout:* /foo/base.htm /foo/head.htm /foo/foot.htm /foo/page1.htm /foo/sub/head.htm /foo/sub/page2.htm */foo/base.htm:* Example [- Execute ('head.htm') -] [- Execute ('*') -] [- Execute ('foot.htm') -] */foo/head.htm:*

head from foo

*/foo/sub/head.htm:*

another head from sub

*/foo/foot.htm:*
Footer
*/foo/page1.htm:* PAGE 1 */foo/sub/page2.htm:* PAGE 2 */foo/sub/index.htm:* Index of /foo/sub If you now request *http://host/foo/page1.htm* you will get the following page Example

head from foo

PAGE 1
Footer
If you now request *http://host/foo/sub/page2.htm* you will get the following page Example

another head from sub

PAGE 2
Footer
If you now request *http://host/foo/sub/* you will get the following page Example

another head from sub

Index of /foo/sub
Footer
Example for using method calls ============================== (Everything not given here is the same as in the example above) */foo/base.htm:* [! sub new { my $self = shift ; # here we attach some data to the request object $self -> {fontsize} = 3 ; } # Here we give a default title sub title { 'Title not given' } ; !] [- # get the request object of the current request $req = shift ; # here we call the method new $req -> new ; -] [+ $req -> title +] [- Execute ('head.htm') -] [- Execute ('*') -] [- Execute ('foot.htm') -] */foo/head.htm:* [# here we use the fontsize Note that $foo = $_[0] is the same as writing $foo = shift #] {fontsize} +]>header */foo/sub/page2.htm:* [! sub new { my $self = shift ; # here we overwrite the new method form base.htm $self -> {fontsize} = 5 ; } # Here we overwrite the default title sub title { 'Title form page 2' } ; !] PAGE 2 Author ====== G. Richter (richter@dev.ecos.de) See Also ======== perl(1), HTML::Embperl, mod_perl, Apache httpd  File: pm.info, Node: HTML/Entities, Next: HTML/Faq, Prev: HTML/EmbperlObject, Up: Module List Encode or decode strings with HTML entities ******************************************* NAME ==== HTML::Entities - Encode or decode strings with HTML entities SYNOPSIS ======== use HTML::Entities; $a = "Våre norske tegn bør æres"; decode_entities($a); encode_entities($a, "\200-\377"); DESCRIPTION =========== This module deals with encoding and decoding of strings with HTML character entities. The module provides the following functions: decode_entities($string) This routine replaces HTML entities found in the $string with the corresponding ISO-8859/1 (or with perl-5.7 or better Unicode) character. Unrecognized entities are left alone. encode_entities($string, [$unsafe_chars]) This routine replaces unsafe characters in $string with their entity representation. A second argument can be given to specify which characters to concider as unsafe. The default set of characters to expand are control chars, high-bit chars and the '<', '&', '>' and '"' characters. Both routines modify the string passed as the first argument if called in a void context. In scalar and array contexts the encoded or decoded string is returned (and the argument string is left unchanged). If you prefer not to import these routines into your namespace you can call them as: use HTML::Entities (); $encoded = HTML::Entities::encode($a); $decoded = HTML::Entities::decode($a); The module can also export the %char2entity and the %entity2char hashes which contain the mapping from all characters to the corresponding entities. COPYRIGHT ========= Copyright 1995-2001 Gisle Aas. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.  File: pm.info, Node: HTML/Faq, Next: HTML/Features, Prev: HTML/Entities, Up: Module List embed Perl code in your HTML docs ********************************* NAME ==== Embperl FAQ - embed Perl code in your HTML docs CONTENTS ======== `"Downloading, Compiling & Installing"' in this node `"Common Problems"' in this node `"Common Questions"' in this node `"Escaping & Unescaping"' in this node `"Debugging"' in this node `"Customizing"' in this node `"Optimizing & Fine Tuning"' in this node `"Additional Help"' in this node Downloading, Compiling & Installing =================================== For basics on downloading, compiling, and installing, please see the `INSTALL' in this node in the Embperl documentation. Please be sure to load Embperl at server startup - if you do not, various problems may result. An exception to that rule is when you have compiled mod_perl with *USE_DSO*. In this case you *must not* load Embperl at server statup, neither via an use in your startup.pl file, nor via PerlModule from your httpd.conf. Is there a binary distribution of Embperl for Unix? --------------------------------------------------- No. Is there a binary distribution of Embperl for Win32? ---------------------------------------------------- Win NT/95/98 binarys for Apache/perl/mod_perl/Embperl are available from ftp://theoryx5.uwinnipeg.ca/pub/other/ . A european mirror is at http://www.robert.cz/misc/ . I want to run Embperl with mod_perl under Apache. In what order should I do the compiling? ------------------------------------------------------------------------------------------ First mod_perl and Apache, then Embperl. I'm getting: ------------ ../apache_1.3.0/src/include/conf.h:916: regex.h: No such file or directory Try compiling Embperl again, like this: make DEFS=-DUSE_HSREGEX I'm trying to build HTML::Embperl, and while running 'make' i get: ------------------------------------------------------------------ cc: Internal compiler error: program cc1 got fatal signal 11 make: *** [epmain.o] Error 1 GCC croaking with signal 11 frequently indicates hardware problems. See http://www.bitwizard.nl/sig11/ I have a lot of errors in 'make test' from mod_perl when using Embperl ---------------------------------------------------------------------- Try recompiling Perl and all modules - this can sometimes make those annoying error messages disappear! How can I prevent 'make test' from running some of the tests? ------------------------------------------------------------- For example, I don't allow CGI scripts, so 'make test' fails at CGI. How do I run just the other tests? Try: $ make test TESTARGS="--help" # and for just offline and mod_perl: $ make test TESTARGS="-hoe" Running 'make test' fails with an error message at loading of Embperl (even though mod_perl compiled and tested cleanly!) -------------------------------------------------------------------------------------------------------------------------- see "I get symbol ap_* undefined/cannot resolve ap_*" I get symbol ap_* undefined/cannot resolve ap_* ----------------------------------------------- This can happen when symbols in the Apache binary can not be found or are not being resolved correctly. Some OS do this (for instance bsdos), and it can also happen if your Apache binary is set to strip symbol information out from binaries. Try: 1. make clean 2. perl Makefile.PL NOTE: answer _no_ to mod_perl support. (This is important!) 3. make test If that works, it means that your installation of Embperl is OK, but is having problems resolving symbols with Apache. Try rebuilding Apache and mod_perl from scratch, and make sure you do not strip symbols out of either. On some systems/linker you need to tell the linker explicitly to export such symbols. For example FreeBSD linker needs the `-export-dynamic' option. If you don't succeed with this approach, try statically linking Embperl to Apache/mod_perl (please see the next question for step-by-step instructions on how to do this). How can I build a statically-linked copy of Embperl with mod_perl support? --------------------------------------------------------------------------- 1. go to your mod_perl directory, change to src/modules/perl and edit the Makefile so that it contains the line #STATIC_EXTS = Apache Apache::Constants HTML::Embperl 2. add a definition for EPDIR and change the ONJ= line so that it looks like this: EPDIR=/usr/msrc/embperl OBJS=$(PERLSRC:.c=.o) $(EPDIR)/Embperl.o $(EPDIR)/epmain.o $(EPDIR)/epio.o (EP DIR)/epeval.o $(EPDIR)/epcmd.o $(EPDIR)/epchar.o $(EPDIR)/eputil.o 3. go to the mod_perl directory and run perl Makefile.PL 4. go to the Embperl directory and do make clean perl Makefule.PL make (to compile in mod_perl support) 5. go back to the mod_perl directory and remake Apache by typing make Now you have successfully built a httpd with statically-linked Embperl. NOTE: If you want to stop here, you can skip to step 11. and run a 'make install' in the Embperl directory to finish. But if you want to run Embperl tests and/or if you want to be able to use Embperl in offline or "vanilla" CGI mode, we need to continue: 6. go back to the Embperl directory 7. backup the file test/conf/config.pl 8. now build Embperl again but _without_ mod_perl support make clean perl Makefile.PL make 9. restore your saved config.pl to test/conf/config.pl (without this step, only the offline mode would be tested) 10. run 'make test' for Embperl 11. do 'make install' for Embperl NOTE: You should do it in this order, or it may not work. NOTE: It seems to be necessary to load Embperl at server startup, either by PerlModule or in a PerlScript. See next question on how to do this. How do I load Embperl at server startup? ---------------------------------------- You can load Embperl at server startup by PerlModule or in a startup.pl: 1. edit your srm.conf file to read: PerlModule HTML::Embperl 2. edit your startup.pl file to read: use HTML::Embperl NOTE 1: Either of these approaches can often 'fix' SIGSEVs in any mod_perl handler, not just Embperl. NOTE 2: When mod_perl is compiled as loadable module (i.e. with USE_DSO) you *must not* load Embperl at server startup time! make test fails with a SIGxxxx, how can I obtain a stack backtrace from gdb? ---------------------------------------------------------------------------- The eaiest way is make install -> if Embperl is installed, it's easier gdb perl -> start the debugger with perl binary set args test.pl -> set the arguments for perl r -> start the program -> Here you should receive the signal share -> makes sure all symbols are really loaded bt -> show the backtrace To get some more information it would be a good idea to compile Embperl with debugging infomation enabled. Therefor do How do I build Embperl with debugging informations -------------------------------------------------- edit the Makefile search for the line starting with 'CC = ' add the -g switch to the end of the line search for the line starting with 'LDDFLAGS = ' add the -g switch to the end of the line type make to build Embperl with debugging infomation now start the gdb as decribed before. make test fails with SIGXFSZ ---------------------------- This may occur when the filesize limit for the account, either test is running as or the test httpd, is too small. Embperl make test generates a really large logfile! Yu must increase the filesize limit for that accounts. Embperl on SCO Unix ------------------- >From Red Plait My OS is SCO Unix 3.2v4.2, Apache 1.3.4, perl 5.004_4, mod_perl 1.18 and Embperl-1.1.1 I done following: 1. I made HTML-Embperl-1.1.1 with no mod_perl support ( when I builded it with mod_perl 1.18 I can`t link it because it don`t finds ap_XXX functions. When I manually insert src/main/libmain.a from Apache 1.3.4 I got message "Symbol main is multiple defined in /src/main/libmain.a. and perlmain.o" ). Then I "make test" - all tests was O`k. After this I "make clean", "perl Makefile.pl" with mod_perl support and "make install" 2. I installed mod_perl and "perl Makefile.PL", then "make" 3. because I have`nt dynamical loading ( very old and buggy OS ) I had to manually change src/modules/perl/perlxsi.c to insert bootstraps function`s and it`s invocations and also /src/Makefile to manually insert libXXX.a libraries 4. In access.conf I insert code: PerlModule HTML::Embperl SetHandler perl-script PerlHandler HTML::Embperl::handler Embperl and mod_perl on AIX --------------------------- You need at least mod_perl 1.22. For mod_perl 1.22 and higher Embperl should compile out of the box on AIX. If you run into problems with undefined symbols (like `ap_*') make sure you have the newest mod_perl version (as of this writing this is mod_perl 1.24_01). Embperl does not write to the logfile, because of missing permissions of the user Apache runs as. ------------------------------------------------------------------------------------------------- The apache server is started as root, then set the effective uid to user "www", who can then write to the embperl logfile (owned by root) file handle that is passed along. However, if this log file handle is later accidentally closed, then reopen, the www user would have problem writing to it? The reopen is only done when the logfile name changes. As log as you don't change the name on the logfile, the logfile will stay open. The problem (in this case) is, that Embperl init function ,(Init in epmain.c) calls OpenLog will an second argument of zero. Which will only save the filename. The log will actually opened on the first write to it (or at the start of the first request). At this time your Apache has alreay switch to user www. This is done to allow to change the logfile name before an request, but after the init is already called (which is done when you or Apache "use" the module) The current solutions is to write something to the log, before Apache changes it's user (i.e. in the startup.pl) Is it possible to install EmbPerl into a private directory on my Unix/Linux Internet Service Provider account of which I have no root privilege? ------------------------------------------------------------------------------------------------------------------------------------------------ Like any other Perl module it can. Read "perldoc ExtUtils::MakeMaker", to see which parameters are needed for Makefile.PL to change the installation directory. Additionally, you have to change the @INC path to contain your private directory and possibly paths to other object files. Here are the brief details: Requirements: * At least Perl 5.004_04 * cc or gcc (your isp must give you access to the gcc compiler) * URI * MIME::Base64 * HTML::Parser * HTML::HeadParser * Digest::MD5 * libnet * libwww * File::Spec (I believe you may have to install this too if you are using Perl 5.004_04 as it may not be a standard module) *Direction*: * Get your copy of EmbPerl (HTML-Embperl-x.x.tar.gz) * % tar -xvzf HTML-Embperl-x.x.tar.gz * % cd HTML-Embperl-x.x * % perl Makefile.PL PREFIX=/to/your/private/dir * % make * % make test * % make install Replace /to/your/private/dir with the path to the directory you want the module to be placed in. Now preface your CGI scripts with something like this: [Alternative 1] #!/usr/bin/perl -wT use CGI::Carp qw( fatalsToBrowser ); #recommend using this to report errors on die or warn to browser use lib '/to/your/private/dir/lib'; #for FILE::Spec use lib '/to/your/private/dir/'; #to find Embperl use lib '/to/your/private/dir/i386-linux/auto/HTML/Embperl'; #to find Embperl compiled stuff #if for some very weird reason the above 'use lib' pragma directive doesn't work, see Alternative 2 use HTML::Embperl; #your code below ... [Alternative 2] #!/usr/bin/perl -wT use CGI::Carp qw( fatalsToBrowser ); #recommend using this to report errors on die or warn to browser BEGIN { unshift @INC, '/to/your/private/dir/lib'; #for FILE::Spec unshift @INC, '/to/your/private/dir/'; #to find Embperl unshift @INC, '/to/your/private/dir/i386-linux/auto/HTML/Embperl'; #to find Embperl compiled stuff } use HTML::Embperl; #your code below ... When you make test, you may encounter superfluous warnings, you may want to change the test.pl that ships with EmbPerl from BEGIN { $fatal = 1 ; to BEGIN { unshift @INC, '/to/your/private/dir/lib'; $fatal = 1 ; ... because the test.pl may not be able to find FILE::Spec if you have it installed on a private directory for Perl 5.004_04. Do something similar to the important file embpcgi.pl as you do for all your CGI scripts, like modifying the @INC as shown above, to allow perl to find in particular the EmbPerl shared obj files... And when you invoke your CGI scripts like so, http://www.yourdomain.com/cgi-bin/embpcgi.pl/templateFiles/myNifty.epl the script should work. Common Problems =============== The most common problems of all involve Escaping and Unescaping. They are so common, that an entire section on `"Escaping & Unescaping"' in this node is devoted to them. When I use a module inside a Embperl page, it behaves weired when the source changes. ------------------------------------------------------------------------------------- Nothing weird here. Everything is well defined. Just let us try to understand how Perl, mod_perl and *Embperl* works together: "perldoc -f use" tells us: Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to BEGIN { require Module; import Module LIST; } except that Module must be a bareword. So what's important here for us is, that use executes a require and this is always done before any other code is executed. "perldoc -f require" says (among other things): ..., demands that a library file be included if it hasn't already been included. and Note that the file will not be included twice under the same specified name. So now we know (or should know) that mod_perl starts the Perl interpreter once when Apache is started and the Perl interpreter is only terminated when Apache is terminated. Out of these two things follows, that a module that is loaded via use or require is only loaded once and will never be reloaded, regardless if the source changes or not. So far this is just standard Perl. Things get's a little bit more difficult when running under mod_perl (only Unix), because Apache forks a set of child processes as neccessary and from the moment they are forked, they run on their own and don't know of each other. So if a module is loaded at server startup time (before the fork), it is loaded in all childs (this can be used to save memory, because the code will actually only reside once in memory), but when the modul is loaded inside the child and the source changes, it could be happen, that one child has loaded an ealier version and another child has loaded a later version of that module, depending on the time the module is actualy loaded by the child. That explains, why sometimes it works and sometimes it doesn't, simply because different childs has loaded different versions of the same module and when you reload your page you hit different childs of Apache! Now there is one point that is special to Embperl to add. Since Embperl compiles every page in a different namespace, a module that doesn't contains a `package foo' statement is compiled in the namespace of the page where it is first loaded. Because Perl will not load the module a second time, every other page will not see subs and vars that are defined in the loaded module. This could be simply avoided by giving every module that should be loaded via use/require an explicit namespace via the package statement. So what can we do? * If a module change, simply restart Apache. That's works always. * Use *Apache::StatInc.* This will do a stat on every loaded module and compare the modification time. If the source has changed the module is reloaded. This works most times (but not all modules can be cleanly reloaded) and as the number of loaded modules increase, your sever will slow down, because of the stat it has to do for every module. * Use do instead of require. do will execute your file everytime it is used. This also adds overhead, but this may be accpetable for small files or in a debugging environement. (NOTE: Be sure to check `$@' after a do, because do works like eval) Why doesn't the following line work? ------------------------------------ [+ $var . "". $foo . "". $bar +] See what we mean? This is an Escaping & Unescaping problem for sure. You need to escape as ' <b> ' and you probably also need to read the section on `"Escaping & Unescaping"' in this node... I'm getting: "Glob not terminated at ..." ----------------------------------------- This might be a problem with `"Escaping & Unescaping"' in this node as well. My HTML is getting stripped out. -------------------------------- Sounds like a problem with Escaping & Unescaping again! Unless, of course, you have already read the section on Escaping & Unescaping, and it is still happening... Like if you are using optRawInput and your HTML is _still_ being stripped out... I _am_ using optRawInput, and my HTML _is_ still being stripped out! -------------------------------------------------------------------- Aha! Well that's different! Never mind.. It can be easy to accidentally set optRawInput too late in your code... Try setting it in an extra Perl block ( [- $optRawInput = 1 -] ) earlier in the code, or in the server config, and see if that doesn't solve the problem... (optRawInput must be set before the block that uses it begins, as the block which uses it shouldn't be translated). Help! I got a SIGSEGV! Ack! --------------------------- If Embperl is not compiled at server startup, it can cause error messages, SEGfaults, core dumps, buffer overflow, etc - especially if you are using another module inside an Embperl page. As far as anyone can tell, this seems to be a Perl/mod_perl problem - but maybe not. If you have any ideas, let me know. To see the steps for loading Embperl at server startup, please see the section `"Downloading, Compiling & Installing"' in this node. NOTE: When mod_perl is compiled with *USE_DSO* it behaves vice versa and you may get SIGSEGVs when Embper is loaded at server startup time. I am having troubles with using Embperl in combination with Apache::Include inside a Apache::Registry script. ------------------------------------------------------------------------------------------------------------- This is a known problem, but it is a problem with mod_perl rather than with Embperl. It looks like mod_perl clears the request_rec after the first subrequest, so that it later doesn't know which subrequest was intended (unless it's explicitly specified). Try using: Apache::Include->virtual("test.epl", $r); (instead of just Apache::Include->virtual("test.epl"); where $r is the apache request rec) I can't get PerlSendHeader to work under Embperl? ------------------------------------------------- You don't need PerlSendHeader when using Embperl - Embperl always sends its own httpd header. But how do I customize the header that Embperl is sending? ---------------------------------------------------------- You'll find the answer to this and many other header issues in the `"Common Questions"' in this node section. I can't figure out how to split a 'while' statement across two [- -] segments ------------------------------------------------------------------------------ That isn't surprising, as you cannot split Perl statements across multiple [- -] blocks in Embperl :) You need to use a metacommand for that. The [$while$] metacommand comes to mind... :) For a list of all possible metacommands, see the section on `Meta-Commands|Embperl' in this node in the Embperl documentation. [$ while $st -> fetch $] #some html or other Embperl blocks goes here [$ endwhile $] Newer Embperl versions (1.2b3 and above) supports the [* *] which can be used for such purposes. [* while ($st -> fetch) { *] #some html or other Embperl blocks goes here [* } *] While the later can use all Perl control structures, the first seems to me more readable and is better debugable, because Embperl controls the execution of the control structure it can do a quite better job in debug logging. My HTML tags like '<' '>' and '"' are being translated to <, > !!! ------------------------------------------------------------------------ Hey! Not you again!? I thought we already sent you to the `"Escaping & Unescaping"' in this node section of the FAQ?!?! ;) Netscape asks to reload the document ------------------------------------ If you have something like this in your source, it may be the problem: Netscape seems to have a problem in such cases, because the http header is only content-type text/html, while the META HTTP-EQUIV has an additional charset specified. If you turn optEarlyHttpHeader off, Embperl will automatically set the http header to be the same as the META HTTP-EQUIV. I get "Stack underflow" ----------------------- The problem often occurs, when you have a tag in one file and a
tag in another file and you both include them in a main page (e.g. as header and footer). There are two workarounds for this problem: 1. Set optDisableTableScan This will avoid that Embperl takes any action on tables. You can disable/enable this (also multiple times) inside the page with [- $optDisableTableScan = 1 -] If you put this at the top of your header/footer which you include with Execute, then the main page will still process dynamic tables. 2. Add a as comment Add the following to the top of the footer document: This will work also, because Embperl (1.x) will not scan for html comments Common Questions ================ The most common questions of all deal with `"Escaping & Unescaping"' in this node - they are so common that the whole next section is devoted to them. Less common questions are addressed here: How can I get my HTML files to be converted into Perl code which, as a whole, could then be compiled as function so that I could, for instance, fetch Perl docs from the Formatter table and compile them the way AUTOLOAD does. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Embperl cannot covert your HTML into one piece of Perl-code, but you can wrap the call to Execute into a Perl function and let AUTOLOAD call it. I have an HTML page which is dynamically generated at runtime and should be post-processed by Embperl. How can I do this? -------------------------------------------------------------------------------------------------------------------------- 1. Generate the page within a normal CGI/Apache::Registry script and put the result into a scalar - then you can call HTML::Embperl::Execute to post-process your document. Execute can either send the document to the browser or put it into another scalar for further processing. 2. Use EMBPERL_INPUT_FUNC (1.1b1 and above). With this configuration directive, you can specify a custom input function which reads the HTML source from the disk or even from a database. Embperl also provides the function ProxyInput, which allows you to get input from another web server altogether. 3. Look at the module Apache::EmbperlChain, which is able to chain multiple modules, including Embperl, together. How can I customise the header that Embperl is sending? ------------------------------------------------------- You can write it as (Embperl will automatically insert all meta http-equiv tags into the http header) or use %http_headers_out [- $http_headers_out{'Content-Type'} = 'text/html' -] or (only when running under mod_perl) you can use [- $req_rec -> content_type ('text/html') -] Can I use Embperl to send cookies? ---------------------------------- Yes. Embperl sends its own headers, so all you have to do to send cookies is to remember to print an additional header. Example Code: 1. in documents, add 2. or use %http_headers_out [- $http_headers_out{'Set-Cookie'} = "$cookie=$value" -] 3. or - using mod_perl's functionality - use [- $req_rec -> header_out("Set-Cookie" => "$cookie=$value"); -] NOTE: You make also take a look at Embperls (1.2b2 and above) ability to handle sessions for you inside the %udat and %mdat hashes. Can I do a Redirect with Embperl? --------------------------------- The following way works with mod_perl and as cgi: [- $http_headers_out{'Location'} = "http://www.ecos.de/embperl/" -] the status of the request will automaticly set to 301. or use the mod_perl function Apache::header_out. Example Code: [- use Apache; use Apache::Constants qw(REDIRECT); $req_rec->header_out("Location" => "http://$ENV{HTTP_HOST}/specials/"); $req_rec->status(REDIRECT); -] If there is nothing more to do on this page, you may call exit directly after setting the status. Can I serve random GIFs with Embperl? (Will Lincoln Stein's GD.pm module work with Embperl??) --------------------------------------------------------------------------------------------- As always, there is more than one way to do this - especially as this is more of a question of how you are coding your HTML than how you are coding your Embperl. Here are some ideas: 1. You could include an IMG tag which points to your cgi-bin, where a regular CGI script serves the graphics. 2. You could be running Apache::Registry, which can generate on-the-fly GIFs using GD. (This is just the same as if you were including the GD image from a static page or from another CGI script, but it allows all of the appropriate logic to live in a single document, which might be appropriate for some Embperl users). If you think of another way, or come up with some sample code, I'd love to hear from you, so that I could add it to the FAQ... Can I use Embperl as a template for forms? Can I make form values persist (like with "vanilla" CGI)? Does Embperl rewrite my template file so that parameters of things like INPUT/TEXTAREA/SELECT persist? ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Yes. Your page design staff should just be able to say and let the default attributes of "foo" be defined elsewhere - for instance in a settings file. In this case, %fdat should be pre-set with your default values. Setting $fdat{foo} = "abc" will cause Embperl to change the above code to . Does Embperl automatically add HIDDEN fields? --------------------------------------------- The [$hidden$] metacommand creates hidden fields for every entry in %fdat which was not used by any other input tag so far. You can also try something like this: [- $fdat{foo} = "abc" ; $fdat{bar} = "xyz" ; -] [$hidden$] and Embperl will create: For a list of all possible metacommands, see the section on `Meta-Commands|Embperl' in this node in the Embperl documentation. What about security? Is Embperl Secure? --------------------------------------- Just like anything else, Embperl is as secure as you make it. Embperl incorporates Safe.pm, which will make it impossible to accidentally access other Packages - it also permits the Administrator to disable Perl opcodes, etc. For more on security, please see `Embperl' in this node in the Embperl documentation. Is there any plan to make Embperl an Object so someone could subclass it and override certain of its methods? (For example, I'd like to let it parse the file for me, but then let me control the manipulation of the form tags.) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Embperl is going to be an Object from version 1.2b1. This, among other things, make it re-entrant, so that you will be able to call Execute from within an Embperl page. It will also mean that Embperl will come with hooks, which will allow you to alter or change the way Embperl processes code. The details have not all been worked out yet, but I'm working on it... :) Are Embperl routines currently pre-compiled or even cached, or are only fragments cached? ----------------------------------------------------------------------------------------- All embedded Perl code is compiled the first time it is executed and cached for later use. The second time the code is executed, only the precompiled p-code is called. Every code block is compiled as a single subroutine. The HTML text between the Perl block is still read from the file. Why are Perl blocks broken up into single subroutines? ------------------------------------------------------ 1. It makes it easier to process the HTML tags between the Perl blocks - this gives you more control over what's happening 2. If you compiled _everything_ to Perl, you would hold all of the HTML text in memory, and your Apache child processes would grow and grow... But often-accessed documents are still held in memory by your os disk cache, which is much more memory-efficient. 3. There is only so far that you can go with precompiling until you reach the point of diminishing returns. My guess is that converting dynamic tables and other HTML processing to Perl at this point in Embperl's development would actually slow down operation. Can I pass QUERY_STRING information to an HTML::Embperl::Execute call? ---------------------------------------------------------------------- With Embperl 1.0 and higher, you can do this. QUERY_STRING is set as $ENV{QUERY_STRING} by default. Alternatively, you can use the fdat parameter to pass values to %fdat. How to include other files into Embperl pages? ---------------------------------------------- I am using embedded Perl on my site and am curious if I can use it for server side includes. I want to embed the contents of file x.html into file y.html such that whenever I change x.html, displaying y.html will also reflect this change. How do I do it using embedded perl? You need Embperl 1.2b4 or above. Then you can say inside of y.html: [- Execute ('x.html') -] EmbPerl iteration without indexing ---------------------------------- I have a rather large table in a database which I'd like to display using EmbPerl. All of the examples show a process of fetching all the data first, then iterating through it using $row and $col, like this: [- $sth = $dbh -> prepare ("select * from $comptbl order by SubSystem"); $sth -> execute; $dref = $sth -> fetchall_arrayref; -]
... $dref -> [$row][0] ...
I'd prefer to fetch the data one row at a time, how can I do this? For solution 1 you may write [$while $rref = $sth -> fetch $] .... [$endwhile$]
Solution 2 should work like this [- $dummy = $row ; $rref = $sth -> fetch -] ....
The table ends when the expression where $row is used in some way returns . So also there is no releation between $row and the fetch, both conditions are met. How to display arrays with undef values in it? ---------------------------------------------- I'm doing a search on a table where some of the columns have NULL and non-NULL values. DBIx::Recordset has no problem reading this values The problem is that I then tried to print these values out in a table using Embperl's table feature, like this. The problem is that I got 5 rows instead of the 15 that I was expected. I have been trying all kinds of tweaks to the arguments to the Search function and getting nowwhere, until I re-read the Embperl docs. Embperl will not print out a table row if one of the columns has an expression that is undefined. This is a problem since DBIx::Recordset (and DBI) natually uses undef to represent a NULL value for a column. So I made a slight modification to my embperl code.
$set[$row]{column_name1} $set[$row]{column_nameN}
. . . Now all 15 rows appear as expected, with "UNDEF" representing the NULL values in the database. Another way top solve you problem may be:
defined($set[$row]{column_name1}) ? $set[$row]{column_name1} : "UNDEF"$set[$row]{column_nameN} ? $set[$row]{column_nameN} : "UNDEF"
[- $r = $set[$row] -] . . . This will only refer one time to $row and the expression is defined, as long as the row could be fetched from the db. All NULL fields will be displayed as empty table cells. Escaping & Unescaping ===================== Escaping & Unescaping Input --------------------------- By default, Embperl removes all HTML tags from the Perl source. It does this because many high-end WYSIWYG HTML Editors (like MS Front Page) insert HTML tags like and in rather random places (like in the middle of your Perl code). This Embperl feature keeps things like [- $var = 1;
$foo = 2 -] permissable, so that you can enter Perl code while you mark up pages in an editor, all at once. In this example, Embperl would remove the unnecessary
tag and, therefore, make Perl happy. And if Perl is happy, we are all happy. It is not difficult to change this behavior, if you are the kind of person who codes HTML in an ascii editor (like vi or emacs). If you use a high-level HTML editor, you shouldn't have any problems with input escaping, because the editor will, for example, write a '<' as '<' in the HTML code. Embperl translates this back to '<' and therefore it knows that this wasn't an HTML tag which should be removed. Problems with input escaping only occur if you use an ascii editor. Then you will need to escape input (see the next section for details on how to do this). To see the exact steps taken by Embperl to process a Perl-laden document, please see the section `Inside Embperl|Embperl' in this node in the Embperl documentation. Ways To Escape Input: --------------------- 1. Escape it -> \

NOTE: Inside double quotes you will need to use \\ (double backslash), since Perl will remove the first Escape itself. Example: In most cases '\

' but inside double-quotes "\\" 2. Turn off Escaping for all input by setting the optRawInput in EMBPERL_OPTIONS 3. Learn to avoid using HTML tags inside Perl code. Once you get the hang of it, you'll love it. Here is one example of how to do it: [- $output = "Hello world" -] [+ $output +] write [- $output = "Hello world" -] this outputs Hello world or [+ $output +] this outputs Hello world And here is another example of how to do it: [- @a = ('a', 'b', 'c') ; foreach $i (0..2) { $output. = "" ; } -]
[+ $r -> {column_name1} +] [+ $r -> {column_nameN} +]
Row $a[$i]
[+ $output +]
The output here would be: Row aRow bRow c
The Embperl version is [- @a = ('a', 'b', 'c') ; -] " ;
Row [+ $a[$row] +]
The output will be " ; " ; " ;
Row a
Row b
Row c
And another: This elegant solution shows you how to take advantage of Embperl's ability to create dynamic tables: [- use DBI; my $dbh = DBI->connect("DBI:mysql:database:localhost","Username","Password") || die($!); $hstmt = $dbh->prepare("select ID, Heading from Shops order by Heading"); $hstmt->execute(); $dat = $hstmt->fetchall_arrayref() ; $hstmt->finish(); $dbh->disconnect(); -]
[+ $$dat[$row][$col] +]
This HTML code will then display the contents of the whole array. Escaping & Unescaping Output ---------------------------- Embperl will also escape the output - so

will be translated to <H1> To see the exact steps taken by Embperl to process a Perl-laden document, please see `Inside Embperl|Embperl' in this node in the Embperl documentation. Ways To Escape Output: ---------------------- 1. Escape it -> \\

(You need a double backslash \\, because the first one is removed by Perl and the second by Embperl. 2. set $escmode = 0 -> [- $escmode = 0 ; -] 3. set SetEnv EMBPERL_ESCMODE 0 in your srm.conf Debugging ========= I am having a hard time debugging Embperl code ---------------------------------------------- Have you, umm, checked the error log? ;) Have you tried setting debug flags higher by resetting EMBPERL_DEBUG in the server config files? (And still higher? :) dbgMem isn't usually very useful as it always outputs a lot of allocation. dbgFlushLog and dbgFlushOutput should be used if (and only if) you are debugging SIGSEGVs. For easy debugging, you can tell Embperl to display a link at the top of each page to your log file. Then every error displayed in an error page is a link to the corresponding position in the logfile, so you can easily find the place where something is going wrong For more on using HTML links to the Embperl error log, see `Embperl' in this node in the Embperldocs. Embperl is running slow. ------------------------ There are some debugging settings which may cause Embperl to drastically slow down. If you are done with debugging, set debugging bits back to normal. Also, using dbgFlushLog and dbgFlushOutput will make execution much slower. These are only intended for debugging SIGSEGVs. Never set all debugging bits! How can I improve Embperl's performance? ---------------------------------------- 1. Load Embperl at server startup. This will cause UNIX systems to only allocate memory once, and not for each child process. This reduces memory use, especially the need to swap additional memory. 2. Disable all unneeded debugging flags. You should never set dbgFlushLog dbgFlushOutput, dbgMem and dbgEvalNoCache in a production environment. 3. You may also want to take a look at the available options you can set via EMBPERL_OPTIONS. For example optDisableChdir, will speed up processing because it avoid the change directory before every request. Customizing =========== How can I fiddle with the default values? How can I override or alter this or that behavior? -------------------------------------------------------------------------------------------- Usually, defaults are set in a way that is likely to make most sense for a majority of users. As of version 1.0, Embperl allows much more flexibility in tweaking your own default values than before. Take a look at EMBERPL_OPTIONS. I'd like to (temporarily) disable some of Embperl's features. What can be customized? -------------------------------------------------------------------------------------- 1. Use optDisableHtmlScan to disable processing of html tags. If this is set, Embperl will only pay attention to these types of constructs: [+/-/!/$ .... $/!/-/+] 2. optDisableTableScan, optDisableInputScan and optDisableMetaScan can be used to disable individual parts of HTML processing. You may set these flags in your server config, or at runtime: [+ $optDisableHtmlScan = 1 +] foo
[+ $optDisableHtmlScan = 0 +] How can I disable auto-tables? ------------------------------ Set optDisableTableScan in EMBPERL_OPTIONS How can I change predefined values like $escmode from my Toolbox module? ------------------------------------------------------------------------ $HTML::Embperl::escmode = 0 ; Predefined values in Embperl are simply aliases for $HTML::Embperl::foo (for instance, $escmode is an alias for $HTML::Embperl::escmode) How can I customize the header that Embperl is sending? ------------------------------------------------------- You'll find the answer to this and many other header issues in the `"Common Questions"' in this node section. How can I use a different character set? ASCII values over 128 are showing up as ? (question marks)! ---------------------------------------------------------------------------------------------------- This is caused by the translation of characters to HTML escapes. Embperl translates them to escapes which are then sometimes not understood by the browser, which may display a "?" instead, because it is using the wrong character set. If you want to use the escaping features of Embperl in this case, you have to adapt the file `epchar.c' to your character set. The distribution contain already an `epchar.c.iso-latin-2' from Jiri Novak which is an replacement for epchar.c for the iso-8859-2 (iso-latin-2) character set. If you want to use iso-latin-2, simply renmae `epchar.c.iso-latin-2' to `epchar.c'. There is also an file `epchar.c.min' from Sangmook Yi, which leaves all chars above 128 untouch, which is especialy usefull for two byte charsets. This file contains three tables: Char2Html [] Convert characters to html escape Char2Url [] Convert characters to url escapes (do not change this one!!) Html2Char [] Convert html escapes to characters You need to change the first and the last tables. Do not change the second table!! Please make sure Char2Html contains one entry (and only one entry) for each of the 256 ascii codes (with none left undefined) in the right order, and that Html2Char is sorted by html escape. If somebody generates new tables for national character sets, please send a copy to the author, so it can be included it in future versions of Embperl. Optimizing & Fine-Tuning ======================== How can I be sure that Embperl is re-compiling my page template (and the Perl blocks contained in it) only when needed, and not each time? ------------------------------------------------------------------------------------------------------------------------------------------ As long as your input file's time stamp stays the same, Embperl will only compile the script the first time it's called. When you use the Execute function, Embperl will recompile the script only if the input file and mtime paramenters have changed since the last time the script was called. You can verfiy this by setting dbgDefEval. Now, every time a Perl block is compiled, Embperl logs a line starting with DEF:. You will see this line only on the first request. The cached Perl blocks are stored as a set of subroutines in the namespace of the document. (HTML::Embperl::DOC::_ is the default) Look at the logfile to see the actual name. How can I pre-compile pages, so that each httpd child doesn't have to have its own separate copies of the pre-compiled pages? ------------------------------------------------------------------------------------------------------------------------------ To pre-compile pages, just call Execute once for every file at server startup in your startup.pl file. In what namespace does Embperl store pre-compiled data? ------------------------------------------------------- The cached Perl blocks are stored as a set of subroutines in the namespace of the document. (HTML::Embperl::DOC::_ for default) Look at the logfile to see the actual name. I have both Embperl and ordinary Perl processes running. The docs say that Embperl uses a CGI.pm instance in its own internal processing, but they don't say how to control it. How can I get Embperl to use *my* CGI.pm object instead of creating its own? -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Embperl only creates a CGI objects to process multipart form data (from fileupload). In all other cases Embperl doesn't use CGI.pm. There is no way to change this behaviour, or access the internal CGI object in case of file-uploads. Additional Help =============== Where can I get more help? -------------------------- You can get free support on the mod_perl mailing list. If you need commercial support (with a guarantee for response time or a solution) for Embperl, or if you want a web site where you can run your Embperl/mod_perl scripts without setting up your own web server, please send email to info@ecos.de. Please also see the section `Embperl' in this node in the Embperl documentation. SEE ALSO ======== some links here AUTHOR ====== Gerald Richter Edited by Nora Mikes