Hi:
Reading the Perl documentation i found that if i declare muy subs like this:
$globalp->{mytitle} =
sub
{
my $title = shift;
print OUT "$title";
};
The sub is assigned to the variable $globalp->{mytitle} so i can call it just
doing:
$globalp->{mytitle}("my title");
If the sub does not have a parameter you need to do the call like this:
$globalp->{mytitle}();
See the extended example below.
It is not Embperl Object, it is pure embperl.
I hope this helps to everybody wanting global subs in embperl.
I am using embperl 2.0b9
Regards
Carlos Kassab
file index.epl:
[- $globalp = shift; -]
[- $optRawInput = 1 -]
[-
use Net::SMTP;
$globalp->{bgcolor1} = "#efefef";
$globalp->{bgcolor2} = "#438fff";
Execute ('subs.epl');
-]
<html> <head><title> test </title></head><body>
[- $optRawInput = 1 -]
[-
local $escmode = 0;
$globalp->{OpenTable}($globalp->{bgcolor1},$globalp->{bgcolor2});
$globalp->{mytitle}("<big>My main title</big>");
$globalp->{CloseTable}();
-]
<br>
[- Execute ('somefile.epl') -]
</body></html>
file subs.epl:
[$ syntax EmbperlBlocks ASP $]
<%
$globalp = shift;
$globalp->{mytitle} =
sub
{
my $title = shift;
print OUT "$title";
};
$globalp->{myfooter} =
sub
{
$footertext = shift;
print OUT "<u>$footertext</u>";
};
$globalp->{OpenTable} =
sub
{
$bgcolor1 = shift;
$bgcolor2 = shift;
print OUT "<table width=\"100%\" border=\"0\" cellspacing=\"1\"
cellpadding=\"0\" bgcolor=\"$bgcolor2\"><tr><td>\n"
."<table width=\"100%\" border=\"0\" cellspacing=\"1\"
cellpadding=\"8\" bgcolor=\"$bgcolor1\"><tr><td>\n";
};
$globalp->{CloseTable} =
sub
{
print OUT "</td></tr></table></td></tr></table>\n";
};
%>
file somefile.epl:
[$ syntax EmbperlBlocks ASP $]
<%
$globalp = shift;
local $escmode = 0;
$globalp->{OpenTable}($globalp->{bgcolor1},$globalp->{bgcolor2});
$globalp->{mytitle}("<b>my subtitle</b>");
$globalp->{CloseTable}();
%>
<% &test; %>
<% &test1; %>
[$ sub test $]
<p>some body text here.</p>
<% $globalp->{myfooter}("footer text"); %>
<br>
[$ endsub $]
<%
sub test1
{
$globalp->{myfooter}("footer text 2");
}
%>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]