Mailing List Archive

[! !] and Execute
Hi,

I'm new to Embperl and wondering what happens in this case: I have an
applications that consists of several files/scripts which share a
common set of subs. I put this subs in a common.ep and (as described
on man Embperl) surrounded them with [! !].

So if I include this file with Execute from my scripts... Is it still
compiled once per script (from which it was inclued)? The scripts have
all a diffrent scope?

Ciao,
Eric
RE: [! !] and Execute [ In reply to ]
Hi,
>
> I'm new to Embperl and wondering what happens in this case: I have an
> applications that consists of several files/scripts which share a
> common set of subs.

Perl subroutines or Embperl subs [$ sub foo $] ?

> I put this subs in a common.ep and (as described
> on man Embperl) surrounded them with [! !].
>
> So if I include this file with Execute from my scripts... Is it still
> compiled once per script (from which it was inclued)? The scripts have
> all a diffrent scope?

The subs are comipled in the namespace of common.ep and this is done only
once. If you they are Embperl subs you can import them in the current
namespace with the import parameter of the execute function. Importing is
only done once per script.

If they are perl subs, you must use the full packagename to call them.

Gerald


-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925151
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
RE: [! !] and Execute [ In reply to ]
Hi,

>
> Well it looks like this:
>
> [- Execute("common.ep"); -]
>
> which contains [! sub abc { } !] and so on. So maybe I should write [!
> Execute("common.ep"); !] if I want to compile common.ep only
> once.

You could do so, but you don't know the package name they are compiled in. I
see the following possibilities:

[- Execute({inputfile=>'common.ep', package=>'foo'}) ; -]

Call them as

foo::bar

If you have only [! !] blocks in common.ep Embperl will look every request
at the page, but the [! !] are only executed when common.ep changes. You
could also put the Execute inside a [! !] Block. In this case common.ep will
be executed once per script. A change in common.ep will be only get
vissible, if the page itself changes or the server restarts.

You can also include a plain perl file via require, but be sure to include a
package foo ; at the top, otherwise the sub will be compiled in the
namespace of the first script that requires it. In this case the common.ep
will only be recompiled when the server restarts.

Gerald


-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925151
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------