On Sat, 26 Aug 2000, Steven W McDougall wrote:
> as in the non-threaded case, or do we get
>
> $global::{foo} -> *global::foo -> &global::foo -> { print 1 }
> $thread::{foo} -> *thread::foo -> &thread::foo -> { print 2 }
>
> Does this program output
>
> 12
>
> or
>
> 11
Okay, I understand. Here's how I perceive it....
There is no global::foo, just two thread-specific foos. In which case,
the eval'd foo would create (or replace) that thread's previous foo.
Examples:
package Foo::Server;
...
sub foo { print 1 }
sub hack_foo { eval 'sub foo { print 2 }' }
1;
# Example 1
#!/your/path/to/perl
use Threads;
use Foo::Server;
my $t2 = Threads->new(\&Foo::Server::hack_foo);
Foo::Server::foo();
$t2->join();
# Both the main thread and the created thread put Foo:Server
# into their thread-space. The second thread replaces its initial
# thread-space foo() with the eval'd foo(). Output = '12' (or '21').
#Example 2
#!/your/path/to/perl
use Threads;
Threads->new( sub { require Foo::Server;
Foo::Server::hack_foo(); Foo::Server::foo(); exit } );
Foo::Server::foo();
# Only the second thread has Foo::Server in its thread space.
# The main thread would get a WTFO message on the call.
# The second thread would print '2'
#Example 3
#!/your/path/to/perl
use Threads;
use Foo::Server;
eval 'sub Foo::Server::hack_foo { }' # remove hacking ability
my $t2 = Threads->new(\&Foo::Server::hack_foo);
Foo::Server::foo();
$t2->join();
# Would still print "12" or "21", as the main thread only clobbered
# its own hack_foo.
--
Bryan C. Warnock
([EMAIL PROTECTED])