File Coverage

blib/lib/evil.pm
Criterion Covered Total %
statement 37 37 100.0
branch 18 18 100.0
condition 9 9 100.0
subroutine 6 6 100.0
pod n/a
total 70 70 100.0


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