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