]> mj.ucw.cz Git - temple.git/blobdiff - test
temple -e
[temple.git] / test
diff --git a/test b/test
index c857c413f2add18f76a62655cecadabe9369c283..90ab406fd7edad2a4fe79b50a8594650f3d58517 100644 (file)
--- a/test
+++ b/test
@@ -19,21 +19,30 @@ won't be broken@
 @# If you want to write the "@" character, just write it twice:
 @@
 
-@# You can embed any perl code in your text:
-@[foreach $x (1..10) { print "$x "; } ]
+@# You can embed any perl code in your text (use the "out" function to
+@# write to the templater's output):
+@[foreach $x (1..10) { out "$x "; } ]
 
 @# Or if you use @{...}, then the value of the last expression executed
 @# gets printed automatically:
 @{"1+2+3 = " . (1+2+3)}
 
-@# You can also interpolate perl variables by using @$variable:
+@# You can also interpolate perl variables in the T:: namespace by using @$variable:
 I was run as @$0.
 
-@# It is possible to call any perl functions (result will be discarded):
-@print("One", "Two", "Three\n")
+@# It is possible to call any perl functions
+@# (any result other than undef will be printed automatically)
+@# Use `out' to write to the output stream
+@out("One", "Two", "Three\n")
 
 @# Or do the same with parameters running up to the end of the line:
-@print "Four", "Five", "Six\n"
+@out "Four", "Five", "Six\n"
+
+@# Of course you can define your own functions (they live in the T:: namespace)
+@[ sub quork($) { my ($arg) = @_;
+return "Thus quorkth the Penguin: $arg";
+} ]
+@quork("404!")
 
 @# There are also some conditionals (you can use any perl expressions):
 @if 1
@@ -59,12 +68,25 @@ four
 @load "test3"
 
 @# This one is tricky:
-@print("z\n", <<EOF
+@out("z\n", <<EOF
 a
 b
 c
 EOF
 )
 
+@# The template engine can be run from any Perl code (including Perl embedded
+@# in another template), e.g., in a templated CGI script.
+@[
+       UCW::Temple::process_string('I still see I was run as @$0');
+]
+
+@# Additionally, you can pass a hash of arguments to process_string() and use
+@# the @(name) construct to expand them:
+@[
+       UCW::Temple::process_string('@(count) upon a @(time) dreary...',
+               { 'count' => 'Once', 'time' => 'midnight' } );
+]
+
 @# We are done:
 Finis.