3 $strict::VERSION = "1.06";
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 if (exists $bitmask{$s}) {
23 $^H{"strict/$s"} = undef;
25 else { push @wrong, $s };
26 $bits |= $bitmask{$s} || 0;
30 Carp::croak("Unknown 'strict' tag(s) '@wrong'");
35 my @default_bits = qw(refs subs vars);
39 $^H |= bits(@_ ? @_ : @default_bits);
44 $^H &= ~ bits(@_ ? @_ : @default_bits);
52 strict - Perl pragma to restrict unsafe constructs
67 If no import list is supplied, all possible restrictions are assumed.
68 (This is the safest mode to operate in, but is sometimes too strict for
69 casual programming.) Currently, there are three possible things to be
70 strict about: "subs", "vars", and "refs".
76 This generates a runtime error if you
77 use symbolic references (see L<perlref>).
83 print $$ref; # runtime error; normally ok
85 print $file "Hi!"; # error; note: no comma after $file
87 There is one exception to this rule:
92 is allowed so that C<goto &$AUTOLOAD> would not break under stricture.
97 This generates a compile-time error if you access a variable that was
98 neither explicitly declared (using any of C<my>, C<our>, C<state>, or C<use
99 vars>) nor fully qualified. (Because this is to avoid variable suicide
100 problems and subtle dynamic scoping issues, a merely C<local> variable isn't
101 good enough.) See L<perlfunc/my>, L<perlfunc/our>, L<perlfunc/state>,
102 L<perlfunc/local>, and L<vars>.
105 $X::foo = 1; # ok, fully qualified
106 my $foo = 10; # ok, my() var
107 local $baz = 9; # blows up, $baz not declared before
110 our $bar; # Declares $bar in current package
111 $bar = 'HgS'; # ok, global declared via pragma
113 The local() generated a compile-time error because you just touched a global
114 name without fully qualifying it.
116 Because of their special use by sort(), the variables $a and $b are
117 exempted from this check.
121 This disables the poetry optimization, generating a compile-time error if
122 you try to use a bareword identifier that's not a subroutine, unless it
123 is a simple identifier (no colons) and that it appears in curly braces or
124 on the left hand side of the C<< => >> symbol.
127 $SIG{PIPE} = Plumber; # blows up
128 $SIG{PIPE} = "Plumber"; # just fine: quoted string is always ok
129 $SIG{PIPE} = \&Plumber; # preferred form
133 See L<perlmodlib/Pragmatic Modules>.
137 C<strict 'subs'>, with Perl 5.6.1, erroneously permitted to use an unquoted
138 compound identifier (e.g. C<Foo::Bar>) as a hash key (before C<< => >> or
139 inside curlies), but without forcing it always to a literal string.
141 Starting with Perl 5.8.1 strict is strict about its restrictions:
142 if unknown restrictions are used, the strict pragma will abort with
144 Unknown 'strict' tag(s) '...'
146 As of version 1.04 (Perl 5.10), strict verifies that it is used as
147 "strict" to avoid the dreaded Strict trap on case insensitive file