Acme-Labs

 view release on metacpan or  search on metacpan

lib/Acme/Labs.pm  view on Meta::CPAN

package Acme::Labs;

our $VERSION = '1.1';	# September 14, 2005


srand; rand($.) < 1 && (our $but = $_) while <DATA>; chomp $but;				# randomly choose a line of DATA
our $Qyes; our $yEs="I think so, Brain";
our $pondering = qq(BRAIN:\t"Pinky, are you pondering what I'm pondering?"\nPINKY:\t"$yEs, $but"\n\n);

my @interjections=qw(NARF POIT ZORT EGAD);
my $interjections=join("|", @interjections);									# OR'd list for regexes

our (%zord, %chroz);
my $c=ord("A"); foreach my $w (@interjections) {my $l=length $w; for(my $n=0; $n<2**$l; $n++) {my $narf; my $b=unpack("b$l", chr $n); for my $i (0..$l-1) { $narf.=substr($b, $i, 1)?lc substr($w, $i, 1):uc substr($w, $i, 1); } $chroz{$narf}=chr($c); $...

#----------------------------------------------------------------------

sub AYPWIP 
{
	local $pondering="\Q$pondering\E"; 
	local $yEs="\Q$yEs\E";
	local $Qyes="\Q$yEs\E";

	$pondering=~s[$Qyes.*\s*][$yEs]s;
	$_[0] =~ /^\s*$pondering/ 
}

sub pinking
{
	local $_=pop;
	s/([A-Z])/ $zord{$1}/ig;
	"\n\n$pondering$_"
}

sub brainier
{
	local $_ = pop;

	local $pondering="\Q$pondering\E"; 
	local $yEs="\Q$yEs\E";
	local $Qyes="\Q$yEs\E";

	$pondering=~s[$Qyes.*][$yEs]s;

	s/^\s*$pondering.*\n\n//;	
	s/^\n//;
	s/ ($interjections)/$chroz{$1}/ig;
	$_
}

#----------------------------------------------------------------------

open 0 or print "NARF?  What does that mean?!? '$0'\n" and exit;				# read our source code

(my $plan = join "", <0>) =~ s[(.*^\s*use\s+Acme::Labs\s*;)]["\n" x (split /\n/, $1)]mes;	# capture intro for preserving later on (and leave behind the same number of \n's so we don't throw off the line numbers)

do {eval brainier $plan or print STDERR $@; exit} if AYPWIP($plan);				# if we recognise a Pinky's Plan, apply to North Pole, I mean, Brain

open 0, ">$0" or print "Cannot get pinking shears! '$0'\n" and exit;			# Otherwise, prepare to pinkify!
print {0} $1, pinking $plan 													# write out reformulated plan
	and print STDOUT "Fun-fun-silly-willy!\n" 
		and do {eval brainier $plan or print STDERR $@; exit};					# and execute our plan

#----------------------------------------------------------------------

=pod

=head1 NAME

Acme::Labs -- When you need an extraordinary plan to Take Over the World


=head1 SYNOPSIS

	use Acme::Labs;
	
	print "Egad, brilliant, Brain!\n";
	print "Oh, wait, no -- it'll never work!";


=head1 DESCRIPTION

When you run a program under C<use Acme::Labs>, the module replaces all the 
big, complicated words in your source file. The code will still work the way it 
used to, but it will look something like this:

	use Acme::Labs;
	
	BRAIN:	"Are you pondering what I'm pondering?"
	PINKY:	"I think so, Brain, but where will we find a duck and a hose at this time of night?"
	
	
	 zort eGAD ZORt zOrt egAD " NArF ZorT ZORT zoRT,  zORT eGAD ZORt zoRt zoRt ZORt ZORT zOrt egAD,  nARF eGAD ZORT ZORt zOrt!\ zOrt";
	 zort eGAD ZORt zOrt egAD " Narf zorT,  EgaD ZORT ZORt egAD,  zOrt Zort --  ZORt egAD' zoRt zoRt  zOrt ZOrT eGaD ZOrT eGAD  EgaD Zort eGAD ZoRt!";


=head1 DIAGNOSTICS

=over 4

=item C<Fun-fun-silly-willy!>

Acme::Labs has done its work on your script.  (Only appears the first time
you run under Acme::Labs, to indicate that the source code has been
translated successfully[sic].)

=item C<NARF? What does that mean?!? '%s'>

Acme::Labs could not read the source file.

=item C<Cannot get pinking shears '%s'>

Acme::Labs could not modify the source file.

=back

=head1 BUGS

There's no (easy) way to recover the original script.
(If you're going to let Pinky mess with your work, that's about what you should 



( run in 1.716 second using v1.01-cache-2.11-cpan-98e64b0badf )