6 $ENV{PERL5LIB} = '../lib';
13 # catch "used once" warnings
15 BEGIN { $SIG{__WARN__} = sub { push @warns, @_ }; $^W = 1 };
22 use vars qw($p @q %r *s &t $X::p);
24 my $e = !(grep /^Name "X::x" used only once: possible typo/, @warns) && 'not ';
26 $e = !(grep /^Name "main::x" used only once: possible typo/, @warns) && 'not ';
28 $e = !(grep /^Name "main::y" used only once: possible typo/, @warns) && 'not ';
30 $e = !(grep /^Name "main::z" used only once: possible typo/, @warns) && 'not ';
32 ($e, @warns) = @warns != 4 && 'not ';
35 # this is inside eval() to avoid creation of symbol table entries and
36 # to avoid "used once" warnings
38 $e = ! $main::{p} && 'not ';
40 $e = ! *q{ARRAY} && 'not ';
42 $e = ! *r{HASH} && 'not ';
44 $e = ! $main::{s} && 'not ';
46 $e = ! *t{CODE} && 'not ';
48 $e = defined $X::{q} && 'not ';
50 $e = ! $X::{p} && 'not ';
56 eval q{use vars qw(@X::y !abc); $e = ! *X::y{ARRAY} && 'not '};
58 $e = $@ !~ /^'!abc' is not a valid variable name/ && 'not ';
61 eval 'use vars qw($x[3])';
62 $e = $@ !~ /^Can't declare individual elements of hash or array/ && 'not ';
66 eval 'use vars qw($!)';
67 ($e, @warns) = ($@ || @warns) ? 'not ' : '';
71 # NB the next test only works because vars.pm has already been loaded
72 eval 'use warnings "vars"; use vars qw($!)';
73 $e = ($@ || (shift(@warns)||'') !~ /^No need to declare built-in vars/)
78 eval 'use vars qw(@x%%)';
81 $e = ! *{'x%%'}{ARRAY} && 'not ';
83 eval '$u = 3; @v = (); %w = ()';
88 eval 'use vars qw(@y%%)';
89 $e = $@ !~ /^'\@y%%' is not a valid variable name under strict vars/ && 'not ';
91 $e = *{'y%%'}{ARRAY} && 'not ';
93 eval '$u = 3; @v = (); %w = ()';
94 my @errs = split /\n/, $@;
95 $e = @errs != 3 && 'not ';
97 $e = !(grep(/^Global symbol "\$u" requires explicit package name/, @errs))
100 $e = !(grep(/^Global symbol "\@v" requires explicit package name/, @errs))
103 $e = !(grep(/^Global symbol "\%w" requires explicit package name/, @errs))