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") );
55 # localizing *CORE::GLOBAL::foo should revert to finding CORE::foo
57 local(*CORE::GLOBAL::require);
59 eval "require NoNeXiSt;";
60 ok( ! ( $r or $@ !~ /^Can't locate NoNeXiSt/i ) );
64 # readline() has special behaviour too
68 BEGIN { *CORE::GLOBAL::readline = sub (;*) { ++$r }; }
74 # Non-global readline() override
75 BEGIN { *Rgs::readline = sub (;*) { --$r }; }
80 ::is( <$pad_fh> , 11 );
83 # Global readpipe() override
84 BEGIN { *CORE::GLOBAL::readpipe = sub ($) { "$_[0] " . --$r }; }
85 is( `rm`, "rm 10", '``' );
86 is( qx/cp/, "cp 9", 'qx' );
88 # Non-global readpipe() override
89 BEGIN { *Rgs::readpipe = sub ($) { ++$r . " $_[0]" }; }
92 ::is( `rm`, "10 rm", '``' );
93 ::is( qx/cp/, "11 cp", 'qx' );
96 # Verify that the parsing of overriden keywords isn't messed up
97 # by the indirect object notation
99 local $SIG{__WARN__} = sub {
100 ::like( $_[0], qr/^ok overriden at/ );
102 BEGIN { *OverridenWarn::warn = sub { CORE::warn "@_ overriden"; }; }
103 package OverridenWarn;
105 warn( OverridenWarn->foo() );
106 warn OverridenWarn->foo();
108 BEGIN { *OverridenPop::pop = sub { ::is( $_[0][0], "ok" ) }; }
110 package OverridenPop;
112 pop( OverridenPop->foo() );
113 pop OverridenPop->foo();
118 local *CORE::GLOBAL::require = sub {
119 CORE::require($_[0]);
122 require Text::ParseWords;