| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # This file is part of Acme::Tie::Eleet. | ||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) 2001-2007 Jerome Quelin, all rights reserved. | ||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||
| 5 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||
| 6 | # it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | package Acme::Tie::Eleet; | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 7 | our $VERSION = '1.0.2'; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | # Our to allow user to hack/overwrite it. | ||||||||||||||||||||||||||||||||
| 22 | 7 | our @beg = ( "hey man, ", "hey dude, ", "cool, ", '$#$!#!$ ', "sure, ", "hey, ", | |||||||||||||||||||||||||||||||
| 23 | "yeah, ", "yeah man, ", "yeah dude, ", "listen, ", "listen pal, " ); | ||||||||||||||||||||||||||||||||
| 24 | 7 | our @end = ( ", fear us.", ", d'ya think so?", ' $#$!#!$!' ); | |||||||||||||||||||||||||||||||
| 25 | 7 | our @sentences = ( "Fear us!", "All your base are belong to us!", | |||||||||||||||||||||||||||||||
| 26 | "Resistance is futile; you will be assimilated.", | ||||||||||||||||||||||||||||||||
| 27 | "Resistance is futile.", "Whololo!" ); | ||||||||||||||||||||||||||||||||
| 28 | 7 | our %words = | |||||||||||||||||||||||||||||||
| 29 | ( apps => "appz", | ||||||||||||||||||||||||||||||||
| 30 | are => "r", | ||||||||||||||||||||||||||||||||
| 31 | awesome => "awesum", | ||||||||||||||||||||||||||||||||
| 32 | because => "cuz", | ||||||||||||||||||||||||||||||||
| 33 | capital => "capitull", | ||||||||||||||||||||||||||||||||
| 34 | cool => [ "kool", "kewl" ], # Anon arrays accepted. | ||||||||||||||||||||||||||||||||
| 35 | dude => "dood", | ||||||||||||||||||||||||||||||||
| 36 | elite => "eleet", | ||||||||||||||||||||||||||||||||
| 37 | every => "evry", | ||||||||||||||||||||||||||||||||
| 38 | everybody => "evry budy", | ||||||||||||||||||||||||||||||||
| 39 | freak => "phreak", | ||||||||||||||||||||||||||||||||
| 40 | games => "gamez", | ||||||||||||||||||||||||||||||||
| 41 | hacker => "haxor", | ||||||||||||||||||||||||||||||||
| 42 | hackers => "haxors", | ||||||||||||||||||||||||||||||||
| 43 | letter => "lettr", | ||||||||||||||||||||||||||||||||
| 44 | letters => "lettrs", | ||||||||||||||||||||||||||||||||
| 45 | phone => "fone", | ||||||||||||||||||||||||||||||||
| 46 | rule => "rulez", | ||||||||||||||||||||||||||||||||
| 47 | see => "c", | ||||||||||||||||||||||||||||||||
| 48 | the => "da", | ||||||||||||||||||||||||||||||||
| 49 | wares => "warez", | ||||||||||||||||||||||||||||||||
| 50 | you => "u", | ||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # Populate the hash. | ||||||||||||||||||||||||||||||||
| 55 | 7 | my %letter = | |||||||||||||||||||||||||||||||
| 56 | ( a => [ "4", "@" ], | ||||||||||||||||||||||||||||||||
| 57 | c => "(", | ||||||||||||||||||||||||||||||||
| 58 | e => "3", | ||||||||||||||||||||||||||||||||
| 59 | g => "6", | ||||||||||||||||||||||||||||||||
| 60 | h => [ "|-|", "]-[" ], | ||||||||||||||||||||||||||||||||
| 61 | k => [ "|<", "]{" ], | ||||||||||||||||||||||||||||||||
| 62 | i => "!", | ||||||||||||||||||||||||||||||||
| 63 | l => [ "1", "|" ], | ||||||||||||||||||||||||||||||||
| 64 | m => [ "|V|", "|\\/|" ], | ||||||||||||||||||||||||||||||||
| 65 | n => "|\\|", | ||||||||||||||||||||||||||||||||
| 66 | o => "0", | ||||||||||||||||||||||||||||||||
| 67 | s => [ "5", "Z" ], | ||||||||||||||||||||||||||||||||
| 68 | t => [ "7", "+"], | ||||||||||||||||||||||||||||||||
| 69 | u => "\\_/", | ||||||||||||||||||||||||||||||||
| 70 | v => "\\/", | ||||||||||||||||||||||||||||||||
| 71 | w => [ "vv", "\\/\\/" ], | ||||||||||||||||||||||||||||||||
| 72 | 'y' => "j", | ||||||||||||||||||||||||||||||||
| 73 | z => "2", | ||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | #-- | ||||||||||||||||||||||||||||||||
| 78 | # Constructor | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 25 | ▶ | sub _new { | ||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||
| 81 | # Create object. | ||||||||||||||||||||||||||||||||
| 82 | 25 | my $self = { | |||||||||||||||||||||||||||||||
| 83 | letters => 25, # transform o to 0, l to 1, etc. | ||||||||||||||||||||||||||||||||
| 84 | spacer => "1/0", # %age 0=no extra spaces, 'm/n'=m extra+n noextra, 60=3/5 at random | ||||||||||||||||||||||||||||||||
| 85 | case_mixer => 50, # %age 0=nothing, 'm/n'=m ucase+n lcase, 25=1/4 at random | ||||||||||||||||||||||||||||||||
| 86 | words => 1, # transform cool to kewl or kool, etc. | ||||||||||||||||||||||||||||||||
| 87 | add_before => 15, # add comments before sentence. | ||||||||||||||||||||||||||||||||
| 88 | add_after => 15, # add comments after sentences. | ||||||||||||||||||||||||||||||||
| 89 | extra_sent => 10, # extra sentences. | ||||||||||||||||||||||||||||||||
| 90 | @_, # overwrite with user values. | ||||||||||||||||||||||||||||||||
| 91 | # internals, do not modify. | ||||||||||||||||||||||||||||||||
| 92 | _space => "m0", | ||||||||||||||||||||||||||||||||
| 93 | _case_mix => "m0" | ||||||||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | # Check patterns. | ||||||||||||||||||||||||||||||||
| 97 | 25 | ▶ | $self->{spacer} =~ m!^(((\d+)/(\d+))|(\d+))$! | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | or croak "spacer: wrong pattern $self->{spacer}"; | ||||||||||||||||||||||||||||||||
| 99 | 24 | ▶ | $self->{spacer} =~ m!^(\d+)/(\d+)$! && $1+$2 == 0 | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"spacer"} =~ m[^(\d+)/(\d+)$] and $1 + $2 == 0
MC/DC100%2/2
$self->{"spacer"} =~ m[^(\d+)/(\d+)$] and $1 + $2 == 0
$self->{"spacer"} =~ m[^(\d+)/(\d+)$]
$1 + $2 == 0
Truth table100%3/3
A and B
A= $self->{"spacer"} =~ m[^(\d+)/(\d+)$]B= $1 + $2 == 0
| |||||||||||||||||||||||||||||||||
| 100 | and croak "spacer: illegal pattern $self->{spacer}"; | ||||||||||||||||||||||||||||||||
| 101 | 23 | ▶ | $self->{case_mixer} =~ m!^(((\d+)/(\d+))|(\d+))$! | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 102 | or croak "case_mixer: wrong pattern $self->{case_mixer}"; | ||||||||||||||||||||||||||||||||
| 103 | 22 | ▶ | $self->{case_mixer} =~ m!^(\d+)/(\d+)$! && $1+$2 == 0 | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"case_mixer"} =~ m[^(\d+)/(\d+)$] and $1 + $2 == 0
MC/DC100%2/2
$self->{"case_mixer"} =~ m[^(\d+)/(\d+)$] and $1 + $2 == 0
$self->{"case_mixer"} =~ m[^(\d+)/(\d+)$]
$1 + $2 == 0
Truth table100%3/3
A and B
A= $self->{"case_mixer"} =~ m[^(\d+)/(\d+)$]B= $1 + $2 == 0
| |||||||||||||||||||||||||||||||||
| 104 | and croak "case_mixer: illegal pattern $self->{case_mixer}"; | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | # Init internals. | ||||||||||||||||||||||||||||||||
| 107 | $self->{spacer} =~ m!^(\d+)/(\d+)$! && $1 == 0 | ||||||||||||||||||||||||||||||||
| 108 | 21 | ▶ | and $self->{_space} = "n0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"spacer"} =~ m[^(\d+)/(\d+)$] and $1 == 0
MC/DC100%2/2
$self->{"spacer"} =~ m[^(\d+)/(\d+)$] and $1 == 0
$self->{"spacer"} =~ m[^(\d+)/(\d+)$]
$1 == 0
Truth table100%3/3
A and B
A= $self->{"spacer"} =~ m[^(\d+)/(\d+)$]B= $1 == 0
| |||||||||||||||||||||||||||||||||
| 109 | $self->{case_mixer} =~ m!^(\d+)/(\d+)$! && $1 == 0 | ||||||||||||||||||||||||||||||||
| 110 | 21 | ▶ | and $self->{_case_mix} = "n0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"case_mixer"} =~ m[^(\d+)/(\d+)$] and $1 == 0
MC/DC100%2/2
$self->{"case_mixer"} =~ m[^(\d+)/(\d+)$] and $1 == 0
$self->{"case_mixer"} =~ m[^(\d+)/(\d+)$]
$1 == 0
Truth table100%3/3
A and B
A= $self->{"case_mixer"} =~ m[^(\d+)/(\d+)$]B= $1 == 0
| |||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | # Return the hash ref. | ||||||||||||||||||||||||||||||||
| 113 | 21 | return $self; | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub TIEHANDLE { | ||||||||||||||||||||||||||||||
|
Subroutine
TIEHANDLE: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 118 | # Process args. | ||||||||||||||||||||||||||||||||
| 119 | 0 | my $pkg = shift; | |||||||||||||||||||||||||||||||
| 120 | 0 | my $fh = shift; | |||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | ref $pkg and croak "Not an instance method"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $fh or croak "Filehandle is not an optional paramater"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 124 | 0 | $fh->autoflush(1); | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 0 | my $self = &_new; # magic call. | |||||||||||||||||||||||||||||||
| 127 | 0 | $self->{FH} = $fh; | |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | # Return it. | ||||||||||||||||||||||||||||||||
| 130 | 0 | return bless( $self, $pkg ); | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 25 | ▶ | sub TIESCALAR { | ||||||||||||||||||||||||||||||
|
Subroutine
TIESCALAR: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 135 | # Process args. | ||||||||||||||||||||||||||||||||
| 136 | 25 | my $pkg = shift; | |||||||||||||||||||||||||||||||
| 137 | 25 | ▶ | ref $pkg and croak "Not an instance method"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 25 | my $self = &_new; # magic call. | |||||||||||||||||||||||||||||||
| 140 | 21 | $self->{value} = undef; | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | # Return it. | ||||||||||||||||||||||||||||||||
| 143 | 21 | return bless( $self, $pkg ); | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | #-- | ||||||||||||||||||||||||||||||||
| 148 | # Handlers. | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | # Catch scalar fetching. | ||||||||||||||||||||||||||||||||
| 151 | 21 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 152 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||
| 153 | 21 | return $self->_transform( $self->{value} ); | |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | # Catch calls to print. | ||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub PRINT { | ||||||||||||||||||||||||||||||
|
Subroutine
PRINT: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 158 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 159 | 0 | my $fh = $self->{FH}; | |||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $_[0] or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 161 | 0 | print $fh $self->_transform(join "", @_); | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | # Catch scalar storing. | ||||||||||||||||||||||||||||||||
| 165 | 21 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 166 | 21 | $_[0]{value} = $_[1]; | |||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | #-- | ||||||||||||||||||||||||||||||||
| 171 | # Modification plugins. | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | # | ||||||||||||||||||||||||||||||||
| 174 | # All plugins will get (not counting the object that will always be | ||||||||||||||||||||||||||||||||
| 175 | # the first argument) a string to modify. Each string will contain one | ||||||||||||||||||||||||||||||||
| 176 | # and only one sentence. | ||||||||||||||||||||||||||||||||
| 177 | # | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | # Add preambles randomly. | ||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | sub _apply_add_before { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_add_before: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 181 | 1 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||
| 182 | 1 | ▶ | if ( rand(100) < $self->{add_before} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 183 | 1 | my $before = $beg[ rand( int(@beg) ) ]; | |||||||||||||||||||||||||||||||
| 184 | 1 | $target = $before.$target; | |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | 1 | return $target; | |||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | # Add end of sentences randomly. | ||||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | sub _apply_add_after { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_add_after: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 191 | 1 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | if ( rand(100) < $self->{add_after} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 193 | 1 | my $after = $end[ rand( int(@end) ) ]; | |||||||||||||||||||||||||||||||
| 194 | 1 | $target .= $after; | |||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | 1 | return $target; | |||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | # Mix case as wanted. | ||||||||||||||||||||||||||||||||
| 200 | 5 | ▶ | sub _apply_case_mixer { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_case_mixer: called CC=16 SCAR=28.0
| |||||||||||||||||||||||||||||||||
| 201 | 5 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 5 | ▶ | if ( $self->{case_mixer} =~ m!^(\d+)/(\d+)$! ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 204 | # Fixed pattern. | ||||||||||||||||||||||||||||||||
| 205 | 3 | my $what = ""; | |||||||||||||||||||||||||||||||
| 206 | 3 | my ($m, $n) = ( $1, $2 ); | |||||||||||||||||||||||||||||||
| 207 | 3 | for my $c (split //, $target) { | |||||||||||||||||||||||||||||||
| 208 | 15 | $self->{_case_mix} =~ m/^([mn])(\d+)$/; | |||||||||||||||||||||||||||||||
| 209 | 15 | ▶ | $what .= ($1 eq "m") ? uc($c) : $c; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 210 | 15 | my $new; | |||||||||||||||||||||||||||||||
| 211 | 15 | my $count = $2 + 1; | |||||||||||||||||||||||||||||||
| 212 | 15 | ▶ | if ( $1 eq "m" ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 213 | 8 | ▶ | $2+1 != $m and $new = "m$count"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 214 | 8 | ▶ | $2+1 == $m && $n == 0 and $new = "m0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$2 + 1 == $m and $n == 0
MC/DC50%1/2
$2 + 1 == $m and $n == 0
$2 + 1 == $m
$n == 0
Truth table66%2/3
A and B
A= $2 + 1 == $mB= $n == 0
| |||||||||||||||||||||||||||||||||
| 215 | 8 | ▶ | $2+1 == $m && $n != 0 and $new = "n0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$2 + 1 == $m and $n != 0
MC/DC50%1/2
$2 + 1 == $m and $n != 0
$2 + 1 == $m
$n != 0
Truth table66%2/3
A and B
A= $2 + 1 == $mB= $n != 0
| |||||||||||||||||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||||||||||||||
| 217 | 7 | ▶ | $2+1 != $n and $new = "n$count"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 218 | 7 | ▶ | $2+1 == $n && $m == 0 and $new = "n0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$2 + 1 == $n and $m == 0
MC/DC50%1/2
$2 + 1 == $n and $m == 0
$2 + 1 == $n
$m == 0
Truth table66%2/3
A and B
A= $2 + 1 == $nB= $m == 0
| |||||||||||||||||||||||||||||||||
| 219 | 7 | ▶ | $2+1 == $n && $m != 0 and $new = "m0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$2 + 1 == $n and $m != 0
MC/DC50%1/2
$2 + 1 == $n and $m != 0
$2 + 1 == $n
$m != 0
Truth table66%2/3
A and B
A= $2 + 1 == $nB= $m != 0
| |||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||
| 221 | 15 | $self->{_case_mix} = $new; | |||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | 3 | $target = $what; | |||||||||||||||||||||||||||||||
| 224 | } else { | ||||||||||||||||||||||||||||||||
| 225 | # Put extra space at random. | ||||||||||||||||||||||||||||||||
| 226 | 2 | ▶ | $target =~ s/(.)/rand(100)<$self->{case_mixer}?uc($1):$1/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | 5 | return $target; | |||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | # Add whole sentences randomly. | ||||||||||||||||||||||||||||||||
| 232 | 21 | ▶ | sub _apply_extra_sent { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_extra_sent: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 233 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||
| 234 | 21 | ▶ | if ( rand(100) < $self->{extra_sent} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 235 | 1 | return $sentences[rand( @sentences ) ]; | |||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||
| 237 | 20 | return undef; | |||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | # Transform o to 0, l to 1, etc. That's 31337! | ||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | sub _apply_letters { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_letters: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 242 | 2 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | 2 | return join "", map { rand(100) < $self->{letters} && exists $letter{$_} ? | |||||||||||||||||||||||||||||||
| 245 | ( ref($letter{$_}) eq ref([]) ) ? | ||||||||||||||||||||||||||||||||
| 246 | 2 | $letter{$_}[rand( @{$letter{$_}} ) ] : | |||||||||||||||||||||||||||||||
| 247 | 10 | ▶ | $letter{$_} | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
rand 100 < $self->{"letters"} and exists $letter{$_}
MC/DC50%1/2
rand 100 < $self->{"letters"} and exists $letter{$_}
rand 100 < $self->{"letters"}
exists $letter{$_}
Truth table66%2/3
A and B
A= rand 100 < $self->{"letters"}B= exists $letter{$_}
| |||||||||||||||||||||||||||||||||
| 248 | : $_ } split //, $target; | ||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | # Put extra space between chars. | ||||||||||||||||||||||||||||||||
| 252 | 5 | ▶ | sub _apply_spacer { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_spacer: called CC=16 SCAR=28.0
| |||||||||||||||||||||||||||||||||
| 253 | 5 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | 5 | ▶ | if ( $self->{spacer} =~ m!^(\d+)/(\d+)$! ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 256 | # Fixed pattern. | ||||||||||||||||||||||||||||||||
| 257 | 3 | my $what = ""; | |||||||||||||||||||||||||||||||
| 258 | 3 | my ($m, $n) = ( $1, $2 ); | |||||||||||||||||||||||||||||||
| 259 | 3 | for my $c (split //, $target) { | |||||||||||||||||||||||||||||||
| 260 | 20 | $self->{_space} =~ m/^([mn])(\d+)$/; | |||||||||||||||||||||||||||||||
| 261 | 20 | ▶ | $what .= ($1 eq "m") ? "$c " : $c; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 262 | 20 | my $new; | |||||||||||||||||||||||||||||||
| 263 | 20 | my $count = $2 + 1; | |||||||||||||||||||||||||||||||
| 264 | 20 | ▶ | if ( $1 eq "m" ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 265 | 10 | ▶ | $2+1 != $m and $new = "m$count"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 266 | 10 | ▶ | $2+1 == $m && $n == 0 and $new = "m0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$2 + 1 == $m and $n == 0
MC/DC50%1/2
$2 + 1 == $m and $n == 0
$2 + 1 == $m
$n == 0
Truth table66%2/3
A and B
A= $2 + 1 == $mB= $n == 0
| |||||||||||||||||||||||||||||||||
| 267 | 10 | ▶ | $2+1 == $m && $n != 0 and $new = "n0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$2 + 1 == $m and $n != 0
MC/DC50%1/2
$2 + 1 == $m and $n != 0
$2 + 1 == $m
$n != 0
Truth table66%2/3
A and B
A= $2 + 1 == $mB= $n != 0
| |||||||||||||||||||||||||||||||||
| 268 | } else { | ||||||||||||||||||||||||||||||||
| 269 | 10 | ▶ | $2+1 != $n and $new = "n$count"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 270 | 10 | ▶ | $2+1 == $n && $m == 0 and $new = "n0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$2 + 1 == $n and $m == 0
MC/DC50%1/2
$2 + 1 == $n and $m == 0
$2 + 1 == $n
$m == 0
Truth table66%2/3
A and B
A= $2 + 1 == $nB= $m == 0
| |||||||||||||||||||||||||||||||||
| 271 | 10 | ▶ | $2+1 == $n && $m != 0 and $new = "m0"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$2 + 1 == $n and $m != 0
MC/DC50%1/2
$2 + 1 == $n and $m != 0
$2 + 1 == $n
$m != 0
Truth table66%2/3
A and B
A= $2 + 1 == $nB= $m != 0
| |||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | 20 | $self->{_space} = $new; | |||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||
| 275 | 3 | $target = $what; | |||||||||||||||||||||||||||||||
| 276 | } else { | ||||||||||||||||||||||||||||||||
| 277 | # Put extra space at random. | ||||||||||||||||||||||||||||||||
| 278 | 2 | ▶ | $target =~ s/(.)/rand(100)<$self->{spacer}?"$1 ":$1/eg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||
| 280 | 5 | return $target; | |||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | # Transform words according to %words. | ||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | sub _apply_words { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_words: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 285 | 2 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||
| 286 | 2 | my @what = (); | |||||||||||||||||||||||||||||||
| 287 | 2 | for my $word ( split / /, $target ) { | |||||||||||||||||||||||||||||||
| 288 | 2 | ▶ | if ( exists( $words{$word} ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 289 | 2 | my $subst = $words{$word}; | |||||||||||||||||||||||||||||||
| 290 | 2 | ▶ | $word = ref($subst) eq ref([]) ? | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 291 | $subst->[ rand( int(@$subst) ) ] | ||||||||||||||||||||||||||||||||
| 292 | : $subst; | ||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||
| 294 | 2 | push @what, $word; | |||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||
| 296 | 2 | return join " ", @what; | |||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | # Main entry point for string transformation. | ||||||||||||||||||||||||||||||||
| 300 | 21 | ▶ | sub _transform { | ||||||||||||||||||||||||||||||
|
Subroutine
_transform: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||
| 301 | 21 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | 21 | ▶ | $line or return; # Case undef. | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 304 | 21 | my $sentence; | |||||||||||||||||||||||||||||||
| 305 | 21 | my @what = split "([.?!\n])", lc $line; | |||||||||||||||||||||||||||||||
| 306 | 21 | ▶ | while ( my ($what, $punc) = splice @what, 0, 2 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 307 | # Build the sentence. | ||||||||||||||||||||||||||||||||
| 308 | 21 | ▶ | $self->{add_before} and $what = $self->_apply_add_before($what); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 309 | 21 | ▶ | $self->{add_after} and $what = $self->_apply_add_after($what); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 21 | ▶ | defined($punc) and $what .= $punc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||
| 313 | 21 | my $extra = $self->_apply_extra_sent(); | |||||||||||||||||||||||||||||||
| 314 | 21 | ▶ | $extra and $what .= " $extra"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | # Transform chars. | ||||||||||||||||||||||||||||||||
| 317 | 21 | foreach my $plugin ( qw( words spacer letters case_mixer ) ) { | |||||||||||||||||||||||||||||||
| 318 | 84 | my $meth = "_apply_$plugin"; | |||||||||||||||||||||||||||||||
| 319 | 84 | ▶ | $self->{$plugin} and $what = $self->$meth($what); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||
| 321 | 21 | $sentence .= $what; | |||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||
| 323 | 21 | return $sentence; | |||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||
| 326 | # By default, tie standard filedescriptors. | ||||||||||||||||||||||||||||||||
| 327 | # tie *STDOUT, __PACKAGE__, *STDOUT; | ||||||||||||||||||||||||||||||||
| 328 | # tie *STDERR, __PACKAGE__, *STDERR; | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | 7 | 1; | |||||||||||||||||||||||||||||||
| 332 | __END__ | ||||||||||||||||||||||||||||||||