3 $strict::VERSION = "1.04";
5 # Verify that we're called correctly so that strictures will work.
6 unless ( __FILE__ =~ /(^|[\/\\])\Q${\__PACKAGE__}\E\.pmc?$/ ) {
7 # Can't use Carp, since Carp uses us!
8 my (undef, $f, $l) = caller;
9 die("Incorrect use of pragma '${\__PACKAGE__}' at $f line $l.\n");
22 push @wrong, $s unless exists $bitmask{$s};
23 $bits |= $bitmask{$s} || 0;
27 Carp::croak("Unknown 'strict' tag(s) '@wrong'");
32 my $default_bits = bits(qw(refs subs vars));
36 $^H |= @_ ? bits(@_) : $default_bits;
41 $^H &= ~ (@_ ? bits(@_) : $default_bits);
49 strict - Perl pragma to restrict unsafe constructs
64 If no import list is supplied, all possible restrictions are assumed.
65 (This is the safest mode to operate in, but is sometimes too strict for
66 casual programming.) Currently, there are three possible things to be
67 strict about: "subs", "vars", and "refs".
73 This generates a runtime error if you
74 use symbolic references (see L<perlref>).
80 print $$ref; # runtime error; normally ok
82 print $file "Hi!"; # error; note: no comma after $file
84 There is one exception to this rule:
89 is allowed so that C<goto &$AUTOLOAD> would not break under stricture.
94 This generates a compile-time error if you access a variable that wasn't
95 declared via C<our> or C<use vars>,
96 localized via C<my()>, or wasn't fully qualified. Because this is to avoid
97 variable suicide problems and subtle dynamic scoping issues, a merely
98 local() variable isn't good enough. See L<perlfunc/my> and
102 $X::foo = 1; # ok, fully qualified
103 my $foo = 10; # ok, my() var
104 local $foo = 9; # blows up
107 our $bar; # Declares $bar in current package
108 $bar = 'HgS'; # ok, global declared via pragma
110 The local() generated a compile-time error because you just touched a global
111 name without fully qualifying it.
113 Because of their special use by sort(), the variables $a and $b are
114 exempted from this check.
118 This disables the poetry optimization, generating a compile-time error if
119 you try to use a bareword identifier that's not a subroutine, unless it
120 is a simple identifier (no colons) and that it appears in curly braces or
121 on the left hand side of the C<< => >> symbol.
124 $SIG{PIPE} = Plumber; # blows up
125 $SIG{PIPE} = "Plumber"; # just fine: quoted string is always ok
126 $SIG{PIPE} = \&Plumber; # preferred form
130 See L<perlmodlib/Pragmatic Modules>.
134 C<strict 'subs'>, with Perl 5.6.1, erroneously permitted to use an unquoted
135 compound identifier (e.g. C<Foo::Bar>) as a hash key (before C<< => >> or
136 inside curlies), but without forcing it always to a literal string.
138 Starting with Perl 5.8.1 strict is strict about its restrictions:
139 if unknown restrictions are used, the strict pragma will abort with
141 Unknown 'strict' tag(s) '...'
143 As of version 1.04 (Perl 5.10), strict verifies that it is used as
144 "strict" to avoid the dreaded Strict trap on case insensitive file