Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

symbols, scope, and mod_perl

by acanfora (Novice)
on Oct 01, 2012 at 08:10 UTC ( #996605=perlquestion: print w/ replies, xml ) Need Help??
acanfora has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I am trying to export by default a variable from a module in the importer namespace, please look at this sample code:
package EXAMPLE; use strict; use warnings; sub import{ my $context = caller; my $symbol = "$context\:\:my_dirt_sneaky_object_reference"; warn $context; warn $symbol; { no strict 'refs'; *$symbol = \EXAMPLE->new; } } sub new{ my $class = shift; my $self = {}; return bless $self, $class; } sub my_example_method{ print "hi, I am here!"; }
when I call it from a traditional CGI, all works without a glitch:
#!/usr/bin/perl use lib '/path/to/whateveryoulike'; use EXAMPLE; $my_dirt_sneaky_object_reference->my_example_method;
When I call the same code from mod_perl (Registry), I get a segmentation fault after the first invocation. Am I doing any big mistake with mod_perl? Is it the bad way to play with namespaces in mod_perl? To tell the truth, what I am trying to achieve is a bit more convoluted, but I tried to reduce it to what I believe is the kernel of the problem. Any idea? Thanks in advance for tips and advices.

Comment on symbols, scope, and mod_perl
Select or Download Code
Replies are listed 'Best First'.
Re: symbols, scope, and mod_perl
by acanfora (Novice) on Oct 01, 2012 at 10:42 UTC
    Found: manipulations on the symbols under mod_perl are visible to all threads, therefore the pointer mess I am seeing. I should manipulate the thread main function scratchpad, instead of the symbol table, but I do not know how to achieve such a thing.

      Um, that sounds "fishy" :)

      Each thread gets its own symbol table, they don't share

        Furthermore each script running under registry gets its own namespace, ex
        ModPerl::ROOT::ModPerl::Registry::D_3a_ro_sham_bo_theEXAMPLEXPORTERtes +t::my_dirt_sneaky_object_reference

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://996605]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2015-07-08 07:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls