Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.8 KiB

  1. package vars;
  2. require 5.002;
  3. # The following require can't be removed during maintenance
  4. # releases, sadly, because of the risk of buggy code that does
  5. # require Carp; Carp::croak "..."; without brackets dying
  6. # if Carp hasn't been loaded in earlier compile time. :-(
  7. # We'll let those bugs get found on the development track.
  8. require Carp if $] < 5.00450;
  9. use warnings::register;
  10. require strict;
  11. sub import {
  12. my $callpack = caller;
  13. my ($pack, @imports, $sym, $ch) = @_;
  14. foreach $sym (@imports) {
  15. ($ch, $sym) = unpack('a1a*', $sym);
  16. if ($sym =~ tr/A-Za-z_0-9//c) {
  17. # time for a more-detailed check-up
  18. if ($sym =~ /::/) {
  19. require Carp;
  20. Carp::croak("Can't declare another package's variables");
  21. } elsif ($sym =~ /^\w+[[{].*[]}]$/) {
  22. require Carp;
  23. Carp::croak("Can't declare individual elements of hash or array");
  24. } elsif (warnings::enabled() and length($sym) == 1 and $sym !~ tr/a-zA-Z//) {
  25. warnings::warn("No need to declare built-in vars");
  26. } elsif ( $^H &= strict::bits('vars') ) {
  27. Carp::croak("'$ch$sym' is not a valid variable name under strict vars");
  28. }
  29. }
  30. *{"${callpack}::$sym"} =
  31. ( $ch eq "\$" ? \$ {"${callpack}::$sym"}
  32. : $ch eq "\@" ? \@ {"${callpack}::$sym"}
  33. : $ch eq "\%" ? \% {"${callpack}::$sym"}
  34. : $ch eq "\*" ? \* {"${callpack}::$sym"}
  35. : $ch eq "\&" ? \& {"${callpack}::$sym"}
  36. : do {
  37. require Carp;
  38. Carp::croak("'$ch$sym' is not a valid variable name");
  39. });
  40. }
  41. };
  42. 1;
  43. __END__
  44. =head1 NAME
  45. vars - Perl pragma to predeclare global variable names (obsolete)
  46. =head1 SYNOPSIS
  47. use vars qw($frob @mung %seen);
  48. =head1 DESCRIPTION
  49. NOTE: The functionality provided by this pragma has been superseded
  50. by C<our> declarations, available in Perl v5.6.0 or later. See
  51. L<perlfunc/our>.
  52. This will predeclare all the variables whose names are
  53. in the list, allowing you to use them under "use strict", and
  54. disabling any typo warnings.
  55. Unlike pragmas that affect the C<$^H> hints variable, the C<use vars> and
  56. C<use subs> declarations are not BLOCK-scoped. They are thus effective
  57. for the entire file in which they appear. You may not rescind such
  58. declarations with C<no vars> or C<no subs>.
  59. Packages such as the B<AutoLoader> and B<SelfLoader> that delay
  60. loading of subroutines within packages can create problems with
  61. package lexicals defined using C<my()>. While the B<vars> pragma
  62. cannot duplicate the effect of package lexicals (total transparency
  63. outside of the package), it can act as an acceptable substitute by
  64. pre-declaring global symbols, ensuring their availability to the
  65. later-loaded routines.
  66. See L<perlmodlib/Pragmatic Modules>.
  67. =cut