use strict; use Safe; my $CODE = << 'END'; package A; sub new { my($class) = @_; print "hi there"; bless { }, $class; } package B; @ISA = qw(ROOT::A); END # If I uncomment this line, everything works. # eval $CODE; my $safe = Safe->new('ROOT'); $safe->reval($CODE); warn "code - $@" if $@; ROOT::B->new(); warn "new - $@" if $@; #### use strict; use warnings; use Safe; my $despatch = {}; my $code = sub { my $module = "A"; my $mainmodule = $module . ".pm"; require $mainmodule; import $mainmodule; my $obj = $module->new(); $despatch->{"A"} = $obj; $module = "B"; $obj = $module->new(); $despatch->{"$obj"} = $obj; }; my $compartment = Safe->new('testing'); $compartment->reval(&{$code}()); $compartment->reval( $despatch->{'A'}->test() ); #### package A; sub new { my($class) = @_; print "hi there\n"; bless { }, $class; } sub test { print "In test"; } package B; @ISA = qw(A); 1;