source: for-distributions/trunk/bin/windows/perl/lib/vars.pm@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 2.3 KB
Line 
1package vars;
2
3use 5.006;
4
5our $VERSION = '1.01';
6
7use warnings::register;
8use strict qw(vars subs);
9
10sub import {
11 my $callpack = caller;
12 my ($pack, @imports) = @_;
13 my ($sym, $ch);
14 foreach (@imports) {
15 if (($ch, $sym) = /^([\$\@\%\*\&])(.+)/) {
16 if ($sym =~ /\W/) {
17 # time for a more-detailed check-up
18 if ($sym =~ /^\w+[[{].*[]}]$/) {
19 require Carp;
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'))) {
24 require Carp;
25 Carp::croak("'$_' is not a valid variable name under strict vars");
26 }
27 }
28 $sym = "${callpack}::$sym" unless $sym =~ /::/;
29 *$sym =
30 ( $ch eq "\$" ? \$$sym
31 : $ch eq "\@" ? \@$sym
32 : $ch eq "\%" ? \%$sym
33 : $ch eq "\*" ? \*$sym
34 : $ch eq "\&" ? \&$sym
35 : do {
36 require Carp;
37 Carp::croak("'$_' is not a valid variable name");
38 });
39 } else {
40 require Carp;
41 Carp::croak("'$_' is not a valid variable name");
42 }
43 }
44};
45
461;
47__END__
48
49=head1 NAME
50
51vars - Perl pragma to predeclare global variable names (obsolete)
52
53=head1 SYNOPSIS
54
55 use vars qw($frob @mung %seen);
56
57=head1 DESCRIPTION
58
59NOTE: For variables in the current package, the functionality provided
60by this pragma has been superseded by C<our> declarations, available
61in Perl v5.6.0 or later. See L<perlfunc/our>.
62
63This will predeclare all the variables whose names are
64in the list, allowing you to use them under "use strict", and
65disabling any typo warnings.
66
67Unlike pragmas that affect the C<$^H> hints variable, the C<use vars> and
68C<use subs> declarations are not BLOCK-scoped. They are thus effective
69for the entire file in which they appear. You may not rescind such
70declarations with C<no vars> or C<no subs>.
71
72Packages such as the B<AutoLoader> and B<SelfLoader> that delay
73loading of subroutines within packages can create problems with
74package lexicals defined using C<my()>. While the B<vars> pragma
75cannot duplicate the effect of package lexicals (total transparency
76outside of the package), it can act as an acceptable substitute by
77pre-declaring global symbols, ensuring their availability to the
78later-loaded routines.
79
80See L<perlmodlib/Pragmatic Modules>.
81
82=cut
Note: See TracBrowser for help on using the repository browser.