| 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 |
[- $optRawInput = 1 -] |
| 10 |
|
| 11 |
[- $tst1 = '<P>Here is some text</P>' . "\n" ; -] |
| 12 |
|
| 13 |
|
| 14 |
<H1> 1.) Include from memory</H1> |
| 15 |
|
| 16 |
[- Execute ({input => \$tst1, |
| 17 |
mtime => 1, |
| 18 |
inputfile => 'Some text', |
| 19 |
}) ; |
| 20 |
-] |
| 21 |
|
| 22 |
<H1> 2.) Include from memory with some Embperl code</H1> |
| 23 |
|
| 24 |
[- Execute ({input => \('[- @ar = (a1, b2, c3) -' . ']<table><tr><td>[+$ar[$col]+]</td> </tr> </table> </P>' . "\n" ), |
| 25 |
mtime => 1, |
| 26 |
inputfile => 'table', |
| 27 |
}) ; |
| 28 |
-] |
| 29 |
|
| 30 |
<H1> 3.) Include from memory with passing of variables</H1> |
| 31 |
|
| 32 |
|
| 33 |
[- $MyPackage::Interface::Var = 'Some Var' ; -] |
| 34 |
|
| 35 |
[- Execute ({input => \"<P>Transfer some vars [+ \$Var +] !</P>\n" , |
| 36 |
inputfile => 'Var', |
| 37 |
mtime => 1, |
| 38 |
'package' => 'MyPackage::Interface', |
| 39 |
}) ; |
| 40 |
-] |
| 41 |
|
| 42 |
<H1> 4.) Change the variable, but not the code</H1> |
| 43 |
|
| 44 |
[- |
| 45 |
|
| 46 |
$MyPackage::Interface::Var = 'Do it again' ; |
| 47 |
|
| 48 |
# code is the same, so give the same mtime and inputfile to avoid recompile |
| 49 |
# Note you get problems is you change the code, but did not restart the server or |
| 50 |
# change the value in mtime. So make sure if you change something also change mtime! |
| 51 |
|
| 52 |
Execute ({input => \"<P>Transfer some vars [+ \$Var +] !</P>\n", |
| 53 |
inputfile => 'Var2', |
| 54 |
mtime => 1, |
| 55 |
'package' => 'MyPackage::Interface', |
| 56 |
req_rec => $req_rec}) ; |
| 57 |
-] |
| 58 |
<H1> 5a.) Use method -> param to pass parameters</H1> |
| 59 |
|
| 60 |
|
| 61 |
[- |
| 62 |
Execute ({input => \"<P>Use method -> param to transfer some data ([+ do { \$p = shift -> component -> param -> param ; \"\@\$p\" } +]) !</P>\n", |
| 63 |
inputfile => 'Parammethod', |
| 64 |
param => [1, 2, 3, 4] } |
| 65 |
) ; |
| 66 |
-] |
| 67 |
|
| 68 |
<H1> 5.) Use \@param to pass parameters</H1> |
| 69 |
|
| 70 |
|
| 71 |
[- |
| 72 |
Execute ({input => \"<P>Use \@param to transfer some data ([+ \"\@param\" +]) !</P>\n", |
| 73 |
inputfile => 'Param', |
| 74 |
param => [1, 2, 3, 4] } |
| 75 |
) ; |
| 76 |
-] |
| 77 |
|
| 78 |
|
| 79 |
<H1> 6.) Use \@param to pass parameters and return it</H1> |
| 80 |
|
| 81 |
[- @p = ('vara', 'varb') ; -] |
| 82 |
|
| 83 |
<H3> $p[0] is [+ $p[0] +] and $p[1] is [+ $p[1] +]<H3> |
| 84 |
|
| 85 |
[- |
| 86 |
Execute ({input => \('<P>Got data in @param ([+ "@param" +]) !</P>[- $param[0] = "newA" ; $param[1] = "newB" ; -' . ']<P>Change data in @param to ([+ "@param" +]) !</P>' . "\n"), |
| 87 |
inputfile => 'Param & Return', |
| 88 |
req_rec => $req_rec, |
| 89 |
param => \@p } |
| 90 |
) ; |
| 91 |
-] |
| 92 |
|
| 93 |
<H3> $p[0] is now [+ $p[0] +] and $p[1] is now [+ $p[1] +] <H3> |
| 94 |
|
| 95 |
<H1> 7.) Presetup \%fdat and \@ffld</H1> |
| 96 |
|
| 97 |
[- |
| 98 |
|
| 99 |
%myfdat = ('test' => 'value', |
| 100 |
'fdat' => 'text') ; |
| 101 |
|
| 102 |
@myffld = sort keys %myfdat ; |
| 103 |
|
| 104 |
Execute ({input => \('<P><table><tr><td>[+ $ffld[$row] +]</td><td>[+ do { local $^W = 0 ; $fdat{$ffld[$row]} } +]</td></tr></table></P>' . "\n") , |
| 105 |
inputfile => 'fdat & ffld', |
| 106 |
req_rec => $req_rec, |
| 107 |
fdat => \%myfdat, |
| 108 |
ffld => \@myffld} |
| 109 |
) ; |
| 110 |
|
| 111 |
-] |
| 112 |
|
| 113 |
|
| 114 |
<H1> 7a.) Presetup my \%fdat and my \@ffld</H1> |
| 115 |
|
| 116 |
[- |
| 117 |
|
| 118 |
my %myfdat = ('test1' => 'value1', |
| 119 |
'fdat1' => 'text1') ; |
| 120 |
|
| 121 |
my @myffld = sort keys %myfdat ; |
| 122 |
|
| 123 |
Execute ({input => \('<P><table><tr><td>[+ $ffld[$row] +]</td><td>[+ do { local $^W = 0 ; $fdat{$ffld[$row]} } +]</td></tr></table></P>' . "\n") , |
| 124 |
inputfile => 'fdat & ffld', |
| 125 |
req_rec => $req_rec, |
| 126 |
fdat => \%myfdat, |
| 127 |
ffld => \@myffld} |
| 128 |
) ; |
| 129 |
|
| 130 |
-] |
| 131 |
|
| 132 |
<H1> 7b.) Presetup \%fdat</H1> |
| 133 |
|
| 134 |
[- |
| 135 |
%myfdat = ('test2' => 'value2', |
| 136 |
'fdat2' => 'text2') ; |
| 137 |
|
| 138 |
#@myffld = sort keys %myfdat ; |
| 139 |
Execute ({input => \('<P><table><tr><td>[+ $ffld[$row] +]</td><td>[+ do { local $^W = 0 ; $fdat{$ffld[$row]} } +]</td></tr></table></P>' . "\n") , |
| 140 |
inputfile => 'fdat & ffld', |
| 141 |
req_rec => $req_rec, |
| 142 |
fdat => \%myfdat,} |
| 143 |
) ; |
| 144 |
|
| 145 |
-] |
| 146 |
|
| 147 |
|
| 148 |
<H1> 7c.) Presetup \@ffld</H1> |
| 149 |
|
| 150 |
[- |
| 151 |
%myfdat = ('test3' => 'value3', |
| 152 |
'fdat3' => 'text3') ; |
| 153 |
|
| 154 |
@myffld = sort keys %myfdat ; |
| 155 |
Execute ({input => \('<P><table><tr><td>[+ $ffld[$row] +]</td><td>[+ do { local $^W = 0 ; $fdat{$ffld[$row]} } +]</td></tr></table></P> @ffld = [+ "@ffld" +]' . "\n") , |
| 156 |
inputfile => 'ffld', |
| 157 |
req_rec => $req_rec, |
| 158 |
ffld => \@myffld} |
| 159 |
) ; |
| 160 |
|
| 161 |
-] |
| 162 |
|
| 163 |
|
| 164 |
<H1> 8a.) Include a file</H1> |
| 165 |
|
| 166 |
[- Execute ({inputfile => '../inc.htm', options => 0, input_escmode => 7, }) -] |
| 167 |
|
| 168 |
<H1> 8b.) Include again the same file </H1> |
| 169 |
|
| 170 |
[- Execute ({inputfile => '../inc.htm', options => 0, input_escmode => 7, }) -] |
| 171 |
|
| 172 |
<H1> 9.) Include a file and return output in a scalar</H1> |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
[- Execute ({inputfile => '../inc.htm', |
| 177 |
output => \$out, |
| 178 |
options => 0, input_escmode => 7, |
| 179 |
req_rec => $req_rec}) ; |
| 180 |
-] |
| 181 |
|
| 182 |
<H3> [+ $out +] </H3> |
| 183 |
|
| 184 |
|
| 185 |
<H1> 10.) Include inside a table</H1> |
| 186 |
|
| 187 |
[- @a = ('m1', 'm2', 'm3') -] |
| 188 |
|
| 189 |
<table> |
| 190 |
<tr> |
| 191 |
<td> |
| 192 |
[+ $a[$row] +] : [- Execute ({inputfile => '../incsub.htm', req_rec => $req_rec, param => [$a[$row], 'main']}) -] |
| 193 |
</td> |
| 194 |
</tr> |
| 195 |
</table> |
| 196 |
|
| 197 |
|
| 198 |
<H1> 11.) Include a file with parameters</H1> |
| 199 |
|
| 200 |
[- Execute ('../incparam.htm', 0, 'B', 'three', 'dddd', '555') -] |
| 201 |
|
| 202 |
<H1> 12.) Include a file and write outputfile</H1> |
| 203 |
|
| 204 |
[# - Execute ({inputfile => '../inc.htm', |
| 205 |
outputfile => "../../tmp/incout.htm", |
| 206 |
}) ; |
| 207 |
- #] |
| 208 |
|
| 209 |
<H1> 12.) Done :-)</H1> |
| 210 |
|
| 211 |
<br> |
| 212 |
|
| 213 |
|
| 214 |
<p><hr> |
| 215 |
|
| 216 |
<small>Embperl (c) 1997-2005 G.Richter</small> |
| 217 |
|
| 218 |
</body> |
| 219 |
</html> |