This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.002_01: lib/ExtUtils/Install.pm
[perl5.git] / lib / vars.pm
CommitLineData
c07a80fd 1package vars;
2
3=head1 NAME
4
5vars - Perl pragma to predeclare global variable names
6
7=head1 SYNOPSIS
8
9 use vars qw($frob @mung %seen);
10
11=head1 DESCRIPTION
12
13This will predeclare all the variables whose names are
14in the list, allowing you to use them under "use strict", and
15disabling any typo warnings.
16
17See L<perlmod/Pragmatic Modules>.
18
19=cut
20require 5.000;
21use Carp;
22
23sub import {
24 my $callpack = caller;
25 my ($pack, @imports, $sym, $ch) = @_;
26 foreach $sym (@imports) {
27 croak "Can't declare another package's variables" if $sym =~ /::/;
28 ($ch, $sym) = unpack('a1a*', $sym);
29 *{"${callpack}::$sym"} =
30 ( $ch eq "\$" ? \$ {"${callpack}::$sym"}
31 : $ch eq "\@" ? \@ {"${callpack}::$sym"}
32 : $ch eq "\%" ? \% {"${callpack}::$sym"}
33 : $ch eq "\*" ? \* {"${callpack}::$sym"}
34 : $ch eq "\&" ? \& {"${callpack}::$sym"}
35 : croak "'$ch$sym' is not a valid variable name\n");
36 }
37};
38
391;