4 # various typeglob tests
9 # type coersion on assignment
13 print ref(\$bar) eq 'SCALAR' ? "ok 1\n" : "not ok 1\n";
16 # type coersion (not) on misc ops
19 print ref(\$foo) eq 'GLOB' ? "ok 2\n" : "not ok 2\n";
22 unless ($foo =~ /abcd/) {
23 print ref(\$foo) eq 'GLOB' ? "ok 3\n" : "not ok 3\n";
26 if ($foo eq '*main::bar') {
27 print ref(\$foo) eq 'GLOB' ? "ok 4\n" : "not ok 4\n";
30 # type coersion on substitutions that match
34 print ref(\$a) eq 'GLOB' ? "ok 5\n" : "not ok 5\n";
36 print $a eq 'main::foo' ? "ok 6\n" : "not ok 6\n";
37 print ref(\$b) eq 'GLOB' ? "ok 7\n" : "not ok 7\n";
39 # typeglobs as lvalues
40 substr($foo, 0, 1) = "XXX";
41 print ref(\$foo) eq 'SCALAR' ? "ok 8\n" : "not ok 8\n";
42 print $foo eq 'XXXmain::bar' ? "ok 9\n" : "not ok 9\n";
44 # returning glob values
46 local($bar) = *main::foo;
53 print ref(\$fuu) eq 'GLOB' ? "ok 10\n" : "not ok 10\n";
57 print ref(\$baa) eq 'GLOB' ? "ok 11\n" : "not ok 11\n";
60 # nested package globs
61 # NOTE: It's probably OK if these semantics change, because the
62 # fact that %X::Y:: is stored in %X:: isn't documented.
65 { package Foo::Bar; $test=1; }
66 print exists $Foo::{'Bar::'} ? "ok 12\n" : "not ok 12\n";
67 print $Foo::{'Bar::'} eq '*Foo::Bar::' ? "ok 13\n" : "not ok 13\n";
69 # test undef operator clearing out entire glob
71 @foo = qw(more stuff);
72 %foo = qw(even more random stuff);
74 print +($foo || @foo || %foo) ? "not ok" : "ok", " 14\n";
76 # test warnings from assignment of undef to glob
79 local $SIG{__WARN__} = sub { $msg = $_[0] };
82 print $msg ? "not ok" : "ok", " 15\n";
84 print $msg ? "ok" : "not ok", " 16\n";
87 # test *glob{THING} syntax
90 %x = ("ok 19" => "\n");
92 print ${*x{SCALAR}}, @{*x{ARRAY}}, %{*x{HASH}}, &{*x{CODE}};
94 print *{*x{GLOB}} eq "*main::STDOUT" ? "ok 21\n" : "not ok 21\n";
95 print {*x{IO}} "ok 22\n";
96 print {*x{FILEHANDLE}} "ok 23\n";
98 # test if defined() doesn't create any new symbols
104 print "not " if defined *{$a};
105 ++$test; print "ok $test\n";
107 print "not " if defined @{$a} or defined *{$a};
108 ++$test; print "ok $test\n";
110 print "not " if defined %{$a} or defined *{$a};
111 ++$test; print "ok $test\n";
113 print "not " if defined ${$a} or defined *{$a};
114 ++$test; print "ok $test\n";
116 print "not " if defined &{$a} or defined *{$a};
117 ++$test; print "ok $test\n";
119 *{$a} = sub { print "ok $test\n" };
120 print "not " unless defined &{$a} and defined *{$a};
124 # does pp_readline() handle glob-ness correctly?