Start anew
[git/jnareb-git.git] / lib / perl5 / 5.6.1 / vars.pm
blob39a15bd312bb88a039731ec9a969584a759df4c7
1 package vars;
3 require 5.002;
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;
12 use warnings::register;
13 require strict;
15 sub import {
16 my $callpack = caller;
17 my ($pack, @imports, $sym, $ch) = @_;
18 foreach $sym (@imports) {
19 ($ch, $sym) = unpack('a1a*', $sym);
20 if ($sym =~ tr/A-Za-z_0-9//c) {
21 # time for a more-detailed check-up
22 if ($sym =~ /::/) {
23 require Carp;
24 Carp::croak("Can't declare another package's variables");
25 } elsif ($sym =~ /^\w+[[{].*[]}]$/) {
26 require Carp;
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("'$ch$sym' is not a valid variable name under strict vars");
34 *{"${callpack}::$sym"} =
35 ( $ch eq "\$" ? \$ {"${callpack}::$sym"}
36 : $ch eq "\@" ? \@ {"${callpack}::$sym"}
37 : $ch eq "\%" ? \% {"${callpack}::$sym"}
38 : $ch eq "\*" ? \* {"${callpack}::$sym"}
39 : $ch eq "\&" ? \& {"${callpack}::$sym"}
40 : do {
41 require Carp;
42 Carp::croak("'$ch$sym' is not a valid variable name");
43 });
48 __END__
50 =head1 NAME
52 vars - Perl pragma to predeclare global variable names (obsolete)
54 =head1 SYNOPSIS
56 use vars qw($frob @mung %seen);
58 =head1 DESCRIPTION
60 NOTE: The functionality provided by this pragma has been superseded
61 by C<our> declarations, available in Perl v5.6.0 or later. See
62 L<perlfunc/our>.
64 This will predeclare all the variables whose names are
65 in the list, allowing you to use them under "use strict", and
66 disabling any typo warnings.
68 Unlike pragmas that affect the C<$^H> hints variable, the C<use vars> and
69 C<use subs> declarations are not BLOCK-scoped. They are thus effective
70 for the entire file in which they appear. You may not rescind such
71 declarations with C<no vars> or C<no subs>.
73 Packages such as the B<AutoLoader> and B<SelfLoader> that delay
74 loading of subroutines within packages can create problems with
75 package lexicals defined using C<my()>. While the B<vars> pragma
76 cannot duplicate the effect of package lexicals (total transparency
77 outside of the package), it can act as an acceptable substitute by
78 pre-declaring global symbols, ensuring their availability to the
79 later-loaded routines.
81 See L<perlmodlib/Pragmatic Modules>.
83 =cut