3 $strict::VERSION = "1.11";
5 my ( %bitmask, %explicit_bitmask );
8 # Verify that we're called correctly so that strictures will work.
9 # Can't use Carp, since Carp uses us!
10 # see also warnings.pm.
11 die sprintf "Incorrect use of pragma '%s' at %s line %d.\n", __PACKAGE__, +(caller)[1,2]
12 if __FILE__ !~ ( '(?x) \b '.__PACKAGE__.' \.pmc? \z' )
13 && __FILE__ =~ ( '(?x) \b (?i:'.__PACKAGE__.') \.pmc? \z' );
28 $bits |= $_ for values %bitmask;
30 my $inline_all_bits = $bits;
31 *all_bits = sub () { $inline_all_bits };
34 $bits |= $_ for values %explicit_bitmask;
36 my $inline_all_explicit_bits = $bits;
37 *all_explicit_bits = sub () { $inline_all_explicit_bits };
44 if (exists $bitmask{$s}) {
45 $^H |= $explicit_bitmask{$s};
47 $bits |= $bitmask{$s};
55 Carp::croak("Unknown 'strict' tag(s) '@wrong'");
62 $^H |= @_ ? &bits : all_bits | all_explicit_bits;
73 $^H |= all_explicit_bits;
82 strict - Perl pragma to restrict unsafe constructs
97 The C<strict> pragma disables certain Perl expressions that could behave
98 unexpectedly or are difficult to debug, turning them into errors. The
99 effect of this pragma is limited to the current file or scope block.
101 If no import list is supplied, all possible restrictions are assumed.
102 (This is the safest mode to operate in, but is sometimes too strict for
103 casual programming.) Currently, there are three possible things to be
104 strict about: "subs", "vars", and "refs".
110 This generates a runtime error if you
111 use symbolic references (see L<perlref>).
117 print $$ref; # runtime error; normally ok
119 print $file "Hi!"; # error; note: no comma after $file
121 There is one exception to this rule:
126 is allowed so that C<goto &$AUTOLOAD> would not break under stricture.
131 This generates a compile-time error if you access a variable that was
132 neither explicitly declared (using any of C<my>, C<our>, C<state>, or C<use
133 vars>) nor fully qualified. (Because this is to avoid variable suicide
134 problems and subtle dynamic scoping issues, a merely C<local> variable isn't
135 good enough.) See L<perlfunc/my>, L<perlfunc/our>, L<perlfunc/state>,
136 L<perlfunc/local>, and L<vars>.
139 $X::foo = 1; # ok, fully qualified
140 my $foo = 10; # ok, my() var
141 local $baz = 9; # blows up, $baz not declared before
144 our $bar; # Declares $bar in current package
145 $bar = 'HgS'; # ok, global declared via pragma
147 The local() generated a compile-time error because you just touched a global
148 name without fully qualifying it.
150 Because of their special use by sort(), the variables $a and $b are
151 exempted from this check.
155 This disables the poetry optimization, generating a compile-time error if
156 you try to use a bareword identifier that's not a subroutine, unless it
157 is a simple identifier (no colons) and that it appears in curly braces or
158 on the left hand side of the C<< => >> symbol.
161 $SIG{PIPE} = Plumber; # blows up
162 $SIG{PIPE} = "Plumber"; # fine: quoted string is always ok
163 $SIG{PIPE} = \&Plumber; # preferred form
167 See L<perlmodlib/Pragmatic Modules>.
171 C<strict 'subs'>, with Perl 5.6.1, erroneously permitted to use an unquoted
172 compound identifier (e.g. C<Foo::Bar>) as a hash key (before C<< => >> or
173 inside curlies), but without forcing it always to a literal string.
175 Starting with Perl 5.8.1 strict is strict about its restrictions:
176 if unknown restrictions are used, the strict pragma will abort with
178 Unknown 'strict' tag(s) '...'
180 As of version 1.04 (Perl 5.10), strict verifies that it is used as
181 "strict" to avoid the dreaded Strict trap on case insensitive file