12 # This file tries to test builtin override using CORE::GLOBAL
16 BEGIN { package Foo; *main::getlogin = sub { "kilroy"; } }
18 is( getlogin, "kilroy" );
21 BEGIN { *CORE::GLOBAL::time = sub () { $t; } }
26 # require has special behaviour
29 BEGIN { *CORE::GLOBAL::require = sub { $r = shift; 1; } }
35 is( $r, join($dirsep, "Foo", "Bar.pm") );
44 ok( abs($r - 5.006) < 0.001 && $r eq "\x05\x06" );
50 is( $r, join($dirsep, "Foo", "Bar.pm") );
54 local *CORE::GLOBAL::require = sub { push @r, shift; 1; };
56 like( " @r ", qr " 5\.006 " );
67 # Can’t do ‘no warnings’ with CORE::GLOBAL::require overridden. :-)
68 CORE::require warnings;
69 unimport warnings 'experimental::lexical_topic';
76 # localizing *CORE::GLOBAL::foo should revert to finding CORE::foo
78 local(*CORE::GLOBAL::require);
80 eval "require NoNeXiSt;";
81 ok( ! ( $r or $@ !~ /^Can't locate NoNeXiSt/i ) );
85 # readline() has special behaviour too
89 BEGIN { *CORE::GLOBAL::readline = sub (;*) { ++$r }; }
95 # Non-global readline() override
96 BEGIN { *Rgs::readline = sub (;*) { --$r }; }
101 ::is( <$pad_fh> , 11 );
104 # Global readpipe() override
105 BEGIN { *CORE::GLOBAL::readpipe = sub ($) { "$_[0] " . --$r }; }
106 is( `rm`, "rm 10", '``' );
107 is( qx/cp/, "cp 9", 'qx' );
109 # Non-global readpipe() override
110 BEGIN { *Rgs::readpipe = sub ($) { ++$r . " $_[0]" }; }
113 ::is( `rm`, "10 rm", '``' );
114 ::is( qx/cp/, "11 cp", 'qx' );
117 # Verify that the parsing of overridden keywords isn't messed up
118 # by the indirect object notation
120 local $SIG{__WARN__} = sub {
121 ::like( $_[0], qr/^ok overriden at/ );
123 BEGIN { *OverridenWarn::warn = sub { CORE::warn "@_ overriden"; }; }
124 package OverridenWarn;
126 warn( OverridenWarn->foo() );
127 warn OverridenWarn->foo();
129 BEGIN { *OverridenPop::pop = sub { ::is( $_[0][0], "ok" ) }; }
131 package OverridenPop;
133 pop( OverridenPop->foo() );
134 pop OverridenPop->foo();
139 local *CORE::GLOBAL::require = sub {
140 CORE::require($_[0]);
143 require Text::ParseWords;
148 # Constant inlining should not countermand "use subs" overrides
149 BEGIN { package other; *::caller = \&::caller }
151 caller; # inline the constant
152 is caller, 42, 'constant inlining does not undo "use subs" on keywords';