7 # The following require can't be removed during maintenance
8 # releases, sadly, because of the risk of buggy code that does
9 # require Carp; Carp::croak "..."; without brackets dying
10 # if Carp hasn't been loaded in earlier compile time. :-(
11 # We'll let those bugs get found on the development track.
12 require Carp if $] < 5.00450;
14 use warnings::register;
18 my $callpack = caller;
19 my ($pack, @imports) = @_;
22 ($ch, $sym) = unpack('a1a*', $_);
23 if ($sym =~ tr/A-Za-z_0-9//c) {
24 # time for a more-detailed check-up
25 if ($sym =~ /^\w+[[{].*[]}]$/) {
27 Carp::croak("Can't declare individual elements of hash or array");
28 } elsif (warnings::enabled() and length($sym) == 1 and $sym !~ tr/a-zA-Z//) {
29 warnings::warn("No need to declare built-in vars");
30 } elsif ( $^H &= strict::bits('vars') ) {
31 Carp::croak("'$_' is not a valid variable name under strict vars");
34 $sym = "${callpack}::$sym" unless $sym =~ /::/;
36 ( $ch eq "\$" ? \$$sym
37 : $ch eq "\@" ? \@$sym
38 : $ch eq "\%" ? \%$sym
39 : $ch eq "\*" ? \*$sym
40 : $ch eq "\&" ? \&$sym
43 Carp::croak("'$_' is not a valid variable name");
53 vars - Perl pragma to predeclare global variable names (obsolete)
57 use vars qw($frob @mung %seen);
61 NOTE: For variables in the current package, the functionality provided
62 by this pragma has been superseded by C<our> declarations, available
63 in Perl v5.6.0 or later. See L<perlfunc/our>.
65 This will predeclare all the variables whose names are
66 in the list, allowing you to use them under "use strict", and
67 disabling any typo warnings.
69 Unlike pragmas that affect the C<$^H> hints variable, the C<use vars> and
70 C<use subs> declarations are not BLOCK-scoped. They are thus effective
71 for the entire file in which they appear. You may not rescind such
72 declarations with C<no vars> or C<no subs>.
74 Packages such as the B<AutoLoader> and B<SelfLoader> that delay
75 loading of subroutines within packages can create problems with
76 package lexicals defined using C<my()>. While the B<vars> pragma
77 cannot duplicate the effect of package lexicals (total transparency
78 outside of the package), it can act as an acceptable substitute by
79 pre-declaring global symbols, ensuring their availability to the
80 later-loaded routines.
82 See L<perlmodlib/Pragmatic Modules>.