# # Example for using HTML::Embperl::Execute # # run this under mod_perl / Apache::Registry # use HTML::Embperl ; my($r) = @_; # workaround for broken $r -> chdir_file in Apache::Registry on ActiveState perl use Cwd ; use File::Basename ; my $fn = $r -> filename ; chdir(dirname ($fn)) ; $HTML::Embperl::DebugDefault = 811005 ; $tst1 = '

Here is some text

' ; $r -> status (200) ; $r -> send_http_header () ; print "Test for HTML::Embperl::Execute\n" ; print "

1.) Include from memory

\n" ; HTML::Embperl::Execute ({input => \$tst1, mtime => 1, inputfile => 'Some text', req_rec => $r}) ; print "

2.) Include from memory with some Embperl code

\n" ; HTML::Embperl::Execute ({input => \'[- @ar = (a1, b2, c3) -]
[+$ar[$col]+]

', mtime => 1, inputfile => 'table', req_rec => $r}) ; print "

3.) Include from memory with passing of variables

\n" ; $MyPackage::Interface::Var = 'Some Var' ; HTML::Embperl::Execute ({input => \'

Transfer some vars [+ $Var +] !

', inputfile => 'Var', mtime => 1, 'package' => 'MyPackage::Interface', req_rec => $r}) ; print "

4.) Change the variable, but not the code

\n" ; $MyPackage::Interface::Var = 'Do it again' ; # code is the same, so give the same mtime and inputfile to avoid recompile # Note you get problems is you change the code, but did not restart the server or # change the value in mtime. So make sure if you change something also change mtime! HTML::Embperl::Execute ({input => \'

Transfer some vars [+ $Var +] !

', inputfile => 'Var2', mtime => 1, 'package' => 'MyPackage::Interface', req_rec => $r}) ; print "

5.) Use \@param to pass parameters

\n" ; HTML::Embperl::Execute ({input => \'

Use @param to transfer some data ([+ "@param" +]) !

', inputfile => 'Param', req_rec => $r, param => [1, 2, 3, 4] } ) ; print "

6.) Use \@param to pass parameters and return it

\n" ; my @p = ('vara', 'varb') ; print "

\$p[0] is $p[0] and \$p[1] is $p[1]

" ; HTML::Embperl::Execute ({input => \'

Got data in @param ([+ "@param" +]) !

[- $param[0] = "newA" ; $param[1] = "newB" ; -]

Change data in @param to ([+ "@param" +]) !

', inputfile => 'Param & Return', req_rec => $r, param => \@p } ) ; print "

\$p[0] is now $p[0] and \$p[1] is now $p[1]

" ; print "

7.) Presetup \%fdat and \@ffld

\n" ; my %myfdat = ('test' => 'value', 'fdat' => 'text') ; my @myffld = sort keys %myfdat ; HTML::Embperl::Execute ({input => \'

[+ $ffld[$row] +][+ do { local $^W = 0 ; $fdat{$ffld[$row]} } +]

', inputfile => 'fdat & ffld', req_rec => $r, fdat => \%myfdat, ffld => \@myffld} ) ; print "

8.) Inculde a file

\n" ; HTML::Embperl::Execute ({inputfile => '../inc.htm', req_rec => $r}) ; print "

9.) Inculde a file and return output in a scalar

\n" ; my $out ; HTML::Embperl::Execute ({inputfile => '../inc.htm', output => \$out, req_rec => $r}) ; print "

$out

\n" ; print "

10.) Done :-)

\n" ; print "\n";