7 use warnings::register;
8 use strict qw(vars subs);
11 my $callpack = caller;
12 my ($pack, @imports) = @_;
15 if (($ch, $sym) = /^([\$\@\%\*\&])(.+)/) {
17 # time for a more-detailed check-up
18 if ($sym =~ /^\w+[[{].*[]}]$/) {
20 Carp::croak("Can't declare individual elements of hash or array");
21 } elsif (warnings::enabled() and length($sym) == 1 and $sym !~ tr/a-zA-Z//) {
22 warnings::warn("No need to declare built-in vars");
23 } elsif (($^H &= strict::bits('vars'))) {
25 Carp::croak("'$_' is not a valid variable name under strict vars");
28 $sym = "${callpack}::$sym" unless $sym =~ /::/;
30 ( $ch eq "\$" ? \$$sym
31 : $ch eq "\@" ? \@$sym
32 : $ch eq "\%" ? \%$sym
33 : $ch eq "\*" ? \*$sym
34 : $ch eq "\&" ? \&$sym
37 Carp::croak("'$_' is not a valid variable name");
41 Carp::croak("'$_' is not a valid variable name");
51 vars - Perl pragma to predeclare global variable names (obsolete)
55 use vars qw($frob @mung %seen);
59 NOTE: For variables in the current package, the functionality provided
60 by this pragma has been superseded by C<our> declarations, available
61 in Perl v5.6.0 or later. See L<perlfunc/our>.
63 This will predeclare all the variables whose names are
64 in the list, allowing you to use them under "use strict", and
65 disabling any typo warnings.
67 Unlike pragmas that affect the C<$^H> hints variable, the C<use vars> and
68 C<use subs> declarations are not BLOCK-scoped. They are thus effective
69 for the entire file in which they appear. You may not rescind such
70 declarations with C<no vars> or C<no subs>.
72 Packages such as the B<AutoLoader> and B<SelfLoader> that delay
73 loading of subroutines within packages can create problems with
74 package lexicals defined using C<my()>. While the B<vars> pragma
75 cannot duplicate the effect of package lexicals (total transparency
76 outside of the package), it can act as an acceptable substitute by
77 pre-declaring global symbols, ensuring their availability to the
78 later-loaded routines.
80 See L<perlmodlib/Pragmatic Modules>.