| 1 |
|
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<title>Embperl Tests - Include other Embperl pages via Execute</title> |
| 5 |
</head> |
| 6 |
|
| 7 |
<h1>Embperl Tests - Include other Embperl pages via Execute</h1> |
| 8 |
|
| 9 |
|
| 10 |
[- $optRawInput = 1 -] |
| 11 |
|
| 12 |
[- $tst1 = '<P>Here is some text</P>' ; -] |
| 13 |
|
| 14 |
|
| 15 |
<H1> 1.) Include from memory</H1> |
| 16 |
|
| 17 |
[- Execute ({input => \$tst1, |
| 18 |
mtime => 1, |
| 19 |
inputfile => 'Some text', |
| 20 |
}) ; |
| 21 |
-] |
| 22 |
|
| 23 |
<H1> 2.) Include from memory with some Embperl code</H1> |
| 24 |
|
| 25 |
[- Execute ({input => \('[- @ar = (a1, b2, c3) -' . ']<table><tr><td>[+$ar[$col]+]</td> </tr> </table> </P>'), |
| 26 |
mtime => 1, |
| 27 |
inputfile => 'table', |
| 28 |
}) ; |
| 29 |
-] |
| 30 |
|
| 31 |
<H1> 3.) Include from memory with passing of variables</H1> |
| 32 |
|
| 33 |
|
| 34 |
[- $MyPackage::Interface::Var = 'Some Var' ; -] |
| 35 |
|
| 36 |
[- Execute ({input => \'<P>Transfer some vars [+ $Var +] !</P>', |
| 37 |
inputfile => 'Var', |
| 38 |
mtime => 1, |
| 39 |
'package' => 'MyPackage::Interface', |
| 40 |
}) ; |
| 41 |
-] |
| 42 |
|
| 43 |
<H1> 4.) Change the variable, but not the code</H1> |
| 44 |
|
| 45 |
[- |
| 46 |
|
| 47 |
$MyPackage::Interface::Var = 'Do it again' ; |
| 48 |
|
| 49 |
# code is the same, so give the same mtime and inputfile to avoid recompile |
| 50 |
# Note you get problems is you change the code, but did not restart the server or |
| 51 |
# change the value in mtime. So make sure if you change something also change mtime! |
| 52 |
|
| 53 |
Execute ({input => \'<P>Transfer some vars [+ $Var +] !</P>', |
| 54 |
inputfile => 'Var2', |
| 55 |
mtime => 1, |
| 56 |
'package' => 'MyPackage::Interface', |
| 57 |
req_rec => $req_rec}) ; |
| 58 |
-] |
| 59 |
|
| 60 |
<H1> 5.) Use \@param to pass parameters</H1> |
| 61 |
|
| 62 |
|
| 63 |
[- |
| 64 |
Execute ({input => \'<P>Use @param to transfer some data ([+ "@param" +]) !</P>', |
| 65 |
inputfile => 'Param', |
| 66 |
param => [1, 2, 3, 4] } |
| 67 |
) ; |
| 68 |
-] |
| 69 |
|
| 70 |
<H1> 6.) Use \@param to pass parameters and return it</H1> |
| 71 |
|
| 72 |
[- @p = ('vara', 'varb') ; -] |
| 73 |
|
| 74 |
<H3> $p[0] is [+ $p[0] +] and $p[1] is [+ $p[1] +]<H3> |
| 75 |
|
| 76 |
[- |
| 77 |
Execute ({input => \('<P>Got data in @param ([+ "@param" +]) !</P>[- $param[0] = "newA" ; $param[1] = "newB" ; -' . ']<P>Change data in @param to ([+ "@param" +]) !</P>'), |
| 78 |
inputfile => 'Param & Return', |
| 79 |
req_rec => $req_rec, |
| 80 |
param => \@p } |
| 81 |
) ; |
| 82 |
-] |
| 83 |
|
| 84 |
<H3> $p[0] is now [+ $p[0] +] and $p[1] is now [+ $p[1] +] <H3> |
| 85 |
|
| 86 |
<H1> 7.) Presetup \%fdat and \@ffld</H1> |
| 87 |
|
| 88 |
[- %myfdat = ('test' => 'value', |
| 89 |
'fdat' => 'text') ; |
| 90 |
|
| 91 |
@myffld = sort keys %myfdat ; |
| 92 |
|
| 93 |
Execute ({input => \'<P><table><tr><td>[+ $ffld[$row] +]</td><td>[+ do { local $^W = 0 ; $fdat{$ffld[$row]} } +]</td></tr></table></P>', |
| 94 |
inputfile => 'fdat & ffld', |
| 95 |
req_rec => $req_rec, |
| 96 |
fdat => \%myfdat, |
| 97 |
ffld => \@myffld} |
| 98 |
) ; |
| 99 |
|
| 100 |
-] |
| 101 |
|
| 102 |
<H1> 8a.) Include a file</H1> |
| 103 |
|
| 104 |
[- Execute ('inc.htm') -] |
| 105 |
|
| 106 |
<H1> 8b.) Include again the same file </H1> |
| 107 |
|
| 108 |
[- Execute ('inc.htm') -] |
| 109 |
|
| 110 |
<H1> 9.) Include a file and return output in a scalar</H1> |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
[- Execute ({inputfile => 'inc.htm', |
| 115 |
output => \$out, |
| 116 |
req_rec => $req_rec}) ; |
| 117 |
-] |
| 118 |
|
| 119 |
<H3> [+ $out +] </H3> |
| 120 |
|
| 121 |
|
| 122 |
<H1> 10.) Include inside a table</H1> |
| 123 |
|
| 124 |
[- @a = ('m1', 'm2', 'm3') -] |
| 125 |
|
| 126 |
<table> |
| 127 |
<tr> |
| 128 |
<td> |
| 129 |
[+ $a[$row] +] : [- Execute ({inputfile => 'incsub.htm', req_rec => $req_rec, param => [$a[$row], 'main']}) -] |
| 130 |
</td> |
| 131 |
</tr> |
| 132 |
</table> |
| 133 |
|
| 134 |
|
| 135 |
<H1> 11.) Include a file with parameters</H1> |
| 136 |
|
| 137 |
[- Execute ('incparam.htm', 0, 'B', 'three', 'dddd', '555') -] |
| 138 |
|
| 139 |
<H1> 12.) Include a file and write outputfile</H1> |
| 140 |
|
| 141 |
[# - Execute ({inputfile => 'inc.htm', |
| 142 |
outputfile => "../tmp/incout.htm", |
| 143 |
}) ; |
| 144 |
- #] |
| 145 |
|
| 146 |
|
| 147 |
<H1> 12.) Done :-)</H1> |
| 148 |
|
| 149 |
<br> |
| 150 |
|
| 151 |
|
| 152 |
<p><hr> |
| 153 |
|
| 154 |
<small>HTML::Embperl (c) 1997-1998 G.Richter</small> |
| 155 |
|
| 156 |
</body> |
| 157 |
</html> |