Counter Strike : Global Offensive Source Code
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.

136 lines
3.2 KiB

  1. package strict;
  2. $strict::VERSION = "1.03";
  3. my %bitmask = (
  4. refs => 0x00000002,
  5. subs => 0x00000200,
  6. vars => 0x00000400
  7. );
  8. sub bits {
  9. my $bits = 0;
  10. my @wrong;
  11. foreach my $s (@_) {
  12. push @wrong, $s unless exists $bitmask{$s};
  13. $bits |= $bitmask{$s} || 0;
  14. }
  15. if (@wrong) {
  16. require Carp;
  17. Carp::croak("Unknown 'strict' tag(s) '@wrong'");
  18. }
  19. $bits;
  20. }
  21. my $default_bits = bits(qw(refs subs vars));
  22. sub import {
  23. shift;
  24. $^H |= @_ ? bits(@_) : $default_bits;
  25. }
  26. sub unimport {
  27. shift;
  28. $^H &= ~ (@_ ? bits(@_) : $default_bits);
  29. }
  30. 1;
  31. __END__
  32. =head1 NAME
  33. strict - Perl pragma to restrict unsafe constructs
  34. =head1 SYNOPSIS
  35. use strict;
  36. use strict "vars";
  37. use strict "refs";
  38. use strict "subs";
  39. use strict;
  40. no strict "vars";
  41. =head1 DESCRIPTION
  42. If no import list is supplied, all possible restrictions are assumed.
  43. (This is the safest mode to operate in, but is sometimes too strict for
  44. casual programming.) Currently, there are three possible things to be
  45. strict about: "subs", "vars", and "refs".
  46. =over 6
  47. =item C<strict refs>
  48. This generates a runtime error if you
  49. use symbolic references (see L<perlref>).
  50. use strict 'refs';
  51. $ref = \$foo;
  52. print $$ref; # ok
  53. $ref = "foo";
  54. print $$ref; # runtime error; normally ok
  55. $file = "STDOUT";
  56. print $file "Hi!"; # error; note: no comma after $file
  57. There is one exception to this rule:
  58. $bar = \&{'foo'};
  59. &$bar;
  60. is allowed so that C<goto &$AUTOLOAD> would not break under stricture.
  61. =item C<strict vars>
  62. This generates a compile-time error if you access a variable that wasn't
  63. declared via C<our> or C<use vars>,
  64. localized via C<my()>, or wasn't fully qualified. Because this is to avoid
  65. variable suicide problems and subtle dynamic scoping issues, a merely
  66. local() variable isn't good enough. See L<perlfunc/my> and
  67. L<perlfunc/local>.
  68. use strict 'vars';
  69. $X::foo = 1; # ok, fully qualified
  70. my $foo = 10; # ok, my() var
  71. local $foo = 9; # blows up
  72. package Cinna;
  73. our $bar; # Declares $bar in current package
  74. $bar = 'HgS'; # ok, global declared via pragma
  75. The local() generated a compile-time error because you just touched a global
  76. name without fully qualifying it.
  77. Because of their special use by sort(), the variables $a and $b are
  78. exempted from this check.
  79. =item C<strict subs>
  80. This disables the poetry optimization, generating a compile-time error if
  81. you try to use a bareword identifier that's not a subroutine, unless it
  82. is a simple identifier (no colons) and that it appears in curly braces or
  83. on the left hand side of the C<< => >> symbol.
  84. use strict 'subs';
  85. $SIG{PIPE} = Plumber; # blows up
  86. $SIG{PIPE} = "Plumber"; # just fine: quoted string is always ok
  87. $SIG{PIPE} = \&Plumber; # preferred form
  88. =back
  89. See L<perlmodlib/Pragmatic Modules>.
  90. =head1 HISTORY
  91. C<strict 'subs'>, with Perl 5.6.1, erroneously permitted to use an unquoted
  92. compound identifier (e.g. C<Foo::Bar>) as a hash key (before C<< => >> or
  93. inside curlies), but without forcing it always to a literal string.
  94. Starting with Perl 5.8.1 strict is strict about its restrictions:
  95. if unknown restrictions are used, the strict pragma will abort with
  96. Unknown 'strict' tag(s) '...'
  97. =cut