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 " );
71 # localizing *CORE::GLOBAL::foo should revert to finding CORE::foo
73 local(*CORE::GLOBAL::require);
75 eval "require NoNeXiSt;";
76 ok( ! ( $r or $@ !~ /^Can't locate NoNeXiSt/i ) );
80 # readline() has special behaviour too
84 BEGIN { *CORE::GLOBAL::readline = sub (;*) { ++$r }; }
90 # Non-global readline() override
91 BEGIN { *Rgs::readline = sub (;*) { --$r }; }
96 ::is( <$pad_fh> , 11 );
99 # Global readpipe() override
100 BEGIN { *CORE::GLOBAL::readpipe = sub ($) { "$_[0] " . --$r }; }
101 is( `rm`, "rm 10", '``' );
102 is( qx/cp/, "cp 9", 'qx' );
104 # Non-global readpipe() override
105 BEGIN { *Rgs::readpipe = sub ($) { ++$r . " $_[0]" }; }
108 ::is( `rm`, "10 rm", '``' );
109 ::is( qx/cp/, "11 cp", 'qx' );
112 # Verify that the parsing of overridden keywords isn't messed up
113 # by the indirect object notation
115 local $SIG{__WARN__} = sub {
116 ::like( $_[0], qr/^ok overriden at/ );
118 BEGIN { *OverridenWarn::warn = sub { CORE::warn "@_ overriden"; }; }
119 package OverridenWarn;
121 warn( OverridenWarn->foo() );
122 warn OverridenWarn->foo();
124 BEGIN { *OverridenPop::pop = sub { ::is( $_[0][0], "ok" ) }; }
126 package OverridenPop;
128 pop( OverridenPop->foo() );
129 pop OverridenPop->foo();
134 local *CORE::GLOBAL::require = sub {
135 CORE::require($_[0]);
138 require Text::ParseWords;