| 1 | package Acme::Pony::Pink; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use autodie; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | no warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 1 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | $Acme::Pony::Pink::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||
| 11 | 1 | $Acme::Pony::Pink::VERSION = '0.003'; | |||||||||||||
| 12 | } | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 1 | ▶ | use Carp qw<croak>; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 1 | ▶ | use MIME::Base64 qw<decode_base64>; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 1 | ▶ | use List::MoreUtils qw<firstidx>; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 1 | ▶ | use Config; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 1 | ▶ | use constant _path_to_perl => $Config{perlpath}; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | sub new | ||||||||||||||
| 22 | 0 | ▶ | { | ||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 23 | 0 | shift; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | sub _image | ||||||||||||||
| 27 | 0 | ▶ | { | ||||||||||||
|
Subroutine
_image: not called CC=1 SCAR=6.9
| |||||||||||||||
| 28 | 0 | state $image = do { | |||||||||||||
| 29 | 0 | local $/ = <DATA>; | |||||||||||||
| 30 | 0 | decode_base64($/); | |||||||||||||
| 31 | }; | ||||||||||||||
| 32 | 0 | return $image; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | sub _find_shebang | ||||||||||||||
| 36 | 0 | ▶ | { | ||||||||||||
|
Subroutine
_find_shebang: not called CC=5 SCAR=34.0
| |||||||||||||||
| 37 | 0 | my ($class, $lines) = @_; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | ▶ | my $idx = firstidx { /^\#\!.*\bperl\b/ } @$lines; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 40 | 0 | ▶ | return if $idx < 0; # no shebang | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | |||||||||||||||
| 42 | # look for code before shebang... that's not a real shebang | ||||||||||||||
| 43 | 0 | for (0 .. $idx) | |||||||||||||
| 44 | { | ||||||||||||||
| 45 | 0 | ▶ | next if $lines->[$_] =~ m{^\s*#}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 0 | ▶ | next if $lines->[$_] =~ m{^\s*$}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | 0 | return; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | return $lines->[$idx]; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | sub _filehandle | ||||||||||||||
| 54 | 0 | ▶ | { | ||||||||||||
|
Subroutine
_filehandle: not called CC=5 SCAR=34.0
| |||||||||||||||
| 55 | 0 | my ($class, $args, $mode) = @_; | |||||||||||||
| 56 | 0 | ▶ | return unless @$args; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 0 | ▶ | $mode //= '<'; | ||||||||||||
|
Condition0%0/2
$mode //= "<"
MC/DC0%0/1
$mode //= "<"
$mode
Truth table0%0/2
A
A= $mode
| |||||||||||||||
| 58 | |||||||||||||||
| 59 | 0 | my $arg = shift @$args; | |||||||||||||
| 60 | 0 | my $fh; | |||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | ▶ | if (ref $arg eq 'SCALAR') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 63 | 0 | { open $fh, $mode, \$arg } | |||||||||||||
| 64 | elsif (!ref $arg) | ||||||||||||||
| 65 | 0 | { open $fh, $mode, $arg } | |||||||||||||
| 66 | else | ||||||||||||||
| 67 | 0 | { $fh = $arg } | |||||||||||||
| 68 | |||||||||||||||
| 69 | 0 | return $fh; | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | sub ponify | ||||||||||||||
| 73 | 0 | ▶ | { | ||||||||||||
|
Subroutine
ponify: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 74 | 0 | my $class = shift; | |||||||||||||
| 75 | 0 | local $/ = "\n"; | |||||||||||||
| 76 | |||||||||||||||
| 77 | 0 | ▶ | my $fh_in = $class->_filehandle(\@_, '<') or croak "must supply input handle"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 78 | 0 | ▶ | my $fh_out = $class->_filehandle(\@_, '>') || \*STDOUT; | ||||||||||||
|
Condition0%0/2
$class->_filehandle(\@_, '>') || \*STDOUT
MC/DC0%0/1
$class->_filehandle(\@_, '>') || \*STDOUT
$class->_filehandle(\@_, '>')
Truth table0%0/2
A
A= $class->_filehandle(\@_, '>')
| |||||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | my @lines = <$fh_in>; | |||||||||||||
| 81 | 0 | ▶ | unshift @lines, sprintf("#!%s\n", $class->_path_to_perl) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 82 | unless $class->_find_shebang(\@lines); | ||||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | print {$fh_out} $class->_image; | |||||||||||||
| 85 | 0 | print {$fh_out} qq(\n\n); | |||||||||||||
| 86 | 0 | print {$fh_out} @lines; | |||||||||||||
| 87 | 0 | return; | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | =head1 NAME | ||||||||||||||
| 91 | |||||||||||||||
| 92 | Acme::Pony::Pink - make your script look like a pink pony | ||||||||||||||
| 93 | |||||||||||||||
| 94 | =head1 SYNOPSIS | ||||||||||||||
| 95 | |||||||||||||||
| 96 | my $converter = Acme::Pony::Pink->new; | ||||||||||||||
| 97 | $converter->ponify('myscript.pl' => 'myscript.gif'); | ||||||||||||||
| 98 | |||||||||||||||
| 99 | myscript.gif is now a small picture of a pink pony, and you can run the | ||||||||||||||
| 100 | original script using: | ||||||||||||||
| 101 | |||||||||||||||
| 102 | perl -x myscript.gif | ||||||||||||||
| 103 | |||||||||||||||
| 104 | =head1 DESCRIPTION | ||||||||||||||
| 105 | |||||||||||||||
| 106 | This module turns a Perl script into a picture of a pink pony. | ||||||||||||||
| 107 | |||||||||||||||
| 108 | The picture is executable via C<< perl -x >>. | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =head2 Unconstrutive Constructor | ||||||||||||||
| 111 | |||||||||||||||
| 112 | =over | ||||||||||||||
| 113 | |||||||||||||||
| 114 | =item C<< new >> | ||||||||||||||
| 115 | |||||||||||||||
| 116 | Returns the invocant. | ||||||||||||||
| 117 | |||||||||||||||
| 118 | =back | ||||||||||||||
| 119 | |||||||||||||||
| 120 | =head2 Method | ||||||||||||||
| 121 | |||||||||||||||
| 122 | =over | ||||||||||||||
| 123 | |||||||||||||||
| 124 | =item C<< ponify($input, $output) >> | ||||||||||||||
| 125 | |||||||||||||||
| 126 | The input is a Perl script; the output is a GIF file. (No, the "F" in "GIF" | ||||||||||||||
| 127 | does not stand for "file".) | ||||||||||||||
| 128 | |||||||||||||||
| 129 | Input and output may be filehandles, file names, or scalar references if you | ||||||||||||||
| 130 | just want to play with strings. The input source is required; the default | ||||||||||||||
| 131 | output destination is STDOUT. | ||||||||||||||
| 132 | |||||||||||||||
| 133 | =back | ||||||||||||||
| 134 | |||||||||||||||
| 135 | =head1 BUGS | ||||||||||||||
| 136 | |||||||||||||||
| 137 | Please report any bugs to someone who cares. | ||||||||||||||
| 138 | |||||||||||||||
| 139 | =head1 SEE ALSO | ||||||||||||||
| 140 | |||||||||||||||
| 141 | L<Acme::Pony>, | ||||||||||||||
| 142 | L<Unicornify::URL>. | ||||||||||||||
| 143 | |||||||||||||||
| 144 | =head1 AUTHOR | ||||||||||||||
| 145 | |||||||||||||||
| 146 | Toby Inkster E<lt>tobyink@cpan.orgE<gt>. | ||||||||||||||
| 147 | |||||||||||||||
| 148 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||
| 149 | |||||||||||||||
| 150 | This software is copyright (c) 2012 by Toby Inkster. | ||||||||||||||
| 151 | |||||||||||||||
| 152 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 153 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 154 | |||||||||||||||
| 155 | =head1 DISCLAIMER OF WARRANTIES | ||||||||||||||
| 156 | |||||||||||||||
| 157 | THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||
| 158 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||||||||||||||
| 159 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||
| 160 | |||||||||||||||
| 161 | =cut | ||||||||||||||
| 162 | |||||||||||||||
| 163 | 1 | __PACKAGE__ | |||||||||||||
| 164 | __DATA__ | ||||||||||||||