[win32] support win32_select(0,0,0,msec) (winsock doesn't)
[p5sagit/p5-mst-13.2.git] / lib / vars.pm
CommitLineData
c07a80fd 1package vars;
2
fb73857a 3require 5.002;
4
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.
10require Carp if $] < 5.00450;
11
12sub import {
13 my $callpack = caller;
14 my ($pack, @imports, $sym, $ch) = @_;
15 foreach $sym (@imports) {
16 if ($sym =~ /::/) {
17 require Carp;
18 Carp::croak("Can't declare another package's variables");
19 }
20 ($ch, $sym) = unpack('a1a*', $sym);
21 *{"${callpack}::$sym"} =
22 ( $ch eq "\$" ? \$ {"${callpack}::$sym"}
23 : $ch eq "\@" ? \@ {"${callpack}::$sym"}
24 : $ch eq "\%" ? \% {"${callpack}::$sym"}
25 : $ch eq "\*" ? \* {"${callpack}::$sym"}
26 : $ch eq "\&" ? \& {"${callpack}::$sym"}
27 : do {
28 require Carp;
29 Carp::croak("'$ch$sym' is not a valid variable name\n");
30 });
31 }
32};
33
341;
35__END__
36
c07a80fd 37=head1 NAME
38
39vars - Perl pragma to predeclare global variable names
40
41=head1 SYNOPSIS
42
43 use vars qw($frob @mung %seen);
44
45=head1 DESCRIPTION
46
47This will predeclare all the variables whose names are
48in the list, allowing you to use them under "use strict", and
49disabling any typo warnings.
50
55497cff 51Unlike pragmas that affect the C<$^H> hints variable, the C<use vars> and
52C<use subs> declarations are not BLOCK-scoped. They are thus effective
53for the entire file in which they appear. You may not rescind such
54declarations with C<no vars> or C<no subs>.
55
7a2e2cd6 56Packages such as the B<AutoLoader> and B<SelfLoader> that delay
57loading of subroutines within packages can create problems with
58package lexicals defined using C<my()>. While the B<vars> pragma
59cannot duplicate the effect of package lexicals (total transparency
60outside of the package), it can act as an acceptable substitute by
61pre-declaring global symbols, ensuring their availability to the
62later-loaded routines.
c6f23971 63
c07a80fd 64See L<perlmod/Pragmatic Modules>.
65
66=cut