Debian Codegraph @

test/html/registry/Execute.htm

raw
1 #
2 # Example for using Embperl::Execute
3 #
4 # run this under mod_perl / Apache::Registry
5 #
6
7
8 use Embperl ;
9
10 my($r) = @_;
11
12 # workaround for broken $r -> chdir_file in Apache::Registry on ActiveState perl
13 use Cwd ;
14 use File::Basename ;
15 if ($Embperl::modperlapi < 2)
16 {
17 eval { require Apache::compat } ;
18 $@ = '' ;
19 }
20 else
21 {
22 eval { require Apache2::compat } ;
23 $@ = '' ;
24 }
25
26 my $fn = $r -> filename ;
27 chdir(dirname ($fn)) ;
28
29
30 $Embperl::DebugDefault = 0xffffdffd ;
31
32
33 $tst1 = '<P>Here is some text</P>' ;
34
35 $r -> status (200) ;
36 $r -> send_http_header () ;
37
38 print "<HTML><TITLE>Test for Embperl::Execute</TITLE><BODY>\n" ;
39 print "<H1> 1.) Include from memory</H1>\n" ;
40
41 Embperl::Execute ({input => \$tst1,
42 mtime => 1,
43 inputfile => 'Some text',
44 req_rec => $r}) ;
45
46
47 print "\n<H1> 2.) Include from memory with some Embperl code</H1>\n" ;
48
49 Embperl::Execute ({input => \'[- @ar = (a1, b2, c3) -]<table><tr><td>[+$ar[$col]+]</td> </tr> </table> </P>',
50 mtime => 1,
51 inputfile => 'table',
52 req_rec => $r}) ;
53
54 print "\n<H1> 3.) Include from memory with passing of variables</H1>\n" ;
55
56
57 $MyPackage::Interface::Var = 'Some Var' ;
58
59 Embperl::Execute ({input => \'<P>Transfer some vars [+ $Var +] !</P>',
60 inputfile => 'Var',
61 mtime => 1,
62 'package' => 'MyPackage::Interface',
63 req_rec => $r}) ;
64
65 print "\n<H1> 4.) Change the variable, but not the code</H1>\n" ;
66
67 $MyPackage::Interface::Var = 'Do it again' ;
68
69 # code is the same, so give the same mtime and inputfile to avoid recompile
70 # Note you get problems is you change the code, but did not restart the server or
71 # change the value in mtime. So make sure if you change something also change mtime!
72
73 Embperl::Execute ({input => \'<P>Transfer some vars [+ $Var +] !</P>',
74 inputfile => 'Var2',
75 mtime => 1,
76 'package' => 'MyPackage::Interface',
77 req_rec => $r}) ;
78
79
80 print "\n<H1> 5.) Use \@param to pass parameters</H1>\n" ;
81
82
83 Embperl::Execute ({input => \'<P>Use @param to transfer some data ([+ "@param" +]) !</P>',
84 inputfile => 'Param',
85 debug => 0xffffdffd,
86 req_rec => $r,
87 param => [1, 2, 3, 4] }
88 ) ;
89
90
91 print "\n<H1> 6.) Use \@param to pass parameters and return it</H1>\n" ;
92
93
94 my @p = ('vara', 'varb') ;
95
96 print "\n<H3> \$p[0] is $p[0] and \$p[1] is $p[1]<H3>" ;
97
98 Embperl::Execute ({input => \'<P>Got data in @param ([+ "@param" +]) !</P>[- $param[0] = "newA" ; $param[1] = "newB" ; -]<P>Change data in @param to ([+ "@param" +]) !</P>',
99 inputfile => 'Param & Return',
100 req_rec => $r,
101 param => \@p }
102 ) ;
103
104 print "\n<H3> \$p[0] is now $p[0] and \$p[1] is now $p[1]<H3>" ;
105
106 print "<H1> 7.) Presetup \%fdat and \@ffld</H1>\n" ;
107
108 my %myfdat = ('test' => 'value',
109 'fdat' => 'text') ;
110
111 my @myffld = sort keys %myfdat ;
112
113 Embperl::Execute ({input => \'<P><table><tr><td>[+ $ffld[$row] +]</td><td>[+ do { local $^W = 0 ; $fdat{$ffld[$row]} } +]</td></tr></table></P>',
114 inputfile => 'fdat & ffld',
115 req_rec => $r,
116 fdat => \%myfdat,
117 ffld => \@myffld}
118 ) ;
119
120
121 print "\n<H1> 8.) Inculde a file</H1>\n" ;
122
123
124 Embperl::Execute ({inputfile => '../inc.htm', input_escmode => 7,
125 req_rec => $r}) ;
126
127
128 print "\n<H1> 9.) Inculde a file and return output in a scalar</H1>\n" ;
129
130 my $out ;
131
132 Embperl::Execute ({inputfile => '../inc.htm', input_escmode => 7,
133 output => \$out,
134 req_rec => $r}) ;
135
136
137 print "\n<H3>$out</H3>\n" ;
138
139 print "\n<H1> 10.) Test \$req_rec inside Execute</H1>\n" ;
140
141 Embperl::Execute ('../reqrec.htm') ;
142
143
144 print "\n<H1> 11.) Done :-)</H1>\n" ;
145
146
147 print "</body></html>\n";