|
PLP::Functions - Functions that are available in PLP documents |
PLP::Functions - Functions that are available in PLP documents
The functions are exported into the PLP::Script package that is used by PLP documents. Although uppercased letters are unusual in Perl, they were chosen to stand out.
Most of these functions are context-hybird. Before using them, one should know about contexts in Perl. The three major contexts are: void, scalar and list context. You'll find more about context in the perlfunc manpage.
Some context examples:
print foo(); # foo is in list context (print LIST)
foo(); # foo is in void context
$bar = foo(); # foo is in scalar context
@bar = foo(); # foo is in list context
length foo(); # foo is in scalar context (length EXPR)
<: :>). As with Perl's do, the file is evaluated in its own lexical file scope, so lexical variables (my variables) are not shared. PLP's <(filename)> includes at compile-time, is faster and is doesn't create a lexical scope (it shares lexical variables).
Include can be used recursively, and there is no depth limit:
<!-- This is crash.plp -->
<:
include 'crash.plp';
# This example will loop forever,
# and dies with an out of memory error.
# Do not try this at home.
:>
Include.
<html><body> <!-- this is template.plp -->
<: PLP_END { :>
</body></html>
<: } :>
<(template.plp)> <!-- this is index.plp -->
Hello, world!
You should use this function instead of Perl's built-in END blocks, because those do not work properly with mod_perl.
In void context, changes the values of the given variables. In other contexts, returns the changed versions.
<: print Entity($user_input); :>
Be warned that this function also HTMLizes consecutive whitespace and newlines (using and <br> respectively). For simple escaping, use the XML::Quote manpage. To escape high-bit characters as well, use the HTML::Entities manpage.
In void context, changes the values of the given variables. In other contexts, returns the changed versions.
<a href="/foo.plp?name=<:= EncodeURI($name) :>">Link</a>
Note that the following reserved characters are not percent-encoded, even though they may have a special meaning in URIs:
/ ? : @ $
This should be safe for escaping query values (as in the example above), but it may be a better idea to use the URI::Escape manpage instead.
In void context, changes the values of the given variables. In other contexts, returns the changed versions.
You are visitor number <:= Counter('counter.txt') :>.
In void context, changes the value of the given variable. In other contexts, returns the changed version.
<: print AutoURL(Entity($user_input)); :>
Juerd Waalboer <juerd@cpan.org>
Current maintainer: Mischa POSLAWSKY <shiar@cpan.org>
|
PLP::Functions - Functions that are available in PLP documents |