Acme-Pony-Pink/lib/Acme/Pony/Pink.pm
package Acme::Pony::Pink;
use 5.010;
use autodie;
use strict;
no warnings;
use utf8;
BEGIN {
$Acme::Pony::Pink::AUTHORITY = 'cpan:TOBYINK';
$Acme::Pony::Pink::VERSION = '0.003';
}
use Carp qw<croak>;
use MIME::Base64 qw<decode_base64>;
use List::MoreUtils qw<firstidx>;
use Config;
use constant _path_to_perl => $Config{perlpath};
sub new
{
shift;
}
sub _image
{
state $image = do {
local $/ = <DATA>;
decode_base64($/);
};
return $image;
}
sub _find_shebang
{
my ($class, $lines) = @_;
my $idx = firstidx { /^\#\!.*\bperl\b/ } @$lines;
return if $idx < 0; # no shebang
# look for code before shebang... that's not a real shebang
for (0 .. $idx)
{
next if $lines->[$_] =~ m{^\s*#};
next if $lines->[$_] =~ m{^\s*$};
return;
}
return $lines->[$idx];
}
sub _filehandle
{
my ($class, $args, $mode) = @_;
return unless @$args;
$mode //= '<';
my $arg = shift @$args;
my $fh;
if (ref $arg eq 'SCALAR')
{ open $fh, $mode, \$arg }
elsif (!ref $arg)
{ open $fh, $mode, $arg }
else
{ $fh = $arg }
return $fh;
}
sub ponify
{
my $class = shift;
local $/ = "\n";
my $fh_in = $class->_filehandle(\@_, '<') or croak "must supply input handle";
my $fh_out = $class->_filehandle(\@_, '>') || \*STDOUT;
my @lines = <$fh_in>;
unshift @lines, sprintf("#!%s\n", $class->_path_to_perl)
unless $class->_find_shebang(\@lines);
print {$fh_out} $class->_image;
print {$fh_out} qq(\n\n);
print {$fh_out} @lines;
return;
}
=head1 NAME
Acme::Pony::Pink - make your script look like a pink pony
=head1 SYNOPSIS
my $converter = Acme::Pony::Pink->new;
$converter->ponify('myscript.pl' => 'myscript.gif');
myscript.gif is now a small picture of a pink pony, and you can run the
original script using:
perl -x myscript.gif
=head1 DESCRIPTION
This module turns a Perl script into a picture of a pink pony.
The picture is executable via C<< perl -x >>.
=head2 Unconstrutive Constructor
=over
=item C<< new >>
Returns the invocant.
=back
=head2 Method
=over
=item C<< ponify($input, $output) >>
The input is a Perl script; the output is a GIF file. (No, the "F" in "GIF"
does not stand for "file".)
Input and output may be filehandles, file names, or scalar references if you
just want to play with strings. The input source is required; the default
output destination is STDOUT.
=back
=head1 BUGS
Please report any bugs to someone who cares.
=head1 SEE ALSO
L<Acme::Pony>,
L<Unicornify::URL>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=cut
__PACKAGE__
__DATA__
R0lGODlhMgAyAOcAAEpKNn9YbDs7Pl9CUQAA/D8sNm5UYlBQz05MSwEBuCwsLgIC2i8iKFRUSG9N
Xntrd09DSYGFj11cWx0cHTApcY2NjF9UWktLf3x8fWRobwAAenBw3wMDnD40OoFoZ6usrW1rblZZ
XyYkG5mbn6Kmr42NbA4LDAAAV29fZ087RnJdW19KVQUEOWdgao5pfcbGjr+Eou+lysDAwI9jec+P
r59uh4CAgN+avfDw8AAAAODg4Kyyv9ff73N3f6CgoK95lNDQ0EBAQGBgYMnQ3083Q4+Un5CQkHBw
cFBQUJ6jrzExI0dKTx8WG7CwsLrBz7m5hZSUam9vTzAwMGNjRyAgIBAQEIiIYa2tfFdXP3t7WKCg
cz49LhgYEVhYUVdVXTg4MYZ6iDguLEw+SCwiI1pOWSgpIwAADy8hOGhPVTU1Kn1eb1hERzc5OHtZ
Z1FHPm9vYGZmTpean8XFunh4cXBwv39/cIhlcAAAH3Z5f2hoYUBAX0BAT5aFlebu//+w2P8A/wAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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