Embperl - building dynamic websites with Perl


Predefined variables
[ << Prev: Variable scope and cleanup ] [ Content ] [ Next: Session handling >> ]

Embperl has some special variables which have a predefined meaning.



%ENVtop

Contains the environment as seen from a CGI script.



$epreqtop

Contains a reference to the Embperl request object. This is the same as adding $epreq = shift at the top of each page.



$epapptop

Contains a reference to the Embperl application object. This is the same as $epreq - app> would return.



%fdattop

Contains all the form data sent to the script by the calling form. The NAME attribute builds the key and the VALUE attribute is used as the hash value. Embperl doesn't care if it is called with the GET or POST method, but there may be restrictions on the length of parameters using GET -- not from Embperl, but perhaps from the web server, especially if you're using Embperl's CGI mode -- it is safer to use POST.

If multiple fields with the same name are sent to a Embperl page, they will put in the same hash element and separated be tabs. You can split it up in an array, by writing:

  @array = split (/\t/, $fdat{'fieldname'}) ;

Embperl also supports ENCTYPE multipart/form-data, which is used for file uploads. The entry in %fdat corresponding to the file field will be a filehandle, as with CGI.pm. (Embperl uses CGI.pm internally to process forms encoded with multipart/form-data.)

File upload example:

  HTML page:

    <FORM METHOD="POST" ENCTYPE="multipart/form-data">
      <INPUT TYPE="FILE" NAME="ImageName">
    </FORM>

  Embperl ACTION:

    [- if (defined $fdat{ImageName}) {
         open FILE, "> /tmp/file.$$";
	 print FILE $buffer
           while read($fdat{ImageName}, $buffer, 32768);
         close FILE;
       }
    -]
	

When you have installed CGI.pm 2.46 or above, you may also retrieve the filename (local filename, as it was on the browser side) and the information provided by the CGI.pm uploadInfo function. To get the filename, simply print out the value of the corresponding %fdat entry, instead of using it as a filehandle. To get the uploadInfo use the fieldname with a dash in front of it:

  Example:

  # ImageName is the NAME of the field, you must replace it with whatever 
  # name is given in your HTML code
  Filename:      [+ $fdat{ImageName} +] <br>
  Content-Type:  [+ $fdat{-ImageName} -> {'Content-Type'} +] <br>

NOTE: The way uploadInfos are accessed before 1.2b11 is not supported anymore.

NOTE: This works the other way as well: any input fields with names that are %fdat keys, and without values, will have their values automatically set to the appropriate %fdat value. See HTML Tags INPUT/OPTION/TEXTAREA.



@ffldtop

Contains all the field names in the order in which they were sent by the browser. This is normally -- but not necessarily -- the order in which they appear in your form.



%idattop

Contains all the values from all input tags processed so far.



%udat (only 1.2b1 or higher)top

You can use %udat to store per user data. As long as you don't use %udat, nothing happens, but as soon as you write anything to %udat, Embperl creates a session id and sends it via a cookie to the browser. The data you have written to %udat is stored by Apache::Session. The next time the same user request an Embperl page, the browser sends the cookie with the session id back and Embperl fills the %udat hash from Apache::Session with the same values as you have stored for that user. (See also Session handling)



%mdat (only 1.2b2 or higher)top

You can use %mdat to store per module/page data. As long as you don't use %mdat, nothing happens, but as soon as you write anything to %mdat, Embperl creates a session id and stores the data via Apache::Session. The next time any user hits the same Embperl page, Embperl fill the %mdat hash from Apache::Session with the same values as you have stored within the last request to that page. (See also Session handling)



$row, $coltop

Row and column counts for use in dynamic tables. (See HTML tag table.)



$maxrow, $maxcoltop

Maximum number of rows or columns to display in a table. To prevent endless loops, $maxrow defaults to 100 and $maxcol to 10. (See HTML tag table.)



$cnttop

Contains the number of table cells displayed so far. (See HTML tag table.)



$tabmodetop

Determines how the end of a dynamic table is detected. Tables are always limited to the size specified in $maxrow and $maxcol, but can be ended early when the row ($row) and column ($col) variables become undefined. $tabmode operates as follows:

 

$tabmode = 1

 

End table looping when any one of the expressions in the table row using $row returns undefined. The row containing the undefined expression is not displayed. Only those expressions are observed which contain an access to the variable $row.

 

$tabmode = 2

 

End when an expression with $row becomes undefined. The row containing the undefined expression is displayed.

 

$tabmode = 4

 

End when $maxrow rows have been displayed.

end of row

 

$tabmode = 16

 

End table column looping when any one of the expressions in the table column using $col returns undefined. The column containing the undefined expression is not displayed. Only those expressions are observed which contain an access to the variable $col.

 

$tabmode = 32

 

End when an expression with $col becomes undefined. The column containing the undefined expression is displayed.

 

$tabmode = 64

 

End when $maxcol columns have been displayed.

The default is 17, which is correct for all sort of arrays. You should rarely need to change it. The two values can be added together.



$escmodetop

Turn HTML and URL escaping on and off. The default is on ($escmode = 3).

NOTE: Normally you can disable escaping by preceding the item that normally is escaped with a backslash. While this is a handy thing, it could be very dangerous in situations, where content that is inserted by some user is redisplayed, because they can enter arbitrary HTML and precede them with a backslash to avoid correct escaping when their input is redisplayed again. To avoid this problem, add 4 to the values below. This will cause Embperl to ignore the backslash when it does output escaping at all. (only 1.3b4 and above)

NOTE 2: If you want to output binary data, you must set the escmode to zero. (only 1.3b6 and above)

 

$escmode = 8 (or 15) (2.0b4 and above)

 

The result of a Perl expression is always XML-escaped (e.g., `>' becomes `&gt;' and ' become &apos;).

 

$escmode = 3 (or 7)

 

The result of a Perl expression is HTML-escaped (e.g., `>' becomes `&gt;') in normal text and URL-escaped (e.g., `&' becomes `%26') within of A, EMBED, IMG, IFRAME, FRAME and LAYER tags.

 

$escmode = 2 (or 6)

 

The result of a Perl expression is always URL-escaped (e.g., `&' becomes `%26').

 

$escmode = 1 (or 5)

 

The result of a Perl expression is always HTML-escaped (e.g., `>' becomes `&gt;').

 

$escmode = 0

 

No escaping takes place.

SEE ALSO: Configuration directive EMBPERL_INPUT_ESCMODE (was optRawInput in Embperl 1.3.x)



$req_rectop

This variable is only available when running under control of mod_perl. It contains the request record needed to access the Apache server API. See perldoc Apache2::RequestRec for more information.



LOGtop

This is the filehandle of the Embperl logfile. By writing `print LOG "something"' you can add lines to the logfile. NOTE: The logfile line should always start with the pid of the current process and continue with a four-character signature delimited by a ':', which specifies the log reason.

Example: print LOG "[$$]ABCD: your text\n" ;

If you are writing a module for use under Embperl you can say

    tie *LOG, 'Embperl::Log';

to get a handle by which you can write to the Embperl logfile.



OUTtop

This filehandle is tied to Embperl's output stream. Printing to it has the same effect as using the [+ ... +] block. (See also optRedirectStdout)



@paramtop

Will be setup by the 'param' parameter of the Execute function. Could be used to pass parameters to an Embperl document and back. (see Execute for further docs)



%http_headers_out (only 1.2b10 and above)top

You can put any http headers you want to send into this hash.

If you set a location header, Embperl will automatically set the status to 301 (Redirect). Example:

  [- $http_headers_out{'Location'} = "https://www.actevy.io/embperl/" -]

however, it is possible to specify a two element array for Location, the second element of which gives the desired HTTP status:

  [- $http_headers_out{Location} = [ "https://www.actevy.io/embperl/", 303 ]; -]

Starting with version 1.3.2 all headers with the exception of "Content-Type" can take multiple values. For instance, if you wanted to set two cookies, you can proceed as follows:

  [- $http_headers_out{'Set-Cookie'} = 
      ['name=cook1;value=2;','name=cook2;value=b'] ; -]

If you supply multiple values for "Location" or "Content-Type" via an array reference, then Embperl will simply use the first in the list. Empty arrays will be ignored. For instance, the following will neither change the status to 301 nor create a Location: line in the HTTP headers:

  [- $http_headers_out{'Location'} = [] ; -]

see also META HTTP-EQUIV=



$optXXX $dbgXXXtop

All options (see EMBPERL_OPTIONS) and all debugging flags (see EMBPERL_DEBUG) can be read and most of them can be set by the corresponding variables. See perldoc Config.

  Example:

    [- $dbgInput = 1 -] 
    

    [- $dbgInput = 0 -] 
    [+ $dbgCmd +] # Output the state of the dbgCmd flag


%CLEANUPtop

Embperl cleanups up only variables with are defined within the Embperl page. If you want Embperl to cleanup additional variables you can add them to the hash %CLEANUP, with the key set to the variable name and the value set to one. The other way you could prevent Embperl from cleaning up some variables, is by adding them to this hash, with values of zero.



%CLEANUPFILE (1.2b6+)top

Same purpose as %CLEANUP, but you may add filenames. All variables defined inside that file will be cleaned up.


[ << Prev: Variable scope and cleanup ] [ Content ] [ Next: Session handling >> ]


© 1997-2023 Gerald Richter / actevy