]> iEval git - acme-evil.git/blobdiff - lib/evil.pm
Make (un)import arguments case-insensitive
[acme-evil.git] / lib / evil.pm
index db7968d102edd2ca1f1275b9ba522d966366dc0d..c5faa09bf2163ff7b4cf3b16ca3639d603866e82 100644 (file)
@@ -7,22 +7,56 @@ use warnings;
 
 use Carp;
 
-our $VERSION = 0.001;
+my $INTERMEDIATE = __PACKAGE__.'/intermediate';
+my $LAX          = __PACKAGE__.'/lax';
+
+our $VERSION = 0.002;
 
 our %tainted;
-our $strict;
+our %wants_strict;
 
 sub import {
+       croak "Cannot load evil module when \"no evil ':strict'\" is in effect" if %wants_strict;
+
+       my $hinthash = (caller 0)[10] || {};
+       croak "Current module requested no evilness" if $hinthash->{$LAX};
+
+       $hinthash = (caller 3)[10] || {};
+       croak "Cannot load evil module when parent requested \"no evil ':lax'\"" if $hinthash->{$LAX};
+
+       my $level = 4;
+       my @caller;
+       while (@caller = caller $level) {
+               $hinthash = $caller[10] || {};
+               croak "Cannot load evil module when ancestor requested \"no evil ':intermediate'\""
+                 if $hinthash->{$INTERMEDIATE};
+               $level++;
+       }
+
        $tainted{caller()} = 1;
-       croak "Cannot load evil module when \"no evil ':strict'\" is in effect" if $strict;
 }
 
 sub unimport {
-       my $strict_arg = grep /^:strict$/, @_;
-       carp 'no evil; interpreted as no evil ":strict". This will change in a future version of Acme::Evil' unless $strict_arg;
-       $strict = 1; # To be changed when other modes are implemented
-       if ($strict && %tainted) {
-               croak "Evil module already loaded. Cannot enforce \"no evil ':strict'\"";
+       my $strict_arg = grep /^:strict$/i, @_;
+       my $intermediate_arg = grep /^:intermediate$/i, @_;
+       my $lax_arg = grep /^:lax$/i, @_;
+       my $disable_arg = grep /^:disable$/i, @_;
+
+       if (!$disable_arg && $tainted{caller()}) { # caller is evil
+               croak 'Current module is evil'
+       }
+
+       if ($strict_arg) {
+               $wants_strict{caller()} = 1;
+               croak "Evil module already loaded. Cannot enforce \"no evil ':strict'\"" if %tainted
+       } elsif ($lax_arg) {
+               $^H{$LAX} = 1
+       } elsif ($disable_arg) {
+               delete $wants_strict{caller()};
+               delete $^H{$LAX};
+               delete $^H{$INTERMEDIATE};
+       } else { # $intermediate_arg or no arg
+               $^H{$INTERMEDIATE} = $^H{$LAX} = 1
        }
 }
 
@@ -77,6 +111,11 @@ The calling module function properly if malignant code is loaded
 anywhere in the program. Throws an exception if an evil module is
 loaded, whether at the moment of calling this pragma or in the future.
 
+=item no B<evil> ':disable';
+
+Removes the effect of any previous C<no B<evil> ':strict'>. In other
+words evil modules will now be allowed to be loaded.
+
 =item no B<evil> ':intermediate'; (TODO)
 
 Not yet implemented. The calling module cannot function properly if it
This page took 0.024225 seconds and 4 git commands to generate.