5 # The following require can't be removed during maintenance
6 # releases, sadly, because of the risk of buggy code that does
7 # require Carp; Carp::croak "..."; without brackets dying
8 # if Carp hasn't been loaded in earlier compile time. :-(
9 # We'll let those bugs get found on the development track.
10 require Carp if $] < 5.00450;
13 my $callpack = caller;
14 my ($pack, @imports, $sym, $ch) = @_;
15 foreach $sym (@imports) {
16 ($ch, $sym) = unpack('a1a*', $sym);
17 if ($sym =~ tr/A-Za-Z_0-9//c) {
18 # time for a more-detailed check-up
21 Carp::croak("Can't declare another package's variables");
22 } elsif ($sym =~ /^\w+[[{].*[]}]$/) {
24 Carp::croak("Can't declare individual elements of hash or array");
25 } elsif ($^W and length($sym) == 1 and $sym !~ tr/a-zA-Z//) {
27 Carp::carp("No need to declare built-in vars");
30 *{"${callpack}::$sym"} =
31 ( $ch eq "\$" ? \$ {"${callpack}::$sym"}
32 : $ch eq "\@" ? \@ {"${callpack}::$sym"}
33 : $ch eq "\%" ? \% {"${callpack}::$sym"}
34 : $ch eq "\*" ? \* {"${callpack}::$sym"}
35 : $ch eq "\&" ? \& {"${callpack}::$sym"}
38 Carp::croak("'$ch$sym' is not a valid variable name");
48 vars - Perl pragma to predeclare global variable names
52 use vars qw($frob @mung %seen);
56 This will predeclare all the variables whose names are
57 in the list, allowing you to use them under "use strict", and
58 disabling any typo warnings.
60 Unlike pragmas that affect the C<$^H> hints variable, the C<use vars> and
61 C<use subs> declarations are not BLOCK-scoped. They are thus effective
62 for the entire file in which they appear. You may not rescind such
63 declarations with C<no vars> or C<no subs>.
65 Packages such as the B<AutoLoader> and B<SelfLoader> that delay
66 loading of subroutines within packages can create problems with
67 package lexicals defined using C<my()>. While the B<vars> pragma
68 cannot duplicate the effect of package lexicals (total transparency
69 outside of the package), it can act as an acceptable substitute by
70 pre-declaring global symbols, ensuring their availability to the
71 later-loaded routines.
73 See L<perlmodlib/Pragmatic Modules>.