Acme-Buckaroo

 view release on metacpan or  search on metacpan

Buckaroo.pm  view on Meta::CPAN

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = ();
our $VERSION = '1.02';
 
###############################################################################
# IF YOU WANT TO TURN ON DEBUG MODE
# (and thus see lots of logging lines that explain how things are happening
# as they happen), set debug_mode = 1.
# If you do, you'll need either:
#   (1) Perl 5.6 (to get Data::Dumper by default), or
#   (2) to have Data::Dumper already installed.
# Data::Dumper is a very, very handy module, but it wasn't in the default Perl
# installation until (I think) Perl 5.6.  Perl 5.005 usually don't have it.
# Look on CPAN.ORG for Data::Dumper if you don't have it.
###############################################################################
my $debug_mode = 0;
print("starting script...\n") if $debug_mode;
 
if ($debug_mode)
{
    use Data::Dumper;
}
else
{
#    sub Dumper { return(""); }
}
 
my $header = "Buckaroo Banzai Across The Eigth Dimension " x 2 . "\n";
 
###############################################################################
# this translation array is just for fun, but also for debugging so you can see
# how characters are encoded as they are encoded.
#
# If you try a new encoding method, use this one and you'll be able to see if
# characters are encoded and decoded correctly.
 
my @xlate_array1 = (qw(
    000q 001q 002q 003q 004q 005q 006q 007q 008q 009q
    010q 011q 012q 013q 014q 015q 016q 017q 018q 019q
    020q 021q 022q 023q 024q 025q 026q 027q 028q 029q
    030q 031q 032q 033q 034q 035q 036q 037q 038q 039q

Buckaroo.pm  view on Meta::CPAN

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
###############################################################################
 
sub translate
{
    # receives the string of the entire perl script after 'use Acme::Buckaroo'.
 
    my $in_string = shift;
 
    my $out = "";
    $out = Dumper($in_string);
    print("Instring=>>$out<<\n") if $debug_mode;
 
    my @in_array = split(//, $in_string);
    $out = Dumper(@in_array);
    print("in_array=>>$out<<\n"if $debug_mode;
 
    my $i = 0;
    my @temparray = ();
    foreach my $thischar (@in_array)
    {
        # translate each character into it's ascii value.
        my $num = unpack("c", $thischar);
        # change that ascii value into a string from the array...
        my $newchar = $xlate_array[$num];
        print("char=>>$thischar<<, num=>>$num<<, newchar=>>$newchar<<\n"if $debug_mode;
        print("char=>>%s<<, num=>>%s<<, newchar=>>%s<<\n", $thischar, $num, $newcharif $debug_mode;
        push(@temparray, "$newchar");
        $i++;
        if ($i > 3)
        {
            push(@temparray, "\n");
            $i = 0;
        }
    }
 
    my $out_string = $header . join("\t", @temparray) . "\n";
    print("out_string=>>$out_string<<\n"if $debug_mode;
    return $out_string;
 
}
 
################################################################################
# Normalize is called to convert the text to perl again from the encoded version.
#
 
sub normalize
{
    my $in_string = shift;;
 
    $in_string =~ s/^$header//g;
 
    print("normalize, got in_string>>$in_string<<\n"if $debug_mode;
 
    my %revhash = ();
    my $counter = 0;
    foreach my $this_elem (@xlate_array)
    {
        $revhash{$this_elem} = $counter++;
    }
 
    $in_string =~ s/\t\n/\t/g;
    $in_string =~ s/\t+/\t/g;
    my @in_array  = split(/[\t]/, $in_string);
    my $in_array_dump = Dumper(@in_array);
    print("in_array_dump=>>$in_array_dump<<\n"if $debug_mode;
 
    my @translate_array = ();
    my $this_elem = "";
    $counter = 1;
    foreach $this_elem (@in_array)
    {
        if (!($this_elem)) { print("Found undefined elem, counter=$counter.\n"); $counter++; next; }
        my $ascii_num = $xlate_2_hash{$this_elem} || 0;
        my $to_char = pack("c", $ascii_num);
        printf("Normalized >>%s<<, ascii_num=>>%s<<, char=>>%s<<, counter=>>%s<<\n", $this_elem, $ascii_num, $to_char, $counterif $debug_mode;
        push(@translate_array, $to_char);
        $counter++;
    }
 
    my $outtext = join('', @translate_array);
    print("Converted back to text=>>$outtext<<\n") if $debug_mode;
 
    return("$outtext");
 
}
 
###############################################################################
 
sub has_wordchars
{
 
    my $in_string = shift;
    my $retval = 0;
 
    print("In has_wordchars\n") if $debug_mode;
 
    if ($in_string =~ /\s/)
    {
        return $in_string;
    }
    else
    {
        return 0;
    }
}
 
###############################################################################
 
sub starts_with_header
{
 
    my $in_string = shift;
    my $retval = 0;
 
    print("In starts_with_header\n") if $debug_mode;
 
    if ($in_string =~ /^$header/)
    {
        return $in_string;
    }
    else
    {
        return 0;
    }
 
}
 
###############################################################################
 
sub import
{
 
    my $first           = shift;     # name of module, in this case "Buckaroo.pm"
    my $source_filename = $0;        # name of file called from (if test.pl does a 'use Acme::Buckaroo;' then this will be "test.pl")
 
    print("Starting \"Buckaroo\" process...\n") if $debug_mode;
 
    # set up some hashes to go to/from encoding scheme.
    my $i = 0;
    foreach my $this_elem (@xlate_array)
    {
        $xlate_2_hash{$this_elem} = $i;
        $xlate_from_hash{$i}      = $this_elem;
        $i++;
    }
 
    if (!(open(FILE_HANDLE, "<$source_filename")))
    {
        print("Can't Buckaroo again on '$0'\n");
        exit;
    }
    else
    {
        #comment this out if you don't care.
        print("Past open... ") if $debug_mode;
    }
 
    #read entire file in as a string.
    my @file_array = <FILE_HANDLE>;
    my $file_array_dump = Dumper(@file_array);
    print("file_array_dump=>>$file_array_dump<<"if $debug_mode;
 
    my $file_string = join(""@file_array);
 
    # elim anything before the 'use Acme::Buckaroo; line.
    $file_string =~ s/use\s*Acme::Buckaroo\s*;\s*\n//;
 
    print("Filestring=>>$file_string<<\n"if $debug_mode;
 
    # no clue why we do this.  Anyone know?
    #local $SIG{__WARN__} = \&has_wordchars;
 
    if ( (has_wordchars($file_string)        ) &&
         (!(starts_with_header($file_string))) )
    {
        if (!(open(FILE_HANDLE, ">$0")))
        {
            print("Cannot Buckaroo '$0'\n");
            exit;
        }
        print("past open2..."if $debug_mode;
        print(FILE_HANDLE "use Acme::Buckaroo;\n");
        my $result = translate($file_string);
        print(FILE_HANDLE $result);
        print("Done \"Buckaroo-ing!\n");
    }
    else
    {
        print("normalizing...\n"if $debug_mode;
        my $out_string = normalize($file_string);
        print("out_string=>>$out_string<<\n"if $debug_mode;
        my $outval = eval($out_string);
        print("Outval returned: $outval\n") if $debug_mode;
        if ($@)
        {
            print("Perl Error returned: $@\n");
        }
        print("No eval error returned.\n") if $debug_mode;
    }
 
    print("Finishing...\n"if $debug_mode;
 
    exit;
 
}
 
###############################################################################
 
1;
 
###############################################################################

Buckaroo.pm  view on Meta::CPAN

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
after the 'use Acme::Buckaroo;' is converted (character by character)
into characters from the movie "Buckaroo Banzai Across the Eigth
Dimension" (and some other phrases, too).
 
The program will work (or not!) exactly as it did before it was
converted, but the code will be a somewhat endearing tribute to a
movie, instead of a clean, complete, clearly commented set of lines
of Perl code.
 
if you want to convert your program BACK into Perl, you must edit the
Acme::Buckaroo.pm module and turn on debugging (change the
line, "my $debug_mode = 0;" to the line, "my $debug_mode = 1;" and then
run the script again.  As it executes, it will translate the program
back.  Capture the output of this and you have your program back.
 
Acme::Buckaroo came about because the modules Acme::Buffy, Acme::Morse,
Acme::Pony, and Acme::Bleach were somewhat cryptically written.  This
author believes that CODE SHOULD BE SIMPLE and CLEAR to read and
understand.  Code that isn't clear is far less value.  And, since these
modules are for learning or FUN anyway, I might as well start here.
 
As someone who has taught beginners to use Perl, I've seen the problems

README  view on Meta::CPAN

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
after the 'use Acme::Buckaroo;' is converted (character by character)
into characters from the movie "Buckaroo Banzai Across the Eigth
Dimension" (and some other phrases, too).
 
The program will work (or not!) exactly as it did before it was
converted, but the code will be a somewhat endearing tribute to a
movie, instead of a clean, complete, clearly commented set of lines
of Perl code.
 
if you want to convert your program BACK into Perl, you must edit the
Acme::Buckaroo.pm module and turn on debugging (change the
line, "my $debugmode = 0;" to the line, "my $debugmode = 1;" and then
run the script again.  As it executes, it will translate the program
back.  Capture the output of this and you have your program back.
 
Acme::Buckaroo came about because the modules Acme::Buffy, Acme::Morse,
Acme::Pony, and Acme::Bleach were somewhat cryptically written.  This
author believes that CODE SHOULD BE SIMPLE and CLEAR to read and
understand.  Code that isn't clear is far less value.  And, since these
modules are for learning or FUN anyway, I might as well start here.
 
As someone who has taught beginners to use Perl, I've seen the problems

README  view on Meta::CPAN

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
       perl Makefile.PL
       make
       make test
       make install
 
DEPENDENCIES
 
    This module requires NO other modules or libraries.
    If you go into the source of Buckaroo.pm and look, you'll see
    there is a debug mode.  If you turn this on, you'll be able to
    watch it as it works.  However, debug mode requires the module
    Data::Dumper, a fantastically useful module that you should
    have by default in Perl installations > 5.6.
 
 
DEDICATION
 
    I'd like to dedicate this module to Mr. Damian Conway, who has bettered
    Perl and the lives of those in the Perl-using community by vast amounts,
    and continues to do good work.  Someday I'd like to buy him a beer.

retest.txt  view on Meta::CPAN

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
print "Hello world\\n";
use strict;
BEGIN { unshift \@INC, `pwd` }
 
# This test script should change so it contains only Buckaroo Banzai words.
# WARNING!! WARNING!! WARNING!! WARNING!!
# WARNING!! WARNING!! WARNING!! WARNING!!
# If you use this module, your source file will be converted into seeming junk
# Though it will still run normally.
# To fix it, go into the module Buckaroo.pm and set $debugmode = 1; and pipe the
# output to a new file.  Remove the use Buckaroo.pm,
# and you're back the way you were.
# WARNING!! WARNING!! WARNING!! WARNING!!
# WARNING!! WARNING!! WARNING!! WARNING!!
 
# abcdefghijklmnopqrstuvwxyz
# ABCDEFGHIJKLMNOPQRSTUVWXYZ
# 01234567890
# `~1!2@3#$4%%6^7&8*9(0)-_=+\\|]]{{]};:"",<.>/?

test.pl  view on Meta::CPAN

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
print "Hello world\\n";
use strict;
BEGIN { unshift \@INC, `pwd` }
 
# This test script should change so it contains only Buckaroo Banzai words.
# WARNING!! WARNING!! WARNING!! WARNING!!
# WARNING!! WARNING!! WARNING!! WARNING!!
# If you use this module, your source file will be converted into seeming junk
# Though it will still run normally.
# To fix it, go into the module Buckaroo.pm and set $debugmode = 1; and pipe the
# output to a new file.  Remove the use Buckaroo.pm,
# and you're back the way you were.
# WARNING!! WARNING!! WARNING!! WARNING!!
# WARNING!! WARNING!! WARNING!! WARNING!!
 
# abcdefghijklmnopqrstuvwxyz
# ABCDEFGHIJKLMNOPQRSTUVWXYZ
# 01234567890
# `~1!2@3#$4%%6^7&8*9(0)-_=+\\|]]{{]};:"",<.>/?



( run in 0.257 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )