line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package evil; |
3
|
|
|
|
|
|
|
|
4
|
11
|
|
|
11
|
|
9061
|
use 5.008009; |
|
11
|
|
|
|
|
29
|
|
5
|
11
|
|
|
11
|
|
39
|
use strict; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
206
|
|
6
|
11
|
|
|
11
|
|
50
|
use warnings; |
|
11
|
|
|
|
|
10
|
|
|
11
|
|
|
|
|
328
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
41
|
use Carp; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
4601
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $INTERMEDIATE = __PACKAGE__.'/intermediate'; |
11
|
|
|
|
|
|
|
my $LAX = __PACKAGE__.'/lax'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.003; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %tainted; |
16
|
|
|
|
|
|
|
our %wants_strict; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
15
|
100
|
|
15
|
|
3173
|
croak "Cannot load evil module when \"no evil ':strict'\" is in effect" if %wants_strict; |
20
|
|
|
|
|
|
|
|
21
|
13
|
|
100
|
|
|
100
|
my $hinthash = (caller 0)[10] || {}; |
22
|
13
|
100
|
|
|
|
211
|
croak "Current module requested no evilness" if $hinthash->{$LAX}; |
23
|
|
|
|
|
|
|
|
24
|
11
|
|
100
|
|
|
60
|
$hinthash = (caller 3)[10] || {}; |
25
|
11
|
100
|
|
|
|
375
|
croak "Cannot load evil module when parent requested \"no evil ':lax'\"" if $hinthash->{$LAX}; |
26
|
|
|
|
|
|
|
|
27
|
9
|
|
|
|
|
8
|
my $level = 4; |
28
|
9
|
|
|
|
|
9
|
my @caller; |
29
|
9
|
|
|
|
|
47
|
while (@caller = caller $level) { |
30
|
30
|
|
100
|
|
|
83
|
$hinthash = $caller[10] || {}; |
31
|
|
|
|
|
|
|
croak "Cannot load evil module when ancestor requested \"no evil ':intermediate'\"" |
32
|
30
|
100
|
|
|
|
278
|
if $hinthash->{$INTERMEDIATE}; |
33
|
29
|
|
|
|
|
113
|
$level++; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
8
|
|
|
|
|
154
|
$tainted{caller()} = 1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub unimport { |
40
|
19
|
|
|
19
|
|
4931
|
my $strict_arg = grep /^:strict$/i, @_; |
41
|
19
|
|
|
|
|
31
|
my $intermediate_arg = grep /^:intermediate$/i, @_; |
42
|
19
|
|
|
|
|
48
|
my $lax_arg = grep /^:lax$/i, @_; |
43
|
19
|
|
|
|
|
26
|
my $disable_arg = grep /^:disable$/i, @_; |
44
|
|
|
|
|
|
|
|
45
|
19
|
100
|
100
|
|
|
124
|
if (!$disable_arg && $tainted{caller()}) { # caller is evil |
46
|
3
|
|
|
|
|
247
|
croak 'Current module is evil' |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
16
|
100
|
|
|
|
49
|
if ($strict_arg) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
50
|
6
|
|
|
|
|
14
|
$wants_strict{caller()} = 1; |
51
|
6
|
100
|
|
|
|
360
|
croak "Evil module already loaded. Cannot enforce \"no evil ':strict'\"" if %tainted |
52
|
|
|
|
|
|
|
} elsif ($lax_arg) { |
53
|
4
|
|
|
|
|
85
|
$^H{$LAX} = 1 |
54
|
|
|
|
|
|
|
} elsif ($disable_arg) { |
55
|
2
|
|
|
|
|
5
|
delete $wants_strict{caller()}; |
56
|
2
|
|
|
|
|
12
|
delete $^H{$LAX}; |
57
|
2
|
|
|
|
|
46
|
delete $^H{$INTERMEDIATE}; |
58
|
|
|
|
|
|
|
} else { # $intermediate_arg or no arg |
59
|
4
|
|
|
|
|
91
|
$^H{$INTERMEDIATE} = $^H{$LAX} = 1 |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |