File Coverage

blib/lib/Acme/Labs.pm
Criterion Covered Total %
statement 17 20 85.0
branch n/a
condition n/a
subroutine 3 4 75.0
pod 1 3 33.3
total 21 27 77.7


line stmt bran cond sub pod time code
1             package Acme::Labs;
2              
3             our $VERSION = '1.1'; # September 14, 2005
4              
5              
6             srand; rand($.) < 1 && (our $but = $_) while ; chomp $but; # randomly choose a line of DATA
7             our $Qyes; our $yEs="I think so, Brain";
8             our $pondering = qq(BRAIN:\t"Pinky, are you pondering what I'm pondering?"\nPINKY:\t"$yEs, $but"\n\n);
9              
10             my @interjections=qw(NARF POIT ZORT EGAD);
11             my $interjections=join("|", @interjections); # OR'd list for regexes
12              
13             our (%zord, %chroz);
14             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); $zord{chr($c++)}=$narf;}}
15              
16             #----------------------------------------------------------------------
17              
18             sub AYPWIP
19             {
20 1     1 0 8 local $pondering="\Q$pondering\E";
21 1         3 local $yEs="\Q$yEs\E";
22 1         2 local $Qyes="\Q$yEs\E";
23              
24 1         18 $pondering=~s[$Qyes.*\s*][$yEs]s;
25 1         29 $_[0] =~ /^\s*$pondering/
26             }
27              
28             sub pinking
29             {
30 0     0 1 0 local $_=pop;
31 0         0 s/([A-Z])/ $zord{$1}/ig;
32 0         0 "\n\n$pondering$_"
33             }
34              
35             sub brainier
36             {
37 1     1 0 2 local $_ = pop;
38              
39 1         4 local $pondering="\Q$pondering\E";
40 1         3 local $yEs="\Q$yEs\E";
41 1         3 local $Qyes="\Q$yEs\E";
42              
43 1         22 $pondering=~s[$Qyes.*][$yEs]s;
44              
45 1         26 s/^\s*$pondering.*\n\n//;
46 1         5 s/^\n//;
47 1         151 s/ ($interjections)/$chroz{$1}/ig;
48 1         100 $_
49             }
50              
51             #----------------------------------------------------------------------
52              
53             open 0 or print "NARF? What does that mean?!? '$0'\n" and exit; # read our source code
54              
55             (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)
56              
57 1     1   1215 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
  1         26202  
  1         8  
58              
59             open 0, ">$0" or print "Cannot get pinking shears! '$0'\n" and exit; # Otherwise, prepare to pinkify!
60             print {0} $1, pinking $plan # write out reformulated plan
61             and print STDOUT "Fun-fun-silly-willy!\n"
62             and do {eval brainier $plan or print STDERR $@; exit}; # and execute our plan
63              
64             #----------------------------------------------------------------------
65              
66             =pod
67              
68             =head1 NAME
69              
70             Acme::Labs -- When you need an extraordinary plan to Take Over the World
71              
72              
73             =head1 SYNOPSIS
74              
75             use Acme::Labs;
76            
77             print "Egad, brilliant, Brain!\n";
78             print "Oh, wait, no -- it'll never work!";
79              
80              
81             =head1 DESCRIPTION
82              
83             When you run a program under C, the module replaces all the
84             big, complicated words in your source file. The code will still work the way it
85             used to, but it will look something like this:
86              
87             use Acme::Labs;
88            
89             BRAIN: "Are you pondering what I'm pondering?"
90             PINKY: "I think so, Brain, but where will we find a duck and a hose at this time of night?"
91            
92            
93             zort eGAD ZORt zOrt egAD " NArF ZorT ZORT zoRT, zORT eGAD ZORt zoRt zoRt ZORt ZORT zOrt egAD, nARF eGAD ZORT ZORt zOrt!\ zOrt";
94             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!";
95              
96              
97             =head1 DIAGNOSTICS
98              
99             =over 4
100              
101             =item C
102              
103             Acme::Labs has done its work on your script. (Only appears the first time
104             you run under Acme::Labs, to indicate that the source code has been
105             translated successfully[sic].)
106              
107             =item C
108              
109             Acme::Labs could not read the source file.
110              
111             =item C
112              
113             Acme::Labs could not modify the source file.
114              
115             =back
116              
117             =head1 BUGS
118              
119             There's no (easy) way to recover the original script.
120             (If you're going to let Pinky mess with your work, that's about what you should
121             expect.)
122              
123             The C of Acme::Labs pretty much has to be the first line in the source
124             code. (Well, before any run-time stuff, or something like that.) It should
125             also be the only statement on its line.
126              
127             There are probably other bugs not documented in this section. (Unless you
128             count the indirect mention in the previous sentence, in which case it's not
129             a bug that they aren't mentioned because they are. And so saying that this
130             was a bug is in fact a bug itself. Whether the bug of saying bugs aren't
131             mentioned when really they are is covered by the indirect mentioning of the
132             aforementioned bugs is left as an exercise for Bertrand Russell.)
133              
134              
135             =head1 SEE ALSO
136              
137             L, L, your psychiatrist
138              
139              
140             =head1 AUTHOR
141              
142             David Green, C<< >>, with apologies to Damian Conway (or vice versa).
143              
144              
145             =head1 COPYRIGHT
146              
147             Copyright (c) 2003, David Green. This module is free software: It may be used,
148             redistributed, or modified under the terms of the Perl Artistic License
149             (L).
150              
151             =cut
152              
153             #----------------------------------------------------------------------
154              
155             __DATA__