Gerald,
We have a function we use called includeexec that includes an Embperl
file and executes it, using the same namespace as the caller. We use
this all the time for stuff like this:
[+ $menu_item = 1; includeexec('menu.html'); +]
So menu.html tests the value of $menu_item and highlights the
appropriate menu item. (Or whatever else it needs to do.)
Here's the function:
sub includeexec($@)
{
my ($filename) = shift;
use HTML::Embperl;
my @param = @_;
my $body = '';
my ($package, $file, $line) = caller();
HTML::Embperl::Execute({inputfile => $filename,
output => \$body,
param => \@param ,
package => $package,
cleanup => 0});
return $body;
}
We ran into a problem where two different files include menu.html and
the namespace was being mismatched. Brian and I traced it to a
caching issue--once a particular file has been associated with a
particular namespace, Embperl will always execute that file in that
namespace, regardless of what you ask for.
After a couple false starts, we came up with the following. If the
requested namespace is different from the "associated" namespace, the
file is treated as if it has been modified, and is reloaded from disk
and re-executed. It's non-optimal, performance-wise, but it appears
to work.
The change is valid for 1.2.1, but it looks like it should apply to
1.3b2 as well.
Any thoughts on the best way to get back caching with the behavior we
want?
--- epmain.c.orig Mon Mar 27 14:28:20 2000
+++ epmain.c Mon Mar 27 14:27:53 2000
@@ -1668,9 +1668,16 @@
ppSV = hv_fetch(pCacheHash, (char *)sSourcefile, strlen (sSourcefile), 0) ;
if (ppSV && *ppSV)
{
+ int swap = 0;
f = (tFile *)SvIV((SV*)SvRV(*ppSV)) ;
-
- if (mtime == 0 || f -> mtime != mtime)
+
+ if (f->sCurrPackage != NULL &&
+ pConf->sPackage != NULL &&
+ strcmp(f->sCurrPackage, pConf->sPackage) != 0)
+ swap = 1;
+
+
+ if (mtime == 0 || f -> mtime != mtime || swap)
{
hv_clear (f -> pCacheHash) ;
@@ -1686,6 +1693,16 @@
SvREFCNT_dec (f -> pExportHash) ;
f -> pExportHash = NULL ;
}
+
+ if (swap)
+ {
+ lprintf (r, "[%d]MEM: Switch package name in %s from %s to %s\n",
+ r -> nPid, sSourcefile, f -> sCurrPackage, pConf->sPackage) ;
+ free(f->sCurrPackage);
+ f->sCurrPackage = strdup (pConf -> sPackage);
+ f->nCurrPackage = strlen(f->sCurrPackage);
+ }
+
}
}
else
We have a function we use called includeexec that includes an Embperl
file and executes it, using the same namespace as the caller. We use
this all the time for stuff like this:
[+ $menu_item = 1; includeexec('menu.html'); +]
So menu.html tests the value of $menu_item and highlights the
appropriate menu item. (Or whatever else it needs to do.)
Here's the function:
sub includeexec($@)
{
my ($filename) = shift;
use HTML::Embperl;
my @param = @_;
my $body = '';
my ($package, $file, $line) = caller();
HTML::Embperl::Execute({inputfile => $filename,
output => \$body,
param => \@param ,
package => $package,
cleanup => 0});
return $body;
}
We ran into a problem where two different files include menu.html and
the namespace was being mismatched. Brian and I traced it to a
caching issue--once a particular file has been associated with a
particular namespace, Embperl will always execute that file in that
namespace, regardless of what you ask for.
After a couple false starts, we came up with the following. If the
requested namespace is different from the "associated" namespace, the
file is treated as if it has been modified, and is reloaded from disk
and re-executed. It's non-optimal, performance-wise, but it appears
to work.
The change is valid for 1.2.1, but it looks like it should apply to
1.3b2 as well.
Any thoughts on the best way to get back caching with the behavior we
want?
--- epmain.c.orig Mon Mar 27 14:28:20 2000
+++ epmain.c Mon Mar 27 14:27:53 2000
@@ -1668,9 +1668,16 @@
ppSV = hv_fetch(pCacheHash, (char *)sSourcefile, strlen (sSourcefile), 0) ;
if (ppSV && *ppSV)
{
+ int swap = 0;
f = (tFile *)SvIV((SV*)SvRV(*ppSV)) ;
-
- if (mtime == 0 || f -> mtime != mtime)
+
+ if (f->sCurrPackage != NULL &&
+ pConf->sPackage != NULL &&
+ strcmp(f->sCurrPackage, pConf->sPackage) != 0)
+ swap = 1;
+
+
+ if (mtime == 0 || f -> mtime != mtime || swap)
{
hv_clear (f -> pCacheHash) ;
@@ -1686,6 +1693,16 @@
SvREFCNT_dec (f -> pExportHash) ;
f -> pExportHash = NULL ;
}
+
+ if (swap)
+ {
+ lprintf (r, "[%d]MEM: Switch package name in %s from %s to %s\n",
+ r -> nPid, sSourcefile, f -> sCurrPackage, pConf->sPackage) ;
+ free(f->sCurrPackage);
+ f->sCurrPackage = strdup (pConf -> sPackage);
+ f->nCurrPackage = strlen(f->sCurrPackage);
+ }
+
}
}
else