Acme-EyeDrops
view release on metacpan or search on metacpan
Revision history for Perl extension EyeDrops
0.01 Sun Sep 23 11:35:12 2001
- original version
0.02 Tue Sep 25 18:05:02 2001
- updated version number :-)
- improved documentation
- new functions: get_builtin_shapes, get_eye_shapes
- extra tests added
0.03 Sun Sep 30 14:07:03 2001
- new shape: kangaroo
- new shape: moose
- new shape: moosecamel (modelled after http://irclog.perlgeek.de)
- new shape property keywords: logo, opera
- logo keyword shapes are: debian, opera, pgolf, mongers
1.55 Mon December 1 21:42:07 2008
- fixed rt #39035 "The Acme-EyeDrops Archive Contains World-Writable files"
- documentation: updated "99 Bottles of Beer" section with one stroke golf
improvement to mtve/thospel original shortest solution
1.60 Sat May 12 23:59:42 2012
- Bug fix release for upcoming Perl 5.16.0
- Dropped support for Perl 5.005; A::E now requires Perl 5.6 or higher
- Clarified Acme::EyeDrops license (thanks Jotam Jr. Trejo)
LICENSE and README were inconsistent with META.yml
all should be consistent now
- minor code improvements for perl 5.6+ requirement:
added "use warnings" to EyeDrops.pm
demo/sightly.pl view on Meta::CPAN
-e Reflect shape.
-d fact Reduce shape by a factor of fact.
-v fact Expand shape by a factor of fact.
-b Binary file.
-w width Width.
-l List available shapes.
-E Trap die within eval with 'die $@ if $@'
-W Trap warnings with '$SIG{__WARN__}=sub{}'
Examples:
sightly -s camel -f myprog.pl >myprog2.pl
This creates myprog2.pl, equivalent to the original
myprog.pl, but prettier and shaped like a camel.
sightly -p -r 1 -s window -z "Bill Gates is a pest!\n" >bill.pl
This creates bill.pl, a program that prints the above string.
sightly -g 3 -bps camel,mongers -f some_binary_file >eyesore
This creates eyesore, a sightly-encoded file.
To decode it: perl eyesore > f.tmp
To check it worked: cmp f.tmp some_binary_file
Notes:
If no shape is specified, a single (very long) line will be output.
If a shape, but no file, is specified, a default no-op filler will
lib/Acme/EyeDrops.pm view on Meta::CPAN
Then run it like this:
perl cvt.pl >new.pl
After inspecting the newly created program, F<new.pl>, to verify that
it does indeed resemble a camel, run it:
perl new.pl
to confirm it behaves identically to the original F<helloworld.pl>.
Instead of using the API, as shown above, you may find it more
convenient to use the F<sightly.pl> command in the F<demo> directory:
sightly.pl -h (for help)
sightly.pl -s camel -f helloworld.pl -r 1 >new.pl
cat new.pl (should look like a camel)
perl new.pl (should print "hello world" as before)
Notice that the shape C<'camel'> is just the file F<camel.eye> in
lib/Acme/EyeDrops.pm view on Meta::CPAN
For Linux only, you can apply its F</usr/games/banner> command
to the program's source text:
print sightly( { Shape => 'srcbanner',
Width => 70,
SourceFile => 'helloworld.pl',
Regex => 1 } );
The generated program is easier to understand than the
original because its characters are bigger and easier to read.
=head2 An Abbreviated History of Perl 6
Here is a summary of the Perl 6 development effort so far:
print sightly( { Shape => 'jon,larry,damian,simon,parrot,' .
'buffy3,autrijus',
Gap => 3,
Regex => 1,
Print => 1,
lib/Acme/EyeDrops.pm view on Meta::CPAN
print sightly( { Shape => 'japh',
SourceString => $src,
Regex => 0 } );
which runs the generated sightly program via C<eval> instead.
If you want to use Regex => 1 (to eliminate I<all> alphanumerics),
ensure the program to be converted is careful with its use of
regular expressions and C<$_>.
To produce a I<JAPH> that resembles the original
I<Just another Perl hacker,> aka I<Randal L Schwartz>, try this:
print sightly( { Shape => 'merlyn',
SourceString => 'Just another Perl hacker,',
Regex => 1,
Print => 1 } );
producing:
''=~('('.'?'.'{'.('['
lib/Acme/EyeDrops.pm view on Meta::CPAN
b{[@b=(abs||No,bottle."s"x!!++$_,of,beer),on,the,wall]}print
"@{+b},\n@b,\nTake one down, pass it around,\n@{+b}.\n"
for-pop||-99..-1
Some years later I noticed that this program can be further shortened
by changing C<"s"> to C<'s'> and embedding the C<sub> inside the first
C<@{}> block like so:
@{sub b{[@b=(abs||No,bottle.'s'x!!++$_,of,beer),on,the,wall]}b}
This saves a stroke because the first C<+b> in the original is replaced
by a bald C<b>.
Elegant though this solution is, they may have felt a little gobsmacked
when the world's leading I<HQ9+> golfer, Casey West, uncorked a one
stroke solution (C<9>) in that surreal programming language.
To produce a solution shaped like a row of beer bottles, run this:
use Acme::EyeDrops qw(sightly get_eye_string hjoin_shapes);
my $ninety_nine = <<'BURP';
lib/Acme/EyeDrops.pm view on Meta::CPAN
SourceString => $ninety_nine } );
=head2 Sierpinski Triangles
A simple and concise Sierpinski triangle generator, F<siertri.pl>, is:
#!perl -l
$x=2**pop;print$"x--$x,map$x&$_?$"x2:"/\\",0..$y++while$x
which was posted by Mtv Europe to golf@perl.org on 14-sep-2002
as a one stroke improvement on Adam Antonik's original program.
Running:
perl siertri.pl 4
displays a Sierpinski triangle with 2**4 lines.
Proclaiming Mtv's program as the shortest (in Acme::EyeDrops 1.13)
only served to provoke Adam Antonik and Eugene van der Pijll into
shortening it by exploiting a hard C<$^F>, as shown in some of the
examples below:
lib/Acme/EyeDrops.pm view on Meta::CPAN
FillerVar => ';#',
Shape => 'camel',
Gap => 1,
SourceString => $src } ),
";\n1;\n", $doc;
Running this program:
perl mkeye.pl >m.tmp
produces F<m.tmp>, which can be copied over the top of the original
F<EyeDrops.pm> in the Acme directory. Though the new I<bunch o' camels>
version passes the regression test suite, it's about 4 times slower
than the original.
Notice that we used Regex => 0 (since EyeDrops.pm uses many regular
expressions), TrapEvalDie => 1 (since EyeDrops.pm calls the C<die>
function) and FillerVar => ';#' (to avoid possible warnings due to
unused variables).
Notice too that the only known I<eval-hostile> line in EyeDrops.pm:
my $eye_dir = __FILE__; ...
was extracted and inserted at the top of the new file.
lib/Acme/EyeDrops.pm view on Meta::CPAN
and others on the fwp mailing list for their advice on
ASCII Art, imaging programs, and on which picture of
Larry to use.
Thanks also to Mtv Europe, Ronald J Kimball and Eugene
van der Pijll for their help in golfing the program in
the I<Twelve Thousand and Thirty Two Camels> section.
Keith Calvert Ivey also contributed some levity to this section.
The "Love Birds" section was provoked by Muss, Jiun and Taffy.
The thumbsup shape was derived from one originally designed by Jiun.
Ideas from Adam Antonik, Mtv Europe, Eugene van der Pijll, Ton Hospel
and Keith Calvert Ivey were used in the I<Sierpinski Triangles> section.
Thanks cog for the prod to add new Shape Properties feature.
The jon shape was derived from
F<http://www.spidereyeballs.com/os5/set1/small_os5_r06_9705.html>.
Kudos to Elaine -HFB- Ashton for showing me this.
t/08_hoax.t view on Meta::CPAN
$diestr =~ tr/!-~/#/;
$teststr = $evalstr . $camelstr . $diestr;
$srcstr = 'die "hello die\\n";';
$prog = sightly({ Shape => 'camel',
SourceString => $srcstr,
Regex => 0,
InformHandler => sub {},
TrapEvalDie => 1 } );
build_file($tmpf, $prog);
local *SAVERR; open(SAVERR, ">&STDERR"); # save original STDERR
open(STDERR, '>'.$tmpf2) or die "Could not create '$tmpf2': $!";
$outstr = `$^X -w -Mstrict $tmpf`;
$rc = $? >> 8;
open(STDERR, ">&SAVERR"); # restore STDERR
$rc == 0 and print "not ";
++$itest; print "ok $itest - die inside eval rc\n";
$outstr eq "" or print "not ";
++$itest; print "ok $itest - die inside eval output\n";
Acme::EyeDrops::_slurp_tfile($tmpf2) eq "hello die\n" or print "not ";
t/19_surrounds.t view on Meta::CPAN
my $outf = 'out.tmp';
my $errf = 'err.tmp';
-f $outf and (unlink($outf) or die "error: unlink '$outf': $!");
-f $errf and (unlink($errf) or die "error: unlink '$errf': $!");
my $itest = 0;
sub test_one {
my ($e, $rtests) = @_;
local *SAVERR; open(SAVERR, ">&STDERR"); # save original STDERR
local *SAVOUT; open(SAVOUT, ">&STDOUT"); # save original STDOUT
open(STDOUT, '>'.$outf) or die "Could not create '$outf': $!";
open(STDERR, '>'.$errf) or die "Could not create '$errf': $!";
my $status = Test::Harness::runtests(@{$rtests});
# XXX: Test harness does not like the next two closes.
# close(STDOUT) or die "error: close STDOUT: $!";
# close(STDERR) or die "error: close STDERR: $!";
open(STDERR, ">&SAVERR") or die "error: restore STDERR: $!";
open(STDOUT, ">&SAVOUT") or die "error: restore STDOUT: $!";
# XXX: is this necessary to prevent leaks?
close(SAVOUT) or die "error: close SAVOUT: $!";
( run in 2.174 seconds using v1.01-cache-2.11-cpan-f985c23238c )