12 # This file tries to test builtin override using CORE::GLOBAL
16 BEGIN { package Foo; *main::getlogin = sub { "kilroy"; } }
18 print "not " unless getlogin eq "kilroy";
22 BEGIN { *CORE::GLOBAL::time = sub () { $t; } }
24 print "not " unless 45 == time + 3;
28 # require has special behaviour
31 BEGIN { *CORE::GLOBAL::require = sub { $r = shift; 1; } }
34 print "not " unless $r eq "Foo.pm";
38 print "not " unless $r eq join($dirsep, "Foo", "Bar.pm");
42 print "not " unless $r eq "Foo";
46 print "not " unless $r eq "5.6";
50 print "not " unless abs($r - 5.006) < 0.001 && $r eq "\x05\x06";
54 print "not " unless $r eq "Foo.pm";
58 print "not " unless $r eq join($dirsep, "Foo", "Bar.pm");
62 print "not " unless $r eq "5.6";
65 # localizing *CORE::GLOBAL::foo should revert to finding CORE::foo
67 local(*CORE::GLOBAL::require);
69 eval "require NoNeXiSt;";
70 print "not " if $r or $@ !~ /^Can't locate file NoNeXiSt/i;
75 # readline() has special behaviour too
79 BEGIN { *CORE::GLOBAL::readline = sub (;*) { ++$r }; }
80 print <FH> == 12 ? "ok 12\n" : "not ok 12\n";
81 print <$fh> == 13 ? "ok 13\n" : "not ok 13\n";
83 print <$pad_fh> == 14 ? "ok 14\n" : "not ok 14\n";
85 # Non-global readline() override
86 BEGIN { *Rgs::readline = sub (;*) { --$r }; }
88 print <FH> == 13 ? "ok 15\n" : "not ok 15\n";
89 print <$fh> == 12 ? "ok 16\n" : "not ok 16\n";
90 print <$pad_fh> == 11 ? "ok 17\n" : "not ok 17\n";