Skip Menu |

This queue is for tickets about the Import-Into CPAN distribution.

Report information
The Basics
Id: 88643
Status: rejected
Priority: 0/
Queue: Import-Into

People
Owner: Nobody in particular
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.001001
Fixed in: (no value)



Subject: failure to import symbols into Safe compartments
Perl 5.16.3, Safe 2.31_01, The attached code seems to indicates that importing into Safe compartments does not work. This may be related to the fact that this doesn't seem to work either: {package I; # exports via Exporter::import } $cpt = Safe->new( 'Safe' ); eval 'package Safe; I->import; '; while this does package NonSafe; I->import; At least according to my tests; perhaps at this late hour I've got it wrong. Thanks, Diab
Subject: safe_import.t
#!perl use Test::More; use strict; use warnings; use Test::Fatal; use Import::Into; use Safe; { package I; use Exporter 'import'; our @EXPORT = qw[ i ii ]; sub i { return 'I' } sub ii { return 'II' } sub iii { return 'III' } } # Safe compartment my $cpt = Safe->new( 'AA' ); subtest 'define in Safe package via eval' => sub { SKIP: { is( exception { eval 'package AA; sub aa { q[AA] } ; 1;' or die $@ }, undef, 'eval' ) or skip 'bad eval', 2; ok( $cpt->reval( 'exists $::{aa}' ), "exists in symbol table" ) or skip 'bad exists', 1; is( $cpt->reval( 'aa()' ), 'AA', 'evaluate' ); } }; subtest 'I->import::into Safe package' => sub { SKIP: { is( exception { I->import::into( 'AA', 'i' ) }, undef, 'import::into' ) or skip "failed import", 2; ok( $cpt->reval( 'exists $::{i}' ), "exists in symbol table" ) or skip 'bad exists', 1; is( $cpt->reval( 'i()' ), 'I', 'evaluate sub' ); } }; subtest 'I->import in Safe package via eval' => sub { SKIP: { is( exception { eval "package AA; I->import( 'ii' ); 1;" or die $@ }, undef, 'eval' ) or skip 'bad eval', 2; ok( $cpt->reval( 'exists $::{ii}' ), "exists in symbol table" ) or skip 'bad exists', 1; is( $cpt->reval( 'ii()' ), 'II', 'evaluate sub' ); } }; subtest 'Manipulate Safe Symbol Table directly' => sub { SKIP: { is( exception { *{AA::iii} = \&I::iii }, undef, 'eval' ) or skip 'bad eval', 2; ok( $cpt->reval( 'exists $::{iii}' ), "exists in symbol table" ) or skip 'bad exists', 1; is( $cpt->reval( 'iii()' ), 'III', 'evaluate sub' ); } }; subtest 'I->import::into normal package' => sub { SKIP: { is( exception { I->import::into( 'BB', 'i' ) }, undef, 'import::into' ) or skip "failed import", 2; ok( exists $BB::{i}, "exists in symbol table" ) or skip 'bad exists', 1; is( BB::i->(), 'I', 'evaluate sub' ); } }; subtest 'I->import in normal package via eval' => sub { SKIP: { is( exception { eval "package BB; I->import( 'ii' ); 1;" or die $@ }, undef, 'eval' ) or skip 'bad eval', 2; ok( exists $BB::{ii}, "exists in symbol table" ) or skip 'bad exists', 1; is( BB::ii->(), 'II', 'evaluate sub' ); } }; done_testing;
On Fri Sep 13 02:06:14 2013, DJERIUS wrote: Show quoted text
> Perl 5.16.3, Safe 2.31_01, > > The attached code seems to indicates that importing into Safe > compartments does not work.
Forgot to attach the output. Here it is.
Subject: log
Download log
application/octet-stream 1.2k

Message body not shown because it is not plain text.

There's no fix for this within Import::Into. It isn't related to the use of eval. The same issue occurs if you call ->import while in the context of the compartment package. caller reports the wrong value for compartment package because Safe (well, Opcode) renames them to 'main'. For an example, try: perl -MSafe -le'Safe->new("AA"); package AA; sub { print scalar caller }->()' One solution for this would be to import things into the package before creating the Safe object. If there is a better fix, it would have to be in Safe or Opcode.