various small tweaks (still fails a few taint tests in {taint,locale}.t)
[p5sagit/p5-mst-13.2.git] / lib / re.pm
CommitLineData
b3eb6a9b 1package re;
2
3=head1 NAME
4
5re - Perl pragma to alter regular expression behaviour
6
7=head1 SYNOPSIS
8
9 ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
10
11 use re "taint";
12 ($x) = ($^X =~ /^(.*)$/s); # $x _is_ tainted here
13
14=head1 DESCRIPTION
15
16When C<use re 'taint'> is in effect, and a tainted string is the target
17of a regex, the regex memories (or values returned by the m// operator
18in list context) are tainted.
19
20This feature is useful when regex operations on tainted data aren't
21meant to extract safe substrings, but to perform other transformations.
22
23See L<perlmodlib/Pragmatic Modules>.
24
25=cut
26
27my %bitmask = (
11162842 28taint => 0x00100000
b3eb6a9b 29);
30
31sub bits {
32 my $bits = 0;
33 unless(@_) {
34 require Carp;
35 Carp::carp("Useless use of \"re\" pragma");
36 }
37 foreach my $s (@_){ $bits |= $bitmask{$s} || 0; };
38 $bits;
39}
40
41sub import {
42 shift;
43 $^H |= bits(@_);
44}
45
46sub unimport {
47 shift;
48 $^H &= ~ bits(@_);
49}
50
511;