This is my patch patch.1g for perl5.001.
[p5sagit/p5-mst-13.2.git] / lib / strict.pm
CommitLineData
a0d0e21e 1package strict;
2
f06db76b 3=head1 NAME
4
5strict - Perl pragma to restrict unsafe constructs
6
7=head1 SYNOPSIS
8
9 use strict;
10
11 use strict "vars";
12 use strict "refs";
13 use strict "subs";
14
15 use strict;
16 no strict "vars";
17
18=head1 DESCRIPTION
19
20If no import list is supplied, all possible restrictions are assumed.
21(This is the safest mode to operate in, but is sometimes too strict for
22casual programming.) Currently, there are three possible things to be
23strict about: "subs", "vars", and "refs".
24
25=over 6
26
27=item C<strict refs>
28
29This generates a runtime error if you
30use symbolic references (see L<perlref>).
31
32 use strict 'refs';
33 $ref = \$foo;
34 print $$ref; # ok
35 $ref = "foo";
36 print $$ref; # runtime error; normally ok
37
38=item C<strict vars>
39
40This generates a compile-time error if you access a variable that wasn't
41localized via C<my()> or wasn't fully qualified. Because this is to avoid
42variable suicide problems and subtle dynamic scoping issues, a merely
43local() variable isn't good enough. See L<perlfunc/my> and
44L<perlfunc/local>.
45
46 use strict 'vars';
47 $X::foo = 1; # ok, fully qualified
48 my $foo = 10; # ok, my() var
49 local $foo = 9; # blows up
50
51The local() generated a compile-time error because you just touched a global
52name without fully qualifying it.
53
54=item C<strict subs>
55
56This disables the poetry optimization,
57generating a compile-time error if you
58try to use a bareword identifier that's not a subroutine.
59
60 use strict 'subs';
61 $SIG{PIPE} = Plumber; # blows up
62 $SIG{"PIPE"} = "Plumber"; # just fine
63
64=back
65
66See L<perlmod/Pragmatic Modules>.
67
68
69=cut
70
a0d0e21e 71sub bits {
72 my $bits = 0;
73 foreach $sememe (@_) {
74 $bits |= 0x00000002 if $sememe eq 'refs';
75 $bits |= 0x00000200 if $sememe eq 'subs';
76 $bits |= 0x00000400 if $sememe eq 'vars';
77 }
78 $bits;
79}
80
81sub import {
82 shift;
83 $^H |= bits(@_ ? @_ : qw(refs subs vars));
84}
85
86sub unimport {
87 shift;
88 $^H &= ~ bits(@_ ? @_ : qw(refs subs vars));
89}
90
911;