| 1 | package POE::Filter::KennySpeak; | ||||||||||||||||||||||||||||
| 2 | 2 | $POE::Filter::KennySpeak::VERSION = '1.02'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: Mmm PfmPpfMpp Mpfmffpmffmpmpppff fmpmfpmmmfmp fmppffmmmpppfmmpmfmmmfmpmppfmm fmpppf mmmpppmpm mpfpffppfppm PmpmppppppppffmFmmpfmmppmmmpmp | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base qw(POE::Filter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | my $kenny = _generateKenny(); # encoding table | |||||||||||||||||||||||||||
| 11 | 2 | my $dekenny = _generateDeKenny($kenny); # decoding table | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 15 | 1 | my %opts = @_; | |||||||||||||||||||||||||||
| 16 | 1 | $opts{lc $_} = delete $opts{$_} for keys %opts; | |||||||||||||||||||||||||||
| 17 | 1 | $opts{BUFFER} = []; | |||||||||||||||||||||||||||
| 18 | 1 | return bless \%opts, $class; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | sub get_one_start { | ||||||||||||||||||||||||||
|
Subroutine
get_one_start: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 2 | my ($self, $raw) = @_; | |||||||||||||||||||||||||||
| 23 | 2 | push @{ $self->{BUFFER} }, $_ for @$raw; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 18 | ▶ | sub get_one { | ||||||||||||||||||||||||||
|
Subroutine
get_one: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 18 | my $self = shift; | |||||||||||||||||||||||||||
| 28 | 18 | my $events = []; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 18 | my $event = shift @{ $self->{BUFFER} }; | |||||||||||||||||||||||||||
| 31 | 18 | ▶ | if ( defined $event ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 16 | my $record = _translate($event,1); | |||||||||||||||||||||||||||
| 33 | 16 | ▶ | push @$events, $record if $record; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 18 | return $events; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub get_pending { | ||||||||||||||||||||||||||
|
Subroutine
get_pending: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 0 | return $self->{BUFFER}; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | sub put { | ||||||||||||||||||||||||||
|
Subroutine
put: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 2 | my ($self, $events) = @_; | |||||||||||||||||||||||||||
| 45 | 2 | my $raw_lines = []; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | foreach my $event (@$events) { | |||||||||||||||||||||||||||
| 48 | 16 | ▶ | if ( defined $event ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 16 | my $record = _translate($event); | |||||||||||||||||||||||||||
| 50 | 16 | ▶ | push @$raw_lines, $record if $record; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | return $raw_lines; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 59 | 1 | my $nself = { }; | |||||||||||||||||||||||||||
| 60 | 1 | $nself->{$_} = $self->{$_} for keys %{ $self }; | |||||||||||||||||||||||||||
| 61 | 1 | $nself->{BUFFER} = [ ]; | |||||||||||||||||||||||||||
| 62 | 1 | return bless $nself, ref $self; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | ##### Generate KennySpeak encoding table | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub _generateKenny { | ||||||||||||||||||||||||||
|
Subroutine
_generateKenny: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 68 | 2 | my %kenny; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # lower case characters | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | my ($a, $b, $c) = (0,0,0); | |||||||||||||||||||||||||||
| 73 | 2 | for my $char ("a".."z") { | |||||||||||||||||||||||||||
| 74 | 52 | my $foo = $a.$b.$c; | |||||||||||||||||||||||||||
| 75 | 52 | $foo =~ tr/012/mpf/; | |||||||||||||||||||||||||||
| 76 | 52 | $kenny{$char} = $foo; | |||||||||||||||||||||||||||
| 77 | 52 | $c++; | |||||||||||||||||||||||||||
| 78 | 52 | ▶ | if ($c == 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 16 | $c=0; | |||||||||||||||||||||||||||
| 80 | 16 | $b++; | |||||||||||||||||||||||||||
| 81 | 16 | ▶ | if ($b == 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 4 | $b=0; | |||||||||||||||||||||||||||
| 83 | 4 | $a++; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # upper case characters | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | map { $kenny{uc $_} = ucfirst $kenny{$_} } keys %kenny; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | return \%kenny; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | ##### Generate KennySpeak decoding table | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 2 | ▶ | sub _generateDeKenny { | ||||||||||||||||||||||||||
|
Subroutine
_generateDeKenny: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 100 | 2 | my %dekenny; | |||||||||||||||||||||||||||
| 101 | 2 | my $kenny = $_[0]; | |||||||||||||||||||||||||||
| 102 | 2 | foreach my $key (keys %{$kenny}) | |||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||
| 104 | 104 | my ($a, $b, $c) = split //, $kenny->{$key}; | |||||||||||||||||||||||||||
| 105 | 104 | ▶ | if (! exists $dekenny{$a}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 12 | $dekenny{$a} = {}; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 104 | ▶ | if (! exists $dekenny{$a}->{$b}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 36 | $dekenny{$a}->{$b} = {}; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 104 | $dekenny{$a}->{$b}->{$c} = $key; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 2 | return \%dekenny; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | ##### Encode/decode a given line | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 32 | ▶ | sub _translate { | ||||||||||||||||||||||||||
|
Subroutine
_translate: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 121 | 32 | my $in = shift; | |||||||||||||||||||||||||||
| 122 | 32 | my $dialect = shift; | |||||||||||||||||||||||||||
| 123 | 32 | my $out = ''; | |||||||||||||||||||||||||||
| 124 | 32 | ▶ | if ($dialect) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 16 | ▶ | $out .= exists $kenny->{$1} ? $kenny->{$1} : $1 while ($in =~ s/^(.)//); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||
| 128 | 16 | my @chars = split //, $in; | |||||||||||||||||||||||||||
| 129 | 16 | ▶ | while (@chars) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 656 | ▶ | if ((@chars > 2) and (exists $dekenny->{$chars[0]}->{$chars[1]}->{$chars[2]})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@chars > 2 and exists $$dekenny{$chars[0]}{$chars[1]}{$chars[2]}
MC/DC100%2/2
@chars > 2 and exists $$dekenny{$chars[0]}{$chars[1]}{$chars[2]}
@chars > 2
exists $$dekenny{$chars[0]}{$chars[1]}{$chars[2]}
Truth table100%3/3
A and B
A= @chars > 2B= exists $$dekenny{$chars[0]}{$chars[1]}{$chars[2]}
| |||||||||||||||||||||||||||||
| 131 | 516 | $out .= $dekenny->{$chars[0]}->{$chars[1]}->{$chars[2]}; | |||||||||||||||||||||||||||
| 132 | 516 | shift @chars; | |||||||||||||||||||||||||||
| 133 | 516 | shift @chars; | |||||||||||||||||||||||||||
| 134 | 516 | shift @chars; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||
| 137 | 140 | $out .= shift @chars; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 32 | return $out; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 2 | 'Fmpmmmpmfpmp pmfmffpmpmpp Pmpmppppppppffm!'; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # | ||||||||||||||||||||||||||||
| 148 | # kenny.pl -- translate from and to KennySpeak | ||||||||||||||||||||||||||||
| 149 | # | ||||||||||||||||||||||||||||
| 150 | # $Revision: 1.7 $ | ||||||||||||||||||||||||||||
| 151 | # | ||||||||||||||||||||||||||||
| 152 | # Licensed unter the Artistic License: | ||||||||||||||||||||||||||||
| 153 | # http://www.perl.com/language/misc/Artistic.html | ||||||||||||||||||||||||||||
| 154 | # | ||||||||||||||||||||||||||||
| 155 | # (C) 2001,2002 by Christian Garbs <mitch@cgarbs.de>, http://www.cgarbs.de | ||||||||||||||||||||||||||||
| 156 | # Alan Eldridge <alane@geeksrus.net> | ||||||||||||||||||||||||||||
| 157 | # | ||||||||||||||||||||||||||||
| 158 | # KennySpeak invented by Kohan Ikin <syneryder@namesuppressed.com> | ||||||||||||||||||||||||||||
| 159 | # http://www.namesuppressed.com/kenny/ | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||