Commit | Line | Data |
b3eb6a9b |
1 | package re; |
2 | |
3 | =head1 NAME |
4 | |
5 | re - 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 | |
16 | When C<use re 'taint'> is in effect, and a tainted string is the target |
17 | of a regex, the regex memories (or values returned by the m// operator |
18 | in list context) are tainted. |
19 | |
20 | This feature is useful when regex operations on tainted data aren't |
21 | meant to extract safe substrings, but to perform other transformations. |
22 | |
23 | See L<perlmodlib/Pragmatic Modules>. |
24 | |
25 | =cut |
26 | |
27 | my %bitmask = ( |
11162842 |
28 | taint => 0x00100000 |
b3eb6a9b |
29 | ); |
30 | |
31 | sub 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 | |
41 | sub import { |
42 | shift; |
43 | $^H |= bits(@_); |
44 | } |
45 | |
46 | sub unimport { |
47 | shift; |
48 | $^H &= ~ bits(@_); |
49 | } |
50 | |
51 | 1; |