File Coverage

blib/lib/Acme/Palindrome.pm
Criterion Covered Total %
statement 11 13 84.6
branch n/a
condition 1 2 50.0
subroutine 5 7 71.4
pod 0 5 0.0
total 17 27 62.9


line stmt bran cond sub pod time code
1             package Acme::Palindrome;
2             # $Id: $
3 1     1   685 use strict qw[vars subs];
  1         2  
  1         287  
4              
5 1     1   7 use vars qw[$VERSION $TIE];
  1         2  
  1         659  
6             $VERSION = (qw$Revision: 0.1$)[1];
7             $TIE = " \t"x8;
8              
9 0     0 0 0 sub backward { "$TIE\n".palindrome(split "\n", $_[0])."\n" }
10 1     1 0 4 sub forward { palindrome(split "\n", $_[0]) }
11              
12 0     0 0 0 sub is_forward { $_[0] !~ /^$TIE/ }
13 1     1 0 18 sub is_backward { $_[0] =~ /^$TIE/ }
14              
15             open 0 or print "Can't reverse '$0'\n" and exit;
16             (my $code = join "", <0>) =~ s/.*^\s*use\s+Acme::Palindrome\s*;\n//sm;
17             local $SIG{__WARN__} = \&is_forward;
18             do {eval forward $code; exit} if is_backward $code;
19             open 0, ">$0" or print "Cannot reverse '$0'\n" and exit;
20             print {0} "use Acme::Palindrome;\n", backward $code and exit;
21              
22             sub palindrome {
23 1     1 0 1 my $max = 0;
24 1   50     7 length > $max && ( $max = length ) for @_;
25 1         51 return join "\n",
26             map sprintf( "%${max}s", scalar reverse $_ ),
27             reverse @_;
28             }
29              
30             1;
31              
32             __END__