4 # various typeglob tests
16 # type coersion on assignment
20 print ref(\$bar) eq 'SCALAR' ? "ok 1\n" : "not ok 1\n";
23 # type coersion (not) on misc ops
26 print ref(\$foo) eq 'GLOB' ? "ok 2\n" : "not ok 2\n";
29 unless ($foo =~ /abcd/) {
30 print ref(\$foo) eq 'GLOB' ? "ok 3\n" : "not ok 3\n";
33 if ($foo eq '*main::bar') {
34 print ref(\$foo) eq 'GLOB' ? "ok 4\n" : "not ok 4\n";
37 # type coersion on substitutions that match
41 print ref(\$a) eq 'GLOB' ? "ok 5\n" : "not ok 5\n";
43 print $a eq 'main::foo' ? "ok 6\n" : "not ok 6\n";
44 print ref(\$b) eq 'GLOB' ? "ok 7\n" : "not ok 7\n";
46 # typeglobs as lvalues
47 substr($foo, 0, 1) = "XXX";
48 print ref(\$foo) eq 'SCALAR' ? "ok 8\n" : "not ok 8\n";
49 print $foo eq 'XXXmain::bar' ? "ok 9\n" : "not ok 9\n";
51 # returning glob values
53 local($bar) = *main::foo;
60 print ref(\$fuu) eq 'GLOB' ? "ok 10\n" : "not ok 10\n";
64 print ref(\$baa) eq 'GLOB' ? "ok 11\n" : "not ok 11\n";
67 # nested package globs
68 # NOTE: It's probably OK if these semantics change, because the
69 # fact that %X::Y:: is stored in %X:: isn't documented.
72 { package Foo::Bar; no warnings 'once'; $test=1; }
73 print exists $Foo::{'Bar::'} ? "ok 12\n" : "not ok 12\n";
74 print $Foo::{'Bar::'} eq '*Foo::Bar::' ? "ok 13\n" : "not ok 13\n";
76 # test undef operator clearing out entire glob
78 @foo = qw(more stuff);
79 %foo = qw(even more random stuff);
81 print +($foo || @foo || %foo) ? "not ok" : "ok", " 14\n";
83 # test warnings from assignment of undef to glob
86 local $SIG{__WARN__} = sub { $msg = $_[0] };
89 print $msg ? "not ok" : "ok", " 15\n";
91 print $msg ? "ok" : "not ok", " 16\n";
94 # test *glob{THING} syntax
97 %x = ("ok 19" => "\n");
99 print ${*x{SCALAR}}, @{*x{ARRAY}}, %{*x{HASH}}, &{*x{CODE}};
103 print ref *x{FORMAT} eq "FORMAT" ? "ok 21\n" : "not ok 21\n";
105 print *{*x{GLOB}} eq "*main::STDOUT" ? "ok 22\n" : "not ok 22\n";
106 print {*x{IO}} "ok 23\n";
108 # test if defined() doesn't create any new symbols
114 print "not " if defined *{$a};
115 ++$test; print "ok $test\n";
117 print "not " if defined @{$a} or defined *{$a};
118 ++$test; print "ok $test\n";
120 print "not " if defined %{$a} or defined *{$a};
121 ++$test; print "ok $test\n";
123 print "not " if defined ${$a} or defined *{$a};
124 ++$test; print "ok $test\n";
126 print "not " if defined &{$a} or defined *{$a};
127 ++$test; print "ok $test\n";
129 *{$a} = sub { print "ok $test\n" };
130 print "not " unless defined &{$a} and defined *{$a};
134 # although it *should* if you're talking about magicals
140 print "not " unless defined ${$a};
141 ++$test; print "ok $test\n";
142 print "not " unless defined *{$a};
143 ++$test; print "ok $test\n";
147 print "not " unless ${$a};
148 ++$test; print "ok $test\n";
149 print "not " unless defined *{$a};
150 ++$test; print "ok $test\n";
152 print "not " if ${$a};
153 ++$test; print "ok $test\n";
154 print "not " unless defined *{$a};
155 ++$test; print "ok $test\n";
157 print "not " if defined ${$a};
158 ++$test; print "ok $test\n";
159 print "not " if defined *{$a};
160 ++$test; print "ok $test\n";
162 "o" =~ /(((((((((((o)))))))))))/;
163 print "not " unless ${$a};
164 ++$test; print "ok $test\n";
165 print "not " unless defined *{$a};
166 ++$test; print "ok $test\n";
170 # does pp_readline() handle glob-ness correctly?
180 local $SIG{__WARN__} = sub {
183 my $val = *x{FILEHANDLE};
184 print {*x{IO}} ($warn =~ /is deprecated/ ? "ok 42\n" : "not ok 42\n");