Acme-Enc

 view release on metacpan or  search on metacpan

Enc.pm  view on Meta::CPAN

package Acme::Enc;
#use strict;use warnings;
use version;our $VERSION = qv('0.0.1');
use Carp;use Crypt::OpenPGP;
our ($stitch,$belt) = buypants();
sub buypants { my $st = defined $_[0] ? $_[0] : 0;my $bl = defined $_[1] ? $_[1] : 'Acme::Enc';return($st,$bl)}
sub button {Crypt::OpenPGP->new->encrypt(Data=>shift(),Passphrase=>$belt,Armour=>$stitch)}
sub unbutton {my $pants = shift;$pants =~ s{\# \s* DanMuey \s* \n}{}xms;Crypt::OpenPGP->new->decrypt(Data=>$pants,Passphrase=>$belt)}
sub zipperstuck { $_[0] !~ /DanMuey/ }sub buypants { my $st = defined $_[0] ? $_[0] : 0;
my $bl = defined $_[1] ? $_[1] : 'Acme::Enc';return($st,$bl)}sub import {
(undef,$belt,$stitch)=@_;$belt=$belt->($0) if ref $belt eq 'CODE';($stitch,$belt)=buypants($stitch,$belt);
my $beltloop = $belt;if($belt =~ m{\&}) {my $x;eval qq{package main;\$x = $belt;};$belt = $x->($0);}
open 0 or croak qq{Can't take off pants '$0': $!};
(my $pants = join '', <0>) =~ m{ (.*) use \s+ Acme::Enc }xms; my $hem = $1 || '';$pants =~ s{ .* use \s+ Acme::Enc [^\n]* \n}{}xms;
local $SIG{__WARN__} = \&zipperstuck;do {eval unbutton $pants; exit;} unless zipperstuck $pants;
open 0, ">$0" or croak qq{Cannot put on pants '$0': $!};
my $useit = $belt eq 'Acme::Enc' ? '' : $beltloop =~ m{\&} ? " $beltloop" : qq{ '$belt'};
print {0} "${hem}use Acme::Enc$useit;\n# DanMuey\n" . button $pants and exit;}
1;
__END__

=head1 NAME

Acme::Enc - Perl extension for Encypting your source code, Acme Style

=head1 SYNOPSIS

   use Acme::Enc;

=head1 DESCRIPTION

   use Acme::Enc;
   
   print "Hello World";

After you run it the first time it will now look like this:

   use Acme::Enc;
   [ encypted version here ]

but run exactly the same :)

=head1 OPTIONS

    use Acme::Enc qw(cyphertext 1);
    use Acme::Enc qw(cyphertext);
    use Acme::Enc qw(\&get_cyphertext 1);
    use Acme::Enc qw(\&get_cyphertext);

This lets you specify the cyphertext or a code reference that returns a cyphertext to use to [de|en]crypt the source.

If a second argument is true then it uses ASCII Armour.

The code reference has $0 as its only argument so you could use that in cypher fetching. (IE based on a database or algorythm)

Note that to have it call your funtion to unencrypt it you must specify it as a string '\&foo' in main:: or else the return value of your function will  be used:

    use Digest::MD5 qw(md5_hex);
    sub get_cyphertext { return md5_hex(shift()) }
    use Acme::Enc qw(\&get_cyphertext);
    [ your code here ]

results in:

    use Digest::MD5 qw(md5_hex);
    sub get_cyphertext { return md5_hex(shift()) }
    use Acme::Enc \&get_cyphertext;
    [ encypted version here ]

while:



( run in 1.555 second using v1.01-cache-2.11-cpan-d80b1682f3f )