You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Andrew Ho <an...@tellme.com> on 2001/03/10 01:52:37 UTC

Re: [OT] Dynamic package name

Andrew,

AM>Is there any way to tell perl that from now on the namespace is
AM>$namespace? `package' does not accept scalars, and its scope is
AM>eval block, so if I use eval to pass scalar to "package" I have to
AM>include entire program text into that eval as well.

You can kind of do this via XS, but definitely not from regular Perl
without an eval(). Of course, you shouldn't be shy with eval() in mod_perl
as Apache::Registry, Apache::ASP, and most everything else uses eval()
anyway. Anyway, for doing it from XS something like this works:

    void declare_package(pTHX_ SV *sv_name) {
        PL_curstash = gv_stashsv(sv_name, TRUE);
        sv_setsv(PL_curstname, sv_name);
    }

Take a look at the Perl documentation for stashes in perlguts(1):

    http://www.perl.com/CPAN/doc/manual/html/pod/perlguts.html#Stashes_and_Globs

Humbly,

Andrew

----------------------------------------------------------------------
Andrew Ho               http://www.tellme.com/       andrew@tellme.com
Engineer                   info@tellme.com          Voice 650-930-9062
Tellme Networks, Inc.       1-800-555-TELL            Fax 650-930-9101
----------------------------------------------------------------------