You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Peter Moran <pe...@forloop.co.uk> on 2003/11/13 07:44:37 UTC
Dynamic Embperl
Hi All,
Is it possible for Embperl not to use *real* files ?
What I want to do is to save template files inside a DB which will have
Embperl code within them - I want to be able to retrieve the templates
within a perl script and then *compile* the page to produce the result.
Main difference between doing this in offline mode is I dont want a
inputfile and a outputfile, just a input scalar (containg the template) and
a output scalar (containing the compiled page)
Is this doable ? I have been looking long and hard through the previous
mails but to no avail.... any suggestions welcome.
Regards
Pete Moran
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Dynamic Embperl
Posted by Kee Hinckley <na...@somewhere.com>.
At 12:46 AM +0000 11/14/03, Peter Moran wrote:
>Thanks Angus,
>
>Thats exactly what I need - incidently, what docs is this in, I cant seem to
>find it ?
It's there in the HTML::Embperl doc in the Execute docs . I don't
usually use the output, but I use the input case quite a bit. Define
a bunch of template files, then create a database structure and
people can update the database to change the site.
[-
Execute({
input => $this->Commons->toHTMLString(\$Page->{content},
$Page->{contenttype}),
mtime => join('', $Page->{dtm} =~ /[0-9]/g),
inputfile => $req_rec->uri(),
}) if ($Page->{contenttype});
-]
Where $Page is a DBIx::Databse record. The inputfile value gives it
a handle so Embperl can cache it by name, the mtime gives it a value
to see if it needs to reparse.
The Messagefire anti-spam site uses this for page content, help text,
FAQs and lots of other things.
--
Kee Hinckley
http://www.messagefire.com/ Next Generation Spam Defense
http://commons.somewhere.com/buzz/ Writings on Technology and Society
I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Dynamic Embperl
Posted by Peter Moran <pe...@forloop.co.uk>.
Thanks Angus,
Thats exactly what I need - incidently, what docs is this in, I cant seem to
find it ?
Regards
Pete
----- Original Message -----
From: "Angus Lees" <gu...@inodes.org>
To: "Peter Moran" <pe...@forloop.co.uk>
Cc: <em...@perl.apache.org>
Sent: Thursday, November 13, 2003 10:56 PM
Subject: Re: Dynamic Embperl
At Thu, 13 Nov 2003 11:14:10 +0100, Jörg Kütemeier wrote:
> Embperl::Execute({
> inputfile => '...some file', # is important for embperl (e.g. caching)
> # it identifies the "real" request with it
> mtime => undef, # time for last modified...
> input => \$content
>
> ... if you need it you can even redirect the output with
> output => \$outputvar
> });
Just to repeat, since earlier posters seemed to have missed this in
the Embperl docs, 'input' and 'output' args to Execute let you run
to/from a scalar.
The 'mtime' and 'inputfile' args are used for caching, see docs and
take advantage of them if you can (have an mtime field in your DB).
--
- Gus
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Dynamic Embperl
Posted by Angus Lees <gu...@inodes.org>.
At Thu, 13 Nov 2003 11:14:10 +0100, Jörg Kütemeier wrote:
> Embperl::Execute({
> inputfile => '...some file', # is important for embperl (e.g. caching)
> # it identifies the "real" request with it
> mtime => undef, # time for last modified...
> input => \$content
>
> ... if you need it you can even redirect the output with
> output => \$outputvar
> });
Just to repeat, since earlier posters seemed to have missed this in
the Embperl docs, 'input' and 'output' args to Execute let you run
to/from a scalar.
The 'mtime' and 'inputfile' args are used for caching, see docs and
take advantage of them if you can (have an mtime field in your DB).
--
- Gus
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Dynamic Embperl
Posted by Jochen Topf <jo...@remote.org>.
On Thu, Nov 13, 2003 at 10:14:08AM +0100, Andre Landwehr wrote:
> > (But it is sort of ugly, because if something changes you always have
> > to rewrite the Apache config file, so if somebody has a better
> > solution, please tell me :-)
>
> cool idea to use mod_rewrite, I hadn't thought of that yet. For
> mod_rewrite you can specify regular expressions so you won't have
> to rewrite the config file that often. Sth. like the following
> (untested, most probably won't work since I never really used
> mod_rewrite):
> RewriteRule ^(/foo/bar/baz)(.*)$ /$0/process.epl?path=$1
Yeah, I know about that, but it still means I have two places (httpd.conf
and the Filesystem) where I have to change things when something
changes. And every time I do this I forget to change the httpd.conf,
wonder why it doesn't work and then smack my head and fix it. :-)
Jochen
--
Jochen Topf jochen@remote.org http://www.remote.org/jochen/ +49-721-388298
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Dynamic Embperl
Posted by Gerald Richter <ri...@ecos.de>.
>perhaps Gerald knows a faster way ;-)
No, that's the way to do it! In case you know when your source changes, you
can set the mtime parameter and only change it's value when the source
changes, then Embperl will only recompile, when mtime changes
Gerald
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: Dynamic Embperl
Posted by Jörg Kütemeier <jk...@wolf-systems.net>.
> You could use that little script deployed with embperl which
> compiles pages offline (embpexec.pl or sth, I don't remember the
> name) and invoke it in backticks, but that is really really slow
> of course
Don't make it so complicated... ;-)
Ensure to set "AcceptPathInfo On" in your httpd.conf and perhaps
the following:
Embperl_AppName Dynamic
Embperl_Object_Base dynamic.epl
EMBPERL_OBJECT_APP dynamicapp.pl
Choose one... or make your own ;-)
# Embperl_UriMatch "\.htm.?$|\.epl$|\/$|\.ehtm.?$|\.shtm.?$"
# Embperl_UriMatch ".*"
EMBPERL_OBJECT_FALLBACK dynamicfallback.html
content of fallback does not matter (we'll never call it ;-) )
but need it to get into dynamic.epl
minimal dynamicapp.pl:
sub init {
return 0;
}
1;
your dynamic.epl (or base.epl):
[-
$r = shift;
my $uri = $r->param->uri;
[.. do something with the uri, e.g get table for it content..]
my $content = "<html>....</html>"; # save it into $content
# and display it...
Embperl::Execute({
inputfile => '...some file', # is important for embperl (e.g. caching)
# it identifies the "real" request with
it
mtime => undef, # time for last modified...
input => \$content
});
... if you need it you can even redirect the output with
output => \$outputvar
-]
hope there's no typo and it helps...
perhaps Gerald knows a faster way ;-)
cu
Jörg
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
wolf-systems IT-Services
Ihr Partner für ein sicheres und beständiges Netzwerk
http://www.wolf-systems.net
-----Original Message-----
From: Andre Landwehr [mailto:andre.landwehr@gmx.net]
Sent: Thursday, November 13, 2003 10:14 AM
To: embperl@perl.apache.org
Subject: Re: Dynamic Embperl
On Thu, Nov 13, 2003 at 09:46:04AM +0100, Jochen Topf wrote:
> a) Compile something out of the database into Embperl. If it is only
> Perl code you can just use eval, but with Embperl code its another
> problem. I have no idea how to do this but maybe somebody else can
> help.
You could use that little script deployed with embperl which
compiles pages offline (embpexec.pl or sth, I don't remember the
name) and invoke it in backticks, but that is really really slow
of course
> (But it is sort of ugly, because if something changes you always
have
> to rewrite the Apache config file, so if somebody has a better
> solution, please tell me :-)
cool idea to use mod_rewrite, I hadn't thought of that yet. For
mod_rewrite you can specify regular expressions so you won't have
to rewrite the config file that often. Sth. like the following
(untested, most probably won't work since I never really used
mod_rewrite):
RewriteRule ^(/foo/bar/baz)(.*)$ /$0/process.epl?path=$1
Andre
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Dynamic Embperl
Posted by Andre Landwehr <an...@gmx.net>.
On Thu, Nov 13, 2003 at 09:46:04AM +0100, Jochen Topf wrote:
> a) Compile something out of the database into Embperl. If it is only
> Perl code you can just use eval, but with Embperl code its another
> problem. I have no idea how to do this but maybe somebody else can
> help.
You could use that little script deployed with embperl which
compiles pages offline (embpexec.pl or sth, I don't remember the
name) and invoke it in backticks, but that is really really slow
of course
> (But it is sort of ugly, because if something changes you always have
> to rewrite the Apache config file, so if somebody has a better
> solution, please tell me :-)
cool idea to use mod_rewrite, I hadn't thought of that yet. For
mod_rewrite you can specify regular expressions so you won't have
to rewrite the config file that often. Sth. like the following
(untested, most probably won't work since I never really used
mod_rewrite):
RewriteRule ^(/foo/bar/baz)(.*)$ /$0/process.epl?path=$1
Andre
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Dynamic Embperl
Posted by Jochen Topf <jo...@remote.org>.
On Thu, Nov 13, 2003 at 06:44:37AM -0000, Peter Moran wrote:
> Is it possible for Embperl not to use *real* files ?
>
> What I want to do is to save template files inside a DB which will have
> Embperl code within them - I want to be able to retrieve the templates
> within a perl script and then *compile* the page to produce the result.
>
> Main difference between doing this in offline mode is I dont want a
> inputfile and a outputfile, just a input scalar (containg the template) and
> a output scalar (containing the compiled page)
>
>
> Is this doable ? I have been looking long and hard through the previous
> mails but to no avail.... any suggestions welcome.
There are really two problems here:
a) Compile something out of the database into Embperl. If it is only
Perl code you can just use eval, but with Embperl code its another
problem. I have no idea how to do this but maybe somebody else can
help.
b) How to get apache/Embperl to call your script if it is not at the
proper place. Here I am using this solution, explained by an example:
I want to get the URL
http://www.example.com/foo/bar/baz
In rewrite this with Apache mod_rewrite to
http://www.example.com/foo.html?path=/bar/baz
And now I have an Embperl File foo.html which will do the right
thing. With this solution you at least don't need the file any more.
(But it is sort of ugly, because if something changes you always have
to rewrite the Apache config file, so if somebody has a better
solution, please tell me :-)
Jochen
--
Jochen Topf jochen@remote.org http://www.remote.org/jochen/ +49-721-388298
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org