1N/A#!./perl
1N/A
1N/A#
1N/A# various typeglob tests
1N/A#
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/Ause warnings;
1N/A
1N/Aprint "1..48\n";
1N/A
1N/A# type coersion on assignment
1N/A$foo = 'foo';
1N/A$bar = *main::foo;
1N/A$bar = $foo;
1N/Aprint ref(\$bar) eq 'SCALAR' ? "ok 1\n" : "not ok 1\n";
1N/A$foo = *main::bar;
1N/A
1N/A# type coersion (not) on misc ops
1N/A
1N/Aif ($foo) {
1N/A print ref(\$foo) eq 'GLOB' ? "ok 2\n" : "not ok 2\n";
1N/A}
1N/A
1N/Aunless ($foo =~ /abcd/) {
1N/A print ref(\$foo) eq 'GLOB' ? "ok 3\n" : "not ok 3\n";
1N/A}
1N/A
1N/Aif ($foo eq '*main::bar') {
1N/A print ref(\$foo) eq 'GLOB' ? "ok 4\n" : "not ok 4\n";
1N/A}
1N/A
1N/A# type coersion on substitutions that match
1N/A$a = *main::foo;
1N/A$b = $a;
1N/A$a =~ s/^X//;
1N/Aprint ref(\$a) eq 'GLOB' ? "ok 5\n" : "not ok 5\n";
1N/A$a =~ s/^\*//;
1N/Aprint $a eq 'main::foo' ? "ok 6\n" : "not ok 6\n";
1N/Aprint ref(\$b) eq 'GLOB' ? "ok 7\n" : "not ok 7\n";
1N/A
1N/A# typeglobs as lvalues
1N/Asubstr($foo, 0, 1) = "XXX";
1N/Aprint ref(\$foo) eq 'SCALAR' ? "ok 8\n" : "not ok 8\n";
1N/Aprint $foo eq 'XXXmain::bar' ? "ok 9\n" : "not ok 9\n";
1N/A
1N/A# returning glob values
1N/Asub foo {
1N/A local($bar) = *main::foo;
1N/A $foo = *main::bar;
1N/A return ($foo, $bar);
1N/A}
1N/A
1N/A($fuu, $baa) = foo();
1N/Aif (defined $fuu) {
1N/A print ref(\$fuu) eq 'GLOB' ? "ok 10\n" : "not ok 10\n";
1N/A}
1N/A
1N/Aif (defined $baa) {
1N/A print ref(\$baa) eq 'GLOB' ? "ok 11\n" : "not ok 11\n";
1N/A}
1N/A
1N/A# nested package globs
1N/A# NOTE: It's probably OK if these semantics change, because the
1N/A# fact that %X::Y:: is stored in %X:: isn't documented.
1N/A# (I hope.)
1N/A
1N/A{ package Foo::Bar; no warnings 'once'; $test=1; }
1N/Aprint exists $Foo::{'Bar::'} ? "ok 12\n" : "not ok 12\n";
1N/Aprint $Foo::{'Bar::'} eq '*Foo::Bar::' ? "ok 13\n" : "not ok 13\n";
1N/A
1N/A# test undef operator clearing out entire glob
1N/A$foo = 'stuff';
1N/A@foo = qw(more stuff);
1N/A%foo = qw(even more random stuff);
1N/Aundef *foo;
1N/Aprint +($foo || @foo || %foo) ? "not ok" : "ok", " 14\n";
1N/A
1N/A# test warnings from assignment of undef to glob
1N/A{
1N/A my $msg;
1N/A local $SIG{__WARN__} = sub { $msg = $_[0] };
1N/A use warnings;
1N/A *foo = 'bar';
1N/A print $msg ? "not ok" : "ok", " 15\n";
1N/A *foo = undef;
1N/A print $msg ? "ok" : "not ok", " 16\n";
1N/A}
1N/A
1N/A# test *glob{THING} syntax
1N/A$x = "ok 17\n";
1N/A@x = ("ok 18\n");
1N/A%x = ("ok 19" => "\n");
1N/Asub x { "ok 20\n" }
1N/Aprint ${*x{SCALAR}}, @{*x{ARRAY}}, %{*x{HASH}}, &{*x{CODE}};
1N/Aformat x =
1N/Aok 21
1N/A.
1N/Aprint ref *x{FORMAT} eq "FORMAT" ? "ok 21\n" : "not ok 21\n";
1N/A*x = *STDOUT;
1N/Aprint *{*x{GLOB}} eq "*main::STDOUT" ? "ok 22\n" : "not ok 22\n";
1N/Aprint {*x{IO}} "ok 23\n";
1N/A
1N/A{
1N/A my $warn;
1N/A local $SIG{__WARN__} = sub {
1N/A $warn .= $_[0];
1N/A };
1N/A my $val = *x{FILEHANDLE};
1N/A print {*x{IO}} ($warn =~ /is deprecated/ ? "ok 24\n" : "not ok 24\n");
1N/A
1N/A}
1N/A
1N/A# test if defined() doesn't create any new symbols
1N/A
1N/A{
1N/A my $test = 24;
1N/A
1N/A my $a = "SYM000";
1N/A print "not " if defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A
1N/A print "not " if defined @{$a} or defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A
1N/A print "not " if defined %{$a} or defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A
1N/A print "not " if defined ${$a} or defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A
1N/A print "not " if defined &{$a} or defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A
1N/A *{$a} = sub { print "ok $test\n" };
1N/A print "not " unless defined &{$a} and defined *{$a};
1N/A ++$test; &{$a};
1N/A}
1N/A
1N/A# although it *should* if you're talking about magicals
1N/A
1N/A{
1N/A my $test = 30;
1N/A
1N/A my $a = "]";
1N/A print "not " unless defined ${$a};
1N/A ++$test; print "ok $test\n";
1N/A print "not " unless defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A
1N/A $a = "1";
1N/A "o" =~ /(o)/;
1N/A print "not " unless ${$a};
1N/A ++$test; print "ok $test\n";
1N/A print "not " unless defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A $a = "2";
1N/A print "not " if ${$a};
1N/A ++$test; print "ok $test\n";
1N/A print "not " unless defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A $a = "1x";
1N/A print "not " if defined ${$a};
1N/A ++$test; print "ok $test\n";
1N/A print "not " if defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A $a = "11";
1N/A "o" =~ /(((((((((((o)))))))))))/;
1N/A print "not " unless ${$a};
1N/A ++$test; print "ok $test\n";
1N/A print "not " unless defined *{$a};
1N/A ++$test; print "ok $test\n";
1N/A}
1N/A
1N/A
1N/A# [ID 20010526.001] localized glob loses value when assigned to
1N/A
1N/A$j=1; %j=(a=>1); @j=(1); local *j=*j; *j = sub{};
1N/A
1N/Aprint $j == 1 ? "ok 41\n" : "not ok 41\n";
1N/Aprint $j{a} == 1 ? "ok 42\n" : "not ok 42\n";
1N/Aprint $j[0] == 1 ? "ok 43\n" : "not ok 43\n";
1N/A
1N/A# does pp_readline() handle glob-ness correctly?
1N/A
1N/A{
1N/A my $g = *foo;
1N/A $g = <DATA>;
1N/A print $g;
1N/A}
1N/A
1N/A{
1N/A my $w = '';
1N/A $SIG{__WARN__} = sub { $w = $_[0] };
1N/A sub abc1 ();
1N/A local *abc1 = sub { };
1N/A print $w eq '' ? "ok 45\n" : "not ok 45\n# $w";
1N/A sub abc2 ();
1N/A local *abc2;
1N/A *abc2 = sub { };
1N/A print $w eq '' ? "ok 46\n" : "not ok 46\n# $w";
1N/A sub abc3 ();
1N/A *abc3 = sub { };
1N/A print $w =~ /Prototype mismatch/ ? "ok 47\n" : "not ok 47\n# $w";
1N/A}
1N/A
1N/A{
1N/A # [17375] rcatline to formerly-defined undef was broken. Fixed in
1N/A # do_readline by checking SvOK. AMS, 20020918
1N/A my $x = "not ";
1N/A $x = undef;
1N/A $x .= <DATA>;
1N/A print $x;
1N/A}
1N/A
1N/A__END__
1N/Aok 44
1N/Aok 48