1#!perl 2 3BEGIN { 4 require Config; 5 import Config; 6 if ($Config{'extensions'} !~ /\bOpcode\b/) { 7 print "1..0\n"; 8 exit 0; 9 } 10} 11 12use strict; 13use warnings; 14use Test::More; 15use Safe; 16plan(tests => 6); 17 18my $c = new Safe; 19$c->permit(qw(require caller)); 20 21my $no_warn_redef = ($] != 5.008009) 22 ? q(no warnings 'redefine';) 23 : q($SIG{__WARN__}=sub{};); 24my $r = $c->reval($no_warn_redef . q! 25 sub UNIVERSAL::isa { "pwned" } 26 (bless[],"Foo")->isa("Foo"); 27!); 28 29is( $r, "pwned", "isa overridden in compartment" ); 30is( (bless[],"Foo")->isa("Foo"), 1, "... but not outside" ); 31 32sub Foo::foo {} 33 34$r = $c->reval($no_warn_redef . q! 35 sub UNIVERSAL::can { "pwned" } 36 (bless[],"Foo")->can("foo"); 37!); 38 39is( $r, "pwned", "can overridden in compartment" ); 40is( (bless[],"Foo")->can("foo"), \&Foo::foo, "... but not outside" ); 41 42$r = $c->reval(q! 43 utf8::is_utf8("\x{100}"); 44!); 45is( $@, '', 'can call utf8::is_valid' ); 46is( $r, 1, '... returns 1' ); 47