You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Robert Buff <bu...@cs.nyu.edu> on 2001/01/15 22:16:08 UTC

Can I share my own functions in a safe namespace?

I include a module X.pm in Apache's startup.pl, which has a public
function f. I share this public function with Embperl by calling

my $cp = HTML::Embperl::AddCompartment( 'SafeCompartment' );
$cp->share_from( 'X', [ 'f' ] );

after HTML::Embperl has been loaded. When I define optSafeNameSpace and
optOpcodeMask in httpd.conf, however, f is not known to Perl code in
documents.

The Embperl documentation says that only opcode masks are used from safe
compartments. Is there a way to selectively share external variables in
Embperl documents, while still having a safe namespace?

Thanks,
Robert


Re: Can I share my own functions in a safe namespace?

Posted by Gerald Richter <ri...@ecos.de>.

> I include a module X.pm in Apache's startup.pl, which has a public
> function f. I share this public function with Embperl by calling
>
> my $cp = HTML::Embperl::AddCompartment( 'SafeCompartment' );
> $cp->share_from( 'X', [ 'f' ] );
>
> after HTML::Embperl has been loaded. When I define optSafeNameSpace and
> optOpcodeMask in httpd.conf, however, f is not known to Perl code in
> documents.
>

The optOpcodeMask is only neccessary when you have defined an opcode mask in
the compartment (in which case it would also be nessecary to specify
EMBPERL_COMPARTMENT).

In your case, where you only want to share functions/variables, you have to
tell Embperl that it uses the package of the compartment, i.e. in addition
to set optSafeNameSpace and setting up the compartment as above, you need to
set

PerlSetEnv EMBPERL_PACKAGE SafeCompartment

this will run the pages in the package SafeCompartment, which is the one
Safe.pm shares the function/variables with (NOTE: from the point of the page
it runs still in package main). What you loose by this, is that every page
is compiled in it's own package, you either have to setup this of your own
or run them all in the same package.

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