| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | package evil; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 11 | my $INTERMEDIATE = __PACKAGE__.'/intermediate'; | |||||||||||||||||||||||||||
| 11 | 11 | my $LAX = __PACKAGE__.'/lax'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 11 | our $VERSION = 0.003002; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 11 | our %tainted; | |||||||||||||||||||||||||||
| 16 | 11 | our %wants_strict; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 15 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 19 | 15 | ▶ | croak "Cannot load evil module when \"no evil ':strict'\" is in effect" if %wants_strict; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 13 | ▶ | my $hinthash = (caller 0)[10] || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
(caller 0)[10] || {}
MC/DC100%1/1
(caller 0)[10] || {}
(caller 0)[10]
Truth table100%2/2
A
A= (caller 0)[10]
| |||||||||||||||||||||||||||||
| 22 | 13 | ▶ | croak "Current module requested no evilness" if $hinthash->{$LAX}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 11 | ▶ | $hinthash = (caller 3)[10] || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
(caller 3)[10] || {}
MC/DC100%1/1
(caller 3)[10] || {}
(caller 3)[10]
Truth table100%2/2
A
A= (caller 3)[10]
| |||||||||||||||||||||||||||||
| 25 | 11 | ▶ | croak "Cannot load evil module when parent requested \"no evil ':lax'\"" if $hinthash->{$LAX}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 9 | my $level = 4; | |||||||||||||||||||||||||||
| 28 | 9 | my @caller; | |||||||||||||||||||||||||||
| 29 | 9 | ▶ | while (@caller = caller $level) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 30 | ▶ | $hinthash = $caller[10] || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$caller[10] || {}
MC/DC100%1/1
$caller[10] || {}
$caller[10]
Truth table100%2/2
A
A= $caller[10]
| |||||||||||||||||||||||||||||
| 31 | croak "Cannot load evil module when ancestor requested \"no evil ':intermediate'\"" | ||||||||||||||||||||||||||||
| 32 | 30 | ▶ | if $hinthash->{$INTERMEDIATE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 29 | $level++; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | $tainted{caller()} = 1; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 19 | ▶ | sub unimport { | ||||||||||||||||||||||||||
|
Subroutine
unimport: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 40 | 19 | my $strict_arg = grep /^:strict$/i, @_; | |||||||||||||||||||||||||||
| 41 | 19 | my $intermediate_arg = grep /^:intermediate$/i, @_; | |||||||||||||||||||||||||||
| 42 | 19 | my $lax_arg = grep /^:lax$/i, @_; | |||||||||||||||||||||||||||
| 43 | 19 | my $disable_arg = grep /^:disable$/i, @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 19 | ▶ | if (!$disable_arg && $tainted{caller()}) { # caller is evil | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $disable_arg and $evil::tainted{caller()}
MC/DC100%2/2
not $disable_arg and $evil::tainted{caller()}
not $disable_arg
$evil::tainted{caller()}
Truth table100%3/3
not(A) and B
A= not $disable_argB= $evil::tainted{caller()}
| |||||||||||||||||||||||||||||
| 46 | 3 | croak 'Current module is evil' | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 16 | ▶ | if ($strict_arg) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 50 | 6 | $wants_strict{caller()} = 1; | |||||||||||||||||||||||||||
| 51 | 6 | ▶ | croak "Evil module already loaded. Cannot enforce \"no evil ':strict'\"" if %tainted | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } elsif ($lax_arg) { | ||||||||||||||||||||||||||||
| 53 | 4 | $^H{$LAX} = 1 | |||||||||||||||||||||||||||
| 54 | } elsif ($disable_arg) { | ||||||||||||||||||||||||||||
| 55 | 2 | delete $wants_strict{caller()}; | |||||||||||||||||||||||||||
| 56 | 2 | delete $^H{$LAX}; | |||||||||||||||||||||||||||
| 57 | 2 | delete $^H{$INTERMEDIATE}; | |||||||||||||||||||||||||||
| 58 | } else { # $intermediate_arg or no arg | ||||||||||||||||||||||||||||
| 59 | 4 | $^H{$INTERMEDIATE} = $^H{$LAX} = 1 | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 11 | 1; | |||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||