patchlevel up to 72, update Changes, minor tweaks to win32/config*
[p5sagit/p5-mst-13.2.git] / ext / re / re.pm
1 package re;
2
3 $VERSION = 0.02;
4
5 =head1 NAME
6
7 re - Perl pragma to alter regular expression behaviour
8
9 =head1 SYNOPSIS
10
11     use re 'taint';
12     ($x) = ($^X =~ /^(.*)$/s);     # $x is tainted here
13
14     $pat = '(?{ $foo = 1 })';
15     use re 'eval';
16     /foo${pat}bar/;                # won't fail (when not under -T switch)
17
18     {
19         no re 'taint';             # the default
20         ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
21
22         no re 'eval';              # the default
23         /foo${pat}bar/;            # disallowed (with or without -T switch)
24     }
25
26     use re 'debug';
27     /^(.*)$/s;                     # output debugging info 
28                                    # during compile and run time
29
30 =head1 DESCRIPTION
31
32 When C<use re 'taint'> is in effect, and a tainted string is the target
33 of a regex, the regex memories (or values returned by the m// operator
34 in list context) are tainted.  This feature is useful when regex operations
35 on tainted data aren't meant to extract safe substrings, but to perform
36 other transformations.
37
38 When C<use re 'eval'> is in effect, a regex is allowed to contain
39 C<(?{ ... })> zero-width assertions even if regular expression contains
40 variable interpolation.  That is normally disallowed, since it is a 
41 potential security risk.  Note that this pragma is ignored when the regular
42 expression is obtained from tainted data, i.e.  evaluation is always
43 disallowed with tainted regular expresssions.  See L<perlre/(?{ code })>.
44
45 For the purpose of this pragma, interpolation of preexisting regular 
46 expressions is I<not> considered a variable interpolation, thus
47
48     /foo${pat}bar/
49
50 I<is> allowed if $pat is a preexisting regular expressions, even 
51 if $pat contains C<(?{ ... })> assertions.
52
53 When C<use re 'debug'> is in effect, perl emits debugging messages when 
54 compiling and using regular expressions.  The output is the same as that
55 obtained by running a C<-DDEBUGGING>-enabled perl interpreter with the
56 B<-Dr> switch. It may be quite voluminous depending on the complexity
57 of the match.
58 See L<perldebug/"Debugging regular expressions"> for additional info.
59
60 I<The directive C<use re 'debug'> is not lexically scoped.>  It has 
61 both compile-time and run-time effects.
62
63 See L<perlmodlib/Pragmatic Modules>.
64
65 =cut
66
67 my %bitmask = (
68 taint   => 0x00100000,
69 eval    => 0x00200000,
70 );
71
72 sub bits {
73     my $on = shift;
74     my $bits = 0;
75     unless(@_) {
76         require Carp;
77         Carp::carp("Useless use of \"re\" pragma");
78     }
79     foreach my $s (@_){
80       if ($s eq 'debug') {
81           eval <<'EOE';
82             use DynaLoader;
83             @ISA = ('DynaLoader');
84             bootstrap re;
85 EOE
86           install() if $on;
87           uninstall() unless $on;
88           next;
89       }
90       $bits |= $bitmask{$s} || 0;
91     }
92     $bits;
93 }
94
95 sub import {
96     shift;
97     $^H |= bits(1,@_);
98 }
99
100 sub unimport {
101     shift;
102     $^H &= ~ bits(0,@_);
103 }
104
105 1;