Mailing List Archive

BEGIN{} and END{}
hi,

I thinks this one's for you Gerald... I want my perl module to know
when it is being called by an embperl page and when the page's finished.

I can't count with BEGIN and END because the interpreter persistent,
allright, but is there any sub I can declare that will catch calls when
Embperl starts/ends executing the page.


martin
RE: BEGIN{} and END{} [ In reply to ]
hi,
>
> I thinks this one's for you Gerald... I want my perl module to know
> when it is being called by an embperl page and when the page's finished.
>
> I can't count with BEGIN and END because the interpreter persistent,
> allright, but is there any sub I can declare that will catch calls when
> Embperl starts/ends executing the page.
>

You can define a sub named CLEANUP in every Embperl page. That will be call
after the request is finish and the connection to the browser has been
closed. As the name suggest, a good place for cleaning up (like closing
database handles). But I guess that's not what you want. To get your module
called every time any Embperl is requested, use EmbperlObject, there you can
define a base page that looks like:

base.htm:

[- $obj = new whatever::module ; -]

[- $obj -> init -]

[- Execute ('*') ; # This calls the page -]

[- $obj -> term -]

in your httpd.conf

PerlSetEnv EMBPERL_OBJECT_BASE base.htm
PerlHandler HTML::EmbperlObject

of course you can do much more with EmbperlObject.

Gerald
RE: BEGIN{} and END{} [ In reply to ]
> You can define a sub named CLEANUP in every Embperl page. That will be call
> after the request is finish and the connection to the browser has been
> closed. As the name suggest, a good place for cleaning up (like closing
> database handles).

How long has CLEANUP been around? I remember asking you about END blocks a
while ago and you said you'd add it to the todo list. I really need to pay more
attention because CLEANUP will be a big help for me.

Thanks.

--
Jason Bodnar + jbodnar@team-linux.com + Team Linux

All right. His story checks out.

-- Homer Simpson, checking in the encyclopedia
under "Bush, George"
Two Bad Neighbors
RE: BEGIN{} and END{} [ In reply to ]
> How long has CLEANUP been around?

I added it somewhere in 0.2x (so about 2-3 years ago)

> I remember asking you about END blocks a
> while ago and you said you'd add it to the todo list.

Oh, sorry. I don't use CLEANUP often, so looks like I had just forget to
mention it when you ask the last time.

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
-------------------------------------------------------------