Add no evil ':disable'
[acme-evil.git] / lib / evil.pm
CommitLineData
f17ddf12
MG
1#!/usr/bin/perl
2package evil;
3
4use 5.008009;
5use strict;
6use warnings;
7
8use Carp;
9
10our $VERSION = 0.001;
11
12our %tainted;
13our $strict;
14
15sub import {
16 $tainted{caller()} = 1;
17 croak "Cannot load evil module when \"no evil ':strict'\" is in effect" if $strict;
18}
19
20sub unimport {
21 my $strict_arg = grep /^:strict$/, @_;
c72607e1
MG
22 my $disable_arg = grep /^:disable/, @_;
23 carp 'no evil; interpreted as no evil ":strict". This will change in a future version of Acme::Evil' unless $strict_arg || $disable_arg;
24 $strict = 1 unless $disable_arg; # To be changed when other modes are implemented
25 $strict = 0 if $disable_arg;
f17ddf12
MG
26 if ($strict && %tainted) {
27 croak "Evil module already loaded. Cannot enforce \"no evil ':strict'\"";
28 }
29}
30
311;
32__END__
33
34=encoding utf-8
35
36=head1 NAME
37
38evil - RFC 3514 (evil bit) implementation for Perl modules
39
40=head1 SYNOPSIS
41
42 # in A.pm
43 package A;
44 use evil;
45 ...
46
47 # in B.pm
48 package B;
49 no evil ':strict';
50 use A; # <dies>
51 ...
52
53
54=head1 DESCRIPTION
55
56L<RFC3514|https://www.ietf.org/rfc/rfc3514.txt> introduces a new flag
57called the "evil bit" in all IP packets. The intention is to simplify
58the work of firewalls. Software that sends IP packets with malicious
59intent must set the evil bit to true, and firewalls can simply drop
60such packets.
61
62The evil pragma is a Perl implementation of the same concept. With
63this pragma malicious modules can declare their evil intent while
64critical modules can request that they will only use / run alongside
65non-evil code.
66
67The pragma can be used in the following ways:
68
69=over
70
71=item use B<evil>;
72
73Marks the current package as evil. All malicious modules MUST use this
74directive to ensure the full functionality of this module.
75
76=item no B<evil> ':strict';
77
78The calling module function properly if malignant code is loaded
79anywhere in the program. Throws an exception if an evil module is
80loaded, whether at the moment of calling this pragma or in the future.
81
c72607e1
MG
82=item no B<evil> ':disable';
83
84Removes the effect of any previous C<no B<evil> ':strict'>. In other
85words evil modules will now be allowed to be loaded.
86
f17ddf12
MG
87=item no B<evil> ':intermediate'; (TODO)
88
89Not yet implemented. The calling module cannot function properly if it
90is using evil code, whether directly or indirectly. Throws an
91exception if an evil module is loaded by the calling module or by one
92of the children modules (or by one of their children modules, etc).
93
94=item no B<evil> ':lax'; (TODO)
95
96Not yet implemented. The calling module cannot function properly if it
97is using evil code direcly. Throws an exception if the calling module
98loads an evil module.
99
100=item no B<evil>;
101
102This would normally be equivalent to C<no evil ':intermediate';> but
103since that mode is not yet implemented this call does the same as
104C<no evil ':strict';> while also emitting a warning saying that this
105behaviour will change in a future version.
106
107=back
108
109=head1 AUTHOR
110
111Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
112
113=head1 COPYRIGHT AND LICENSE
114
115Copyright (C) 2016 by Marius Gavrilescu
116
117This library is free software; you can redistribute it and/or modify
118it under the same terms as Perl itself, either Perl version 5.22.2 or,
119at your option, any later version of Perl 5 you may have available.
120
121
122=cut
This page took 0.017822 seconds and 4 git commands to generate.