Acme-EyeDrops

 view release on metacpan or  search on metacpan

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

      if ($i > $sidx+1 && $rtok->[$i-1] eq '.' && substr($rtok->[$i], 0, 1)
      eq "'" && substr($rtok->[$i-2], 0, 1) eq "'") {
         substr($s, -2) = substr($rtok->[$i], 1);  # 'a'.'b' to 'ab'
      } else {
         $s .= $rtok->[$i];
      }
   }
   $s;
}

# Pour $n tokens from @{$rtok} (starting at index $sidx) into string
# of length $slen. Return string or undef if unsuccessful.
sub _pour_chunk {
   my ($rtok, $sidx, $n, $slen) = @_;
   my $eidx = $sidx + $n - 1; my $tlen = 0;
   my $idot = my $iquote = my $i3quote = my $iparen = my $idollar = -1;
   for my $i ($sidx .. $eidx) {
      $tlen += length($rtok->[$i]);
      if    ($rtok->[$i] eq '.') { $idot = $i }
      elsif ($rtok->[$i] eq '(') { $iparen = $i }
      elsif (substr($rtok->[$i], 0, 1) eq '$') { $idollar = $i }

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

find yourself playing a surreal form of I<Perl Golf>, where
the winner is the one with the smallest F<f.tmp> in:

    sightly.pl -r 1 -f program_to_be_converted >f.tmp

Apart from reducing the (key-)stroke count, you must avoid regexes
and strive to replace alphanumeric characters with sightly ones,
which do not require sightly encoding.

To illustrate, consider the intriguing problem of creating
I<Buffy looking in the mirror>. Let's start with F<k.pl>:

    open$[;chop,($==y===c)>$-&&($-=$=)for@:=<0>;
    print$"x-(y---c-$-).reverse.$/for@:

Notice that EyeDrops-generated programs, by default, contain no
trailing spaces, which complicates the above program.

Buffy looking in the mirror can now be created with:

    sightly.pl -r 1 -f k.pl -s buffy2 >b.pl

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


    open$%;print<0>                    # self printing
    open$%;print+map{y;!-~;#;;$_}<0>   # replace sightly with '#'

=head2 A Somersaulting Camel

Let's extend the Buffy example of the previous section to produce
a camel-shaped program capable of somersaulting across the screen
when run.

We start with a generator program, F<gencamel.pl>:

    print sightly( { Regex          => 1,
                     Compact        => 1,
                     RemoveNewlines => 1,
                     Indent         => 1,
                     BorderGapRight => 1,
                     Shape          => 'camel',
                     SourceString   => <<'END_SRC_STR' } );
    $~=pop||'';open$%;
    y,!-~,#,,s,(.).,$+,gs,$~&&($_=reverse)for@~=grep$|--,('')x18,<0>;

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

You are free to add a leading C<#!/usr/bin/perl -w> line to
F<camel.pl>, so long as you also add a blank line after
this header line.

=head2 Twelve Thousand and Thirty Two Camels

In a similar way to the somersaulting camel described above,
we create a camel-shaped program capable of emitting
twelve thousand and thirty two different camels when run.

As usual, we start with a generator program, F<gencamel.pl>:

    print sightly( { Regex          => 1,
                     Compact        => 1,
                     RemoveNewlines => 1,
                     BorderGap      => 1,
                     Shape          => 'camel',
                     SourceString   => <<'END_SRC_STR' } );
    $~=uc shift;$:=pop||'#';open$%;chop(@~=<0>);$~=~R&&
    (@~=map{$-=$_+$_;join'',map/.{$-}(.)/,@~}$%..33);
    $|--&$~=~H&&next,$~!~Q&&eval"y, ,\Q$:\E,c",$~=~I&&

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

                  of Utrecht, Holland
    eye           An eye
    flag_canada   Canada's flag, contributed by `/anick
    gelly         Featured speaker at every session of Y::E 2003, Paris
    golfer        A golfer hitting a one iron
    halloween     A witch riding a broomstick
    heart         A heart shape contributed by `/anick
    heart2        A heart shape modelled on one by Falkkin
    hipowls       A pair of hip owls
    japh          JAPHs were invented by Randal L Schwartz in 1988
    jon           Kick-started the Perl 6 development effort by smashing
                  a standard-issue white coffee mug against a hotel wall
    jon_oxer      Linux Australia bigwig (contributed by Paul Fenwick)
    kangaroo      A kangaroo
    kansai_pm     Kansai.pm's mascot (Tiger with Perl characters)
                  contributed by Takanori KAWAI (Japanese)
    kermit        Kermit the frog
    koaladile     A cross between a koala and a crocodile
    larry         Wall, Larry (as opposed to Russell Wall who is
                  Wall, Russ)
    larry2        Caricature of Larry contributed by Ryan King

lib/Acme/EyeDrops/jon.eyp  view on Meta::CPAN

description  : Kick-started the Perl 6 development effort by smashing \
               a standard-issue white coffee mug against a hotel wall
keywords     : person perlhacker

t/16_astride.t  view on Meta::CPAN


my $Num_Threads =  3;
my $N_Iter      = 10;

# plan tests => $Num_Threads * ($N_Iter * 2) + $Num_Threads;
plan tests => $Num_Threads;

sub do_one_thread {
   my $kid = shift;
   my $rc = 0;
   print "# kid $kid start\n";
   for my $j (1 .. $N_Iter) {
      my $t1 = join("", map(chr, 0..255));
      my $f1 = ascii_to_sightly($t1);
      # unlike( $f1, qr/[^!"#\$%&'()*+,\-.\/:;<=>?\@\[\\\]^_`\{|\}~]/, 'ascii_to_sightly' );
      if ($f1 =~ /[^!"#\$%&'()*+,\-.\/:;<=>?\@\[\\\]^_`\{|\}~]/) {
         print STDERR  "# $kid, $j: oops 1: $f1 contains unsightly chars\n";
         ++$rc;
      }
      my $t1a = sightly_to_ascii($f1);
      # is( $t1, $t1a, 'sightly_to_ascii' );



( run in 0.246 second using v1.01-cache-2.11-cpan-0d8aa00de5b )