Acme-EyeDrops
view release on metacpan or search on metacpan
lib/Acme/EyeDrops.pm view on Meta::CPAN
That is, pour TEXTSTRING into SHAPESTRING.
FILLTEXT (typically '#') is text to be used as a filler for any
leftover part of the shape (if not set, don't fill in leftovers).
=item pour_sightly SHAPESTRING PROGSTRING GAP RFILLVAR COMPACT IH
Given a shape string SHAPESTRING, a sightly-encoded program
string PROGSTRING, and a GAP between successive shapes,
returns a properly shaped program string.
That is, pour PROGSTRING into SHAPESTRING.
RFILLVAR is either a reference to an array of filler variables
or, alternatively, a string to fill the leftover of the last
shape with. Common filler strings are C<''> for no filler at all,
or C<'#'> or C<';'> or C<';#'>.
A filler variable is a valid Perl variable consisting
of two characters: C<$> and a punctuation character.
For example, RFILLVAR = C<[ '$:', '$^', '$~' ]>.
Do not use C<$;> or C<$"> or C<$_> as filler variables.
If COMPACT is 1, use compact sightly encoding,
if 0 use plain sightly encoding.
If IH (inform handler) is undef, prints status of what it is
doing to STDERR; you can override this by providing a subroutine
reference taking a single inform string argument. To shut it up,
set IH to C<sub {}>.
=item sightly HASHREF
Given a hash reference, HASHREF, describing various attributes,
returns a properly shaped program string.
There is no error return; if something is badly wrong, C<die> is
called -- so wrap the call to C<sightly> in an eval block if you
can't afford to die.
The attributes that HASHREF may contain are:
Shape Describes the shape you want.
First, a built-in shape is looked for.
Next, a 'eye' shape (.eye file in the
get_eye_dir() directory unless overridden
by the EyeDir attribute) is looked for.
Finally, a file name is looked for.
ShapeString Describes the shape you want.
This time you specify a shape string.
SourceFile The source file name to convert.
SourceHandle Specify a file handle instead of a file name.
SourceString Specify a string instead of a file name.
BannerString String to use with built-in Shape 'banner'.
Regex Regex can take the following values:
0: do not embed source program in a regex
If Regex is positive, embed the program in a regex and:
1: add a leading "use re 'eval';" for Perl 5.18+ only
2: do not add a leading "use re 'eval';"
3: add a leading "use re 'eval';"
Do not set this flag when converting complex programs.
Compact Boolean. If set, use compact sightly encoding.
Print Boolean. If set, use a print statement instead
of the default eval statement. Set this flag
when converting text files (not programs).
Binary Boolean. Set if encoding a binary file.
Text Boolean. Set if pouring unsightly text.
TextFiller Filler string used with Text attribute.
For example, TextFiller => '#'.
Gap The number of lines between successive shapes.
Rotate Rotate the shape clockwise 90, 180 or 270 degrees.
RotateType 0 = big rotated shape,
1 = small rotated shape,
2 = squashed rotated shape.
RotateFlip Boolean. Set if want to flip (reflect) the shape
in addition to rotating it.
Reflect Boolean. Reflect the shape.
Reduce Reduce the size of the shape.
Expand Expand the size of the shape.
Invert Boolean. Invert the shape.
Indent Indent the shape. The number of spaces to indent.
TrailingSpaces Boolean. Ensure all lines of the shape are of equal
length, adding trailing spaces if required.
RemoveNewlines Boolean. Remove all newlines from the source before
conversion.
BorderGap Put a border around the shape. Gap between border
and the shape.
BorderGapLeft,BorderGapRight,BorderGapTop,BorderGapBottom
You can override BorderGap with one or more from
the above.
BorderWidth Put a border around the shape. Width of border.
BorderWidthLeft,BorderWidthRight,BorderWidthTop,BorderWidthBottom
You can override BorderWidth with one or more from
the above.
Width Ignored for .eye file shapes. For built-in shapes,
interpreted appropriately for the shape, typically the
shape width in characters. If no shape is specified,
a rectangular block of Width characters is generated.
EyeDir Normally .eye files are got from the EyeDrops
directory underneath where EyeDrops.pm is located.
You can override that by specifying a directory
containing the .eye shape files.
InformHandler By default, sightly prints status of what it is
doing to STDERR; you can override this by providing
a subroutine reference taking a single inform string
argument. To shut it up, set to sub {}.
TrapEvalDie Boolean.
Add closing 'die $@ if $@' to generated program.
When an eval code block calls the die function,
the program does not die; instead the die string
is returned to eval in $@. Using this flag allows
you to convert programs that call die.
TrapWarn Boolean.
Add leading 'local $SIG{__WARN__}=sub{};' to
generated program. This shuts up some warnings.
Use this option if generated program emits
'No such signal: SIGHUP at ...' when run with
warnings enabled.
FillerVar Reference to a list of 'filler variables'.
A filler variable is a Perl variable consisting
of two characters: $ and a punctuation character.
For example, FillerVar => [ '$:', '$^' ].
Do not use $; or $" or $_ as filler variables.
Alternatively, you may set this to '' if you don't
want any filler, or to a string (e.g. '#' or ';'
or ';#') to use instead of filler variables to
fill the leftover part of the last shape with.
=back
=head2 Specifying a Shape
When you specify a shape like this:
sightly( { Shape => 'fred' ...
first a built-in C<fred> shape is looked for, then EyeDrops looks
for the file F<fred.eye> in the F<get_eye_dir> directory.
If you specify a C<'/'> or C<'.'> in the Shape attribute, a file
with that name is looked for instead, for example:
sightly( { Shape => '/tmp/fred.eye' ...
Finally, you may specify a shape with a string, for example:
my $shapestr = <<'FLAMING_OSTRICHES';
#####
#######################
FLAMING_OSTRICHES
sightly ( { ShapeString => $shapestr ...
If you specify a shape without a source file:
print sightly( { Shape => 'camel' } );
a I<no-op> filler is used to fill the shape.
If you specify a source file without a shape:
print sightly( { SourceFile => 'helloworld.pl' } );
a shapeless sightly string without any spaces or newlines is
generated. You can break this string into fixed width lines
via the Width attribute:
print sightly( { SourceFile => 'helloworld.pl',
Width => 40 } );
Generally, you should specify the Width attribute of I<built-in>
shapes. Notice that the Width attribute is ignored for F<.eye>
file shapes.
=head2 Shape Reference
The I<built-in> shapes are:
banner Linux banner command (/usr/games/banner -w Width)
of text in BannerString attribute
srcbanner Linux banner command (/usr/games/banner -w Width)
of source text
siertri A Sierpinski triangle (2**Width lines)
triangle A triangle (width Width characters)
all A shape consisting of all .eye shapes joined together
(Width blank lines between each shape)
The F<.eye> file shapes distributed with this version of EyeDrops are:
a Horizontal banner of "a"
acme Perl/Parrot/Ponie Euro-hacker and modern artist who likes
the colour orange and enjoys having his bra-strap twanged
adrianh Perl qa expert
alien An alien (rumoured to be Ton Hospel, from the
Roswell archives circa 1974)
alpaca Lama pacos, from South America, with long shaggy hair
and related to the llama
autrijus The father of Pugs
baghdad Baghdad Bob aka Comical Ali
beer Beer glass designed by Matthew Byng-Maddick for the
cam.pm Beerfestival Perl Programming Contest 2002
bighorn Ovis canadensis (bighorn sheep) found in the Rocky Mountains
bleach Vertical banner of "use Acme::Bleach;"
bottle A bottle of beer
bottle2 Abbreviated version of shape bottle
bottle3 A bottle of champagne with a champagne glass
bra A bra
buffy Vertical banner of "Buffy"
buffy2 Buffy's angelic face
buffy3 Buffy riding a pony
buffy4 Horizontal banner of "Buffy"
camel Dromedary (Camelus dromedarius, one hump)
camel2 Another dromedary (from use.perl.org)
camel3 London.pm's bactrian camel at London zoo
campm Horizontal banner of "cam.pm"
candle A Christmas candle
china1 Chinese characters, roughly translated as
"God is added a year of seniority; human is added a
year of age, Spring fills the universe; luck and
happiness fills the family"
coffee A cup of coffee
cricket Australia are world champions in this game
damian The Acme namespace is all his fault
dan The father of parrot
debian Debian logo (contributed by Richard Hartmann)
dipsy Teletubbies Dipsy (also london.pm infobot name)
eugene Champion Perl golfer, Drs Eugene van der Pijll
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
llama Llamas are so closely related to camels they can
breed with them (their progeny are called camas)
london Haiku "A Day in The Life of a London Perl Monger"
map_australia Map of Australia
map_italy Map of Italy
map_japan Map of Japan
map_uk Map of United Kingdom and Ireland
map_world1 World globe, Asian view
map_world2 World globe, African view
map_world3 World globe, American view
merlyn Just another Perl hacker, aka Randal L Schwartz
mongers Perl Mongers logo
moose A moose
moosecamel A moose and a camel (modelled after http://irclog.perlgeek.de)
mosquito A mosquito
music A musical symbol
naw Naked Arm Wrestling (Y::E 2002, Munich)
opera Opera browser logo (contributed by Cosimo)
panda A panda designed by Yanni Ellen Liu
parrot Originally an April fool's joke, the joke was that
it was not a joke
pgolf Perl Golf logo (inspired by `/anick)
pony Horizontal banner of "Pony"
pony2 Picture of a Pony
pugs Horizontal banner of "Pugs"
pugs2 Picture of a Pugs dog
riding Horizontal banner of "riding"
rose A rose
santa Santa Claus playing golf
santa2 Santa Claus carrying presents
saturn The planet Saturn
schwern is my bitch
schwern2 Shape schwern without the banner
simon The inventor of parrot
smiley A smiley face
smiley2 Pulling a face
smiley3 A sad face
smiley4 Another sad face
snow Snowflake designed by Matthew Byng-Maddick for the
cam.pm Christmas Perl Programming Contest 2002
spider A spider (tarantula)
spoon A wooden spoon
thumbsup A thumbs up shape modelled on one by Jiun
tonick Pictorial representation of a golf contest between Ton
Hospel and `/anick; colourful but not very suspenseful
tpr Vertical banner of "The Perl Review"
uml A UML diagram
undies A pair of underpants
window A window
writing_perl Perl in camel-style by Takanori KAWAI (Japanese)
yanick Caricature of `/anick's noggin
yanick2 Uttered by `/anick during TPR02
yanick3 Pictorial version of yanick2
yanick4 Abbreviated version of shape yanick
It is easy to create your own shapes. For some ideas on shapes,
point your search engine at I<Ascii Art> or I<Clip Art>.
If you generate some nice shapes, please send them in so they
can be included in future versions of EyeDrops.
=head2 Shape Properties
All the F<.eye> shape files have a corresponding F<.eyp>
shape property file, specifying the shape's properties.
Currently, the allowed shape properties are:
name
nick
description
cpanid
author
authorcpanid
source
keywords
where valid keywords are:
face
person
perlhacker
animal
object
planet
map
flag
sport
underwear
hbanner
vbanner
logo
debian
opera
To give an example of how shape properties might be used,
to find all shapes that depict just the faces of perl hackers:
use Acme::EyeDrops qw(find_eye_shapes);
my @perlhackers = find_eye_shapes('face',
'person',
'perlhacker');
Note that there is an implicit AND between each keyword;
that is, the above code finds all shapes with face AND
person AND perlhacker keywords.
Additionally, you may use OR in any argument, for example:
my @perlhackers = find_eye_shapes('face',
'person OR animal',
'perlhacker');
finds all shapes matching face AND (person OR animal)
AND perlhacker.
Instead of using the API, as shown above, you may also use
the F<findshapes.pl> command in the F<demo> directory:
findshapes.pl -h (for help)
findshapes.pl -v face person perlhacker
The last example displays the faces and properties of all
perl hackers.
Please note that these shape properties are experimental and
may change in future A::E releases.
=head1 BUGS
A really diabolical shape with lots of single character lines
will defeat the shape-pouring algorithm.
You can eliminate all alphanumerics (via Regex => 1) only if the
program to be converted is careful with its use of regular
expressions and C<$_>.
To convert complex programs, you must use Regex => 0, which
emits a leading unsightly double C<eval>.
The code generated by non-zero Regex requires Perl 5.005 or higher
in order to run; when run on earlier versions, you will likely
see the error message: C<Sequence (?{...) not recognized>.
If using Perl 5.18+, the generated file needs a leading
"use re 'eval'" when a postive value for Regex is used.
The converted program runs inside an C<eval> which may cause
( run in 1.786 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )