blib/lib/Text/Bastardize.pm

filter: Statementstmt 98.3% 122 / 124 Branchbran 73.3% 22 / 30 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 13 / 13 Podpod 100% 11 / 11 totaltotal 92.5% 174 / 188 CC 27 SCAR 21.8
CC
27
Cov
92%
pig
17.7
censor
5.0
n20e
4.0
CRAP 8.9
↑ Summary
1 ## -*- Cperl -*-
2 package Text::Bastardize;
3 1 $VERSION = 0.08;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ----------------------------------------------------------------------
8 # Copyright (C) 1999-2006 Julian Fondren <ayrnieu@gmail.com>
9 # Licensed as with perl itself.
10 # ----------------------------------------------------------------------
11  
12 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod documented
13 1 my $proto = shift;
14 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
15 1 my $self = [];
16 1 bless($self, $class)
17 }
18  
19 9 ▶sub peek { @{+shift} }
Subroutine peek: called CC=1 SCAR=0.0
Pod documented
20 1 ▶sub charge {
Subroutine charge: called CC=1 SCAR=0.0
Pod documented
21 1 my $self = shift;
22 1 @{$self} = @_;
23 1 $self
24 }
25  
26 1 ▶sub disemvowel {
Subroutine disemvowel: called CC=2 SCAR=6.9
Pod documented
27 1 my @d = shift->peek;
28 1 s/\B[aeiou]\B//ig for @d;
29 @d
30 1 }
31  
32 1 ▶sub rot13 {
Subroutine rot13: called CC=1 SCAR=0.0
Pod documented
33 1 my $self = shift;
34 1 map { tr/a-zA-Z/n-za-mN-ZA-M/; $_ } $self->peek
35 }
36  
37 1 ▶sub k3wlt0k {
Subroutine k3wlt0k: called CC=2 SCAR=6.9
Pod documented
38 # a slightly modified version of Fmh's t0k.pl
39 1 my $self = shift;
40 1 my @k = $self->peek;
41 1 for (@k) {
42 1 y/A-Z/a-z/;
43 1 s/\bth/d/sg;
44 1 s/ck\b/x0r/sg;
45 1 s/cking\b/x0ring/sg;
46 1 s/cked\b/x0red/sg;
47 1 s/cker/x0r/sg;
48 1 s/or/er/sg;
49 1 s/ing/in/sg;
50 1 s/cause/cus/sg;
51 1 s/fu/f00/sg;
52 1 s/word/werd/sg;
53 1 s/oo/ew/sg;
54 1 s/for/4/sg;
55 1 s/ate/8/sg;
56 1 y/uaes itz clo/v34z 17s s10/;
57 1 s/\'//sg;
58 1 s/\./.../sg;
59 1 s/!/!!!/sg;
60 1 s/\?/???/sg;
61 1 s/\bc/k/sg;
62 1 s/00/o0/sg;
63 1 s/0rk/r0k/sg;
64 1 s/y0v/j00/sg;
65 1 s/[ck]o01/k3wl/sg;
66 1 s/741k/t0k/sg;
67 1 s/j00\B/j3r/sg;
68 1 s/3z/z3/sg;
69 1 s/3r/ur/sg;
70 1 y/a-z/A-Z/;
71 }
72 @k
73 1 }
74  
75 1 ▶sub rdct {
Subroutine rdct: called CC=2 SCAR=6.9
Pod documented
76 1 my $self = shift;
77 1 my @r = $self->peek;
78 1 for (@r) {
79 1 y/A-Z/a-z/;
80 1 y/!#.,?\'\";//;
81 1 s/of/uv/sg;
82 1 s/one/1/sg;
83 1 s/\b(?:a|e)//sg;
84 1 s/a?n?ks/x/sg;
85 1 s/you/u/sg;
86 1 s/are/r/sg;
87 1 s/youre?/ur/sg;
88 1 s/\B(?:a|e|i|o|u)\B//sg;
89 }
90 @r
91 1 }
92  
93 # 7Oct2006: I don't care about this right now;
94 # presumably it works. Will look it over for the
95 # next release.
96 1 ▶sub pig {
Subroutine pig: called CC=16 SCAR=28.7
Pod documented
97 1 my $self = shift;
98 1 my @pig; # what is to be returned, the final result
99 my @piggie; # a word-by-word splitting of each element
100 1 my $allupper;
101 1 my $firstupper;
102 1 my $i = 0;
103 1 for my $v ($self->peek()) { # by line
104 1 @piggie = split(/ /, $v);
105 1 for my $w (@piggie) { # by word
106 11 ▶ "\U$w" eq $w ? $allupper = 1 : $allupper = 0;
Branch: 1 branch
BranchTrueFalseTotal
uc $w eq $w ? : 1 10 11
107
108 # append "way" if word starts with an un'y' vowel
109 11 ▶ if (substr($w, 0, 1) =~ /a|e|i|o|u/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($w, 0, 1) =~ /a|e|i|o|u/i) 3 8 11
110 3 ▶ $allupper ? $w .= "WAY" : $w .= "way";
Branch: 1 branch
BranchTrueFalseTotal
$allupper ? : 0 3 3
111 }
112 11 ▶ "\u\L$w" eq $w ? $firstupper = 1 : $firstupper = 0;
Branch: 1 branch
BranchTrueFalseTotal
ucfirst lc $w eq $w ? : 1 10 11
113 11 ▶ $w =lc $w unless $allupper;
Branch: 1 branch
BranchTrueFalseTotal
unless $allupper 11 0 11
114
115 # copy leading consonants to the end of the word,
116 # not counting "qu"
117 11 ▶ until (substr($w, 0, 1) =~ /a|e|i|o|u|y/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless (substr($w, 0, 1) =~ /a|e|i|o|u|y/i) 10 11 21
118 10 ▶ unless (substr($w, 0, 2) eq "qu") {
Branch: 1 branch
BranchTrueFalseTotal
unless (substr($w, 0, 2) eq "qu") 10 0 10
119 10 $w = join '', reverse unpack ('aa*', $w);
120 }
121 }
122 11 ▶ $w .= "ay" unless substr($w,-2,2) eq "ay";
Branch: 1 branch
BranchTrueFalseTotal
unless substr($w, -2, 2) eq "ay" 8 3 11
123
124 # sickness.
125 11 ▶ if ($w =~ /[.!?,%]/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w =~ /[.!?,%]/s) 2 9 11
126 2 $w =~ s/([,.!?])//s;
127 2 ▶ $w .= $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 2 0 2
128 }
129 11 ▶ if ($w =~ /[\$]/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w =~ /[\$]/s) 0 11 11
130 0 $w =~ s/([\$])//s;
131 0 ▶ $w .= $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
132 }
133
134 11 ▶ $w = ucfirst $w if $firstupper;
Branch: 1 branch
BranchTrueFalseTotal
if $firstupper 0 11 11
135 11 $piggie[$i++] = $w;
136 }
137 1 push(@pig, join(' ', @piggie));
138 }
139 1 return @pig;
140 }
141  
142 1 ▶sub rev {
Subroutine rev: called CC=1 SCAR=0.0
Pod documented
143 1 my $self = shift;
144 1 map { scalar reverse $_ } $self->peek;
145 }
146  
147 1 ▶sub censor {
Subroutine censor: called CC=5 SCAR=16.1
Pod documented
148 1 my $self = shift;
149 1 my @censor;
150 1 LINE: foreach my $l ($self->peek()) {
151 1 my @w;
152 1 WORD: foreach my $w (split / /, $l) {
153 11 ▶ $w =~ y/aeiouAEIOU/**********/
Branch: 1 branch
BranchTrueFalseTotal
unless length $w > 10 or length $w < 4 6 5 11
Condition100%3/3
length $w > 10 or length $w < 4
l!l&&r!l&&!r
146
MC/DC100%2/2
length $w > 10 or length $w < 4
length $w > 10 length $w < 4
Truth table100%3/3
A or B
A= length $w > 10B= length $w < 4
ABresult
1X1
011
000
154 unless (length $w > 10 or length $w < 4);
155 11 push @w, $w;
156 }
157 1 push @censor, (join ' ', @w);
158 }
159 1 @censor;
160 }
161  
162 1 ▶sub n20e {
Subroutine n20e: called CC=4 SCAR=13.9
Pod documented
163 # numerical_abbreviation
164 1 my $self = shift;
165 1 my @n20e;
166 1 LINE: foreach my $l ($self->peek()) {
167 1 my @w;
168 1 WORD: foreach my $w (split / /, $l) {
169 11 my $chars = length $w;
170 11 ▶ if ($chars <= 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chars <= 6) 8 3 11
171 8 push @w, $w;
172 8 next WORD;
173 }
174 3 my @chars = (substr($w, 0, 1), substr($w, -1, 1));
175 3 push @w, ($chars[0] . ($chars - 2) . $chars[1]);
176 }
177 1 push @n20e, (join ' ', @w);
178 }
179 1 @n20e;
180 }
181  
182 1 1;
183  
184 __END__
↑ Summary