File Coverage

blib/lib/Acme/Flip.pm
Criterion Covered Total %
statement 6 14 42.8
branch 0 2 0.0
condition 0 2 0.0
subroutine 2 3 66.6
pod 0 1 0.0
total 8 22 36.3


line stmt bran cond sub pod time code
1             package Acme::Flip;
2              
3 1     1   757 use strict;
  1         2  
  1         38  
4 1     1   5 use warnings;
  1         2  
  1         574  
5              
6             our $VERSION = '1.0';
7              
8             our %table = (
9             "a" => "\x{0250}",
10             "b" => "q",
11             "c" => "\x{0254}",
12             "d" => "p",
13             "e" => "\x{01dd}",
14             "f" => "\x{025f}",
15             "g" => "\x{0183}",
16             "h" => "\x{0265}",
17             "i" => "\x{0131}",
18             "j" => "\x{027e}",
19             "k" => "\x{029e}",
20             "l" => "l",
21             "m" => "\x{026f}",
22             "n" => "u",
23             "o" => "o",
24             "p" => "d",
25             "q" => "b",
26             "r" => "\x{0279}",
27             "s" => "s",
28             "t" => "\x{0287}",
29             "u" => "n",
30             "v" => "\x{028c}",
31             "w" => "\x{028d}",
32             "y" => "\x{028e}",
33             "z" => "z",
34             "1" => "\x{21c2}",
35             # "2" => "\x{1105}",
36             "2" => "Z",
37             # "3" => "\x{1110}",
38             "3" => "E",
39             # "4" => "\x{3123}",
40             # "5" => "\x{078e}",
41             "5" => "S",
42             "6" => "9",
43             # "7" => "\x{3125}",
44             "7" => "L",
45             "8" => "8",
46             "9" => "6",
47             "0" => "0",
48             "." => "\x{02d9}",
49             "," => "'",
50             "'" => ",",
51             "\"" => ",,",
52             "´" => ",",
53             "`" => ",",
54             ";" => "\x{061b}",
55             "!" => "\x{00a1}",
56             "\x{00a1}" => "!",
57             "?" => "\x{00bf}",
58             "\x{00bf}" => "?",
59             "[" => "]",
60             "]" => "[",
61             "(" => ")",
62             ")" => "(",
63             "{" => "}",
64             "}" => "{",
65             "<" => ">",
66             ">" => "<",
67             "_" => "\x{203e}",
68             );
69              
70             sub flip
71             {
72 0     0 0   $_ = shift;
73 0   0       my $width = (shift or 80);
74 0           while (s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
  0            
75 0           join ("\n", map {
76 0           sprintf "%${width}s", join '', map {
77 0 0         $_ = lc $_; exists $table{$_} ? $table{$_} : $_
  0            
78             } reverse split (/\B|\b/, $_)
79             } reverse split (/\n/, $_))."\n";
80             }
81              
82             1;
83              
84             =head1 NAME
85              
86             Acme::Flip - Replace alphanumeric characters in text with ones that look flipped
87              
88             =head1 SYNOPSIS
89              
90             use Acme::Flip;
91             binmode STDOUT, ':encoding(utf8)';
92             print Acme::Flip::flip ('Hello world');
93              
94             =head1 DESCRIPTION
95              
96             Replace alphanumeric characters in text with ones that look flipped.
97              
98             =head1 BUGS
99              
100             =over
101              
102             =item Not all capitalizations, characters and numbers
103             have adequate "flipped" representation
104              
105             =back
106              
107             =head1 AUTHOR
108              
109             Lubomir Rintel C<< >>
110              
111             =head1 COPYRIGHT
112              
113             Copyright 2009 Lubomir Rintel, All rights reserved.
114              
115             This program is free software; you can redistribute
116             it and/or modify it under the same terms as Perl itself.
117              
118             =cut