[system] / trunk / pg / lib / ww_strict.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/ww_strict.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2157 - (download) (as text) (annotate)
Sat May 22 20:46:20 2004 UTC (15 years, 9 months ago) by gage
File size: 2814 byte(s)
We are using our own version of strict.pm that has a require Carp;  commented out.
This is included in be_strict which is used to implement strict within PG macro files
which need to be evaluted inside the Safe compartment

    1 package strict;
    2 
    3 =head1 NAME
    4 
    5 strict - 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 
   20 If 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
   22 casual programming.)  Currently, there are three possible things to be
   23 strict about:  "subs", "vars", and "refs".
   24 
   25 =over 6
   26 
   27 =item C<strict refs>
   28 
   29 This generates a runtime error if you
   30 use 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     $file = "STDOUT";
   38     print $file "Hi!";  # error; note: no comma after $file
   39 
   40 =item C<strict vars>
   41 
   42 This generates a compile-time error if you access a variable that wasn't
   43 declared via "our" or C<use vars>,
   44 localized via C<my()>, or wasn't fully qualified.  Because this is to avoid
   45 variable suicide problems and subtle dynamic scoping issues, a merely
   46 local() variable isn't good enough.  See L<perlfunc/my> and
   47 L<perlfunc/local>.
   48 
   49     use strict 'vars';
   50     $X::foo = 1;   # ok, fully qualified
   51     my $foo = 10;  # ok, my() var
   52     local $foo = 9;  # blows up
   53 
   54     package Cinna;
   55     our $bar;     # Declares $bar in current package
   56     $bar = 'HgS';   # ok, global declared via pragma
   57 
   58 The local() generated a compile-time error because you just touched a global
   59 name without fully qualifying it.
   60 
   61 Because of their special use by sort(), the variables $a and $b are
   62 exempted from this check.
   63 
   64 =item C<strict subs>
   65 
   66 This disables the poetry optimization, generating a compile-time error if
   67 you try to use a bareword identifier that's not a subroutine, unless it
   68 appears in curly braces or on the left hand side of the "=E<gt>" symbol.
   69 
   70 
   71     use strict 'subs';
   72     $SIG{PIPE} = Plumber;     # blows up
   73     $SIG{PIPE} = "Plumber";   # just fine: bareword in curlies always ok
   74     $SIG{PIPE} = \&Plumber;   # preferred form
   75 
   76 
   77 
   78 =back
   79 
   80 See L<perlmodlib/Pragmatic Modules>.
   81 
   82 
   83 =cut
   84 
   85 $strict::VERSION = "1.01";
   86 
   87 my %bitmask = (
   88 refs => 0x00000002,
   89 subs => 0x00000200,
   90 vars => 0x00000400
   91 );
   92 #require Carp;
   93 # sub bits {
   94 #     my $bits = 0;
   95 #     foreach my $s (@_){ $bits |= $bitmask{$s} || 0; };
   96 #     $bits;
   97 # }
   98 sub bits {
   99     my $bits = 0;
  100     my @wrong;
  101     foreach my $s (@_) {
  102   push @wrong, $s unless exists $bitmask{$s};
  103         $bits |= $bitmask{$s} || 0;
  104     }
  105     if (@wrong) {
  106 #        require Carp;
  107 
  108         Carp::croak("Unknown 'strict' tag(s) '@wrong'");
  109     }
  110     $bits;
  111 }
  112 my $default_bits = bits(qw(refs subs vars));
  113 
  114 sub import {
  115     shift;
  116     $^H |= @_ ? bits(@_) : $default_bits;
  117 }
  118 
  119 sub unimport {
  120     shift;
  121     $^H &= ~ (@_ ? bits(@_) : $default_bits);
  122 }
  123 
  124 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9