line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Mutate; |
2
|
1
|
|
|
1
|
|
23253
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
3
|
1
|
|
|
1
|
|
1206
|
use Class::Prototyped; |
|
1
|
|
|
|
|
12579
|
|
|
1
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
53
|
use Exporter (); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
21
|
|
7
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
133
|
|
8
|
1
|
|
|
1
|
|
2
|
$VERSION = '0.04'; |
9
|
1
|
|
|
|
|
59
|
@ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
11
|
1
|
|
|
|
|
2
|
@EXPORT = qw(); |
12
|
1
|
|
|
|
|
2
|
@EXPORT_OK = qw(); |
13
|
1
|
|
|
|
|
549
|
%EXPORT_TAGS = (); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#################### subroutine #################### |
18
|
|
|
|
|
|
|
# Make our array of junk-like characters |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @JUNK; |
21
|
|
|
|
|
|
|
sub mkjunk { |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
0
|
|
for (my $i = 33; $i <= 47; $i++) { |
24
|
0
|
|
|
|
|
|
push @JUNK, chr($i); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#################### constructor #################### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub proto { |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
0
|
|
mkjunk; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $p = Class::Prototyped->new |
37
|
|
|
|
|
|
|
( |
38
|
|
|
|
|
|
|
string => 'Hello, World' |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $p2 = Class::Prototyped->new |
42
|
|
|
|
|
|
|
( |
43
|
|
|
|
|
|
|
'parent*' => $p |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $mir = $p2->reflect; |
47
|
0
|
|
|
|
|
|
$mir->addSlots |
48
|
|
|
|
|
|
|
( |
49
|
|
|
|
|
|
|
m_append => \&append, |
50
|
|
|
|
|
|
|
m_prepend => \&prepend, |
51
|
|
|
|
|
|
|
m_insert => \&insert, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$mir->addSlot |
55
|
|
|
|
|
|
|
( |
56
|
|
|
|
|
|
|
m_rand_insert => sub { |
57
|
0
|
|
|
0
|
|
|
my ($self, $insert_text) = @_; |
58
|
0
|
|
|
|
|
|
$self->m_insert($insert_text); |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$mir->addSlot |
63
|
|
|
|
|
|
|
( |
64
|
|
|
|
|
|
|
m_chunk_of_junk => \&chunk_of_junk |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $p2; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#################### methods #################### |
73
|
|
|
|
|
|
|
# We install these in the constructor, but write |
74
|
|
|
|
|
|
|
# them out here because the bodies are too long |
75
|
|
|
|
|
|
|
# to fit into the constructor |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub append { |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
0
|
0
|
|
my ($self, $text) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->string($self->string . $text); |
82
|
0
|
|
|
|
|
|
$self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub prepend { |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
0
|
|
my ($self, $text) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->string($text . $self->string); |
90
|
0
|
|
|
|
|
|
$self; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub insert { |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
0
|
0
|
|
my ($self, $text, $position) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
0
|
|
|
|
if (not defined $position or $position < 1) { |
98
|
0
|
|
|
|
|
|
my $lth = length $self->string; |
99
|
|
|
|
|
|
|
#warn "string length; $lth"; |
100
|
0
|
|
|
|
|
|
$position = 1 + int(rand( $lth - 1 )); |
101
|
|
|
|
|
|
|
#warn "rand_position: $position"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $pre = substr($self->string, 0, $position); |
105
|
0
|
|
|
|
|
|
my $post = substr($self->string, $position); |
106
|
0
|
|
|
|
|
|
my $out = "$pre$text$post"; |
107
|
0
|
|
|
|
|
|
$self->string($out); |
108
|
0
|
|
|
|
|
|
$self; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub chunk_of_junk { |
112
|
0
|
|
|
0
|
0
|
|
my ($self, $chunk_length) = @_; |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
defined $chunk_length or die 'must supply chunk length' ; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $chunk; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
for (1 .. $chunk_length) { |
119
|
0
|
|
|
|
|
|
$chunk = $chunk . $JUNK[ rand @JUNK ] ; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#warn "CHUNK: $chunk JUNK: @JUNK"; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$self->m_rand_insert($chunk); |
126
|
0
|
|
|
|
|
|
$self; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#################### main pod documentation begin ################### |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 NAME |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
String::Mutate - extensible chaining of string modifiers |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 SYNOPSIS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
use String::Mutate; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Create base object with a string slot and some useful |
140
|
|
|
|
|
|
|
# string modifiers. |
141
|
|
|
|
|
|
|
my $proto = String::Mutate->proto; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$proto->string # "Hello, World" |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Hello, World. It's me Bob |
146
|
|
|
|
|
|
|
$proto->m_append(". It's me Bob"); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Biff!Hello, World. It's me Bob |
149
|
|
|
|
|
|
|
$proto->m_prepend("Biff!"); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# Biff!--Hello, World. It's me Bob |
152
|
|
|
|
|
|
|
$proto->m_insert("--", 4); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Insert yuy at some_random_place into the string |
155
|
|
|
|
|
|
|
$proto->m_rand_insert("yuy"); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# Insert $number junk chars at some_random_place into the string |
158
|
|
|
|
|
|
|
$proto->string('reset to clean string'); |
159
|
|
|
|
|
|
|
my $number=4; |
160
|
|
|
|
|
|
|
$proto->m_chunk_of_junk($number); # res()`*et to clean string |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 DESCRIPTION |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
There comes a time in every data munger's career when he needs to muck up the |
166
|
|
|
|
|
|
|
data. This module is designed to make it easy to code up your own |
167
|
|
|
|
|
|
|
special wecial, tasty-wasty string mucker-uppers. It comes with the |
168
|
|
|
|
|
|
|
mucker-uppers you saw in the SYNOPSIS. But you are dealing with a |
169
|
|
|
|
|
|
|
L object, so you can extend the |
170
|
|
|
|
|
|
|
beskimmers out of it if you so please. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
And now.... method chaining! |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 USAGE |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Well, the SYNOPSIS told all. But let's say what we just said again. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
First you construct your prototype object: |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my $proto = String::Mutate->proto; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Then you call any of the C methods which will then mutate |
183
|
|
|
|
|
|
|
C<< $proto->string >> and leave the results in same. So without further adieu, |
184
|
|
|
|
|
|
|
here are the pre-packaged string mutators |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 BUILT-IN STRING MUTATION METHODS |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 m_append |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Usage : $proto->m_append('some text to append'); |
192
|
|
|
|
|
|
|
Purpose : Append text to $proto->string |
193
|
|
|
|
|
|
|
Argument : the text to append. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 m_prepend |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Usage : $proto->m_prepend('some text to PREpend'); |
200
|
|
|
|
|
|
|
Purpose : Prepend text to $proto->string |
201
|
|
|
|
|
|
|
Argument : the text to Prepend. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 m_insert |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Usage : $proto->m_insert('insertiontext', $after_what_char); |
206
|
|
|
|
|
|
|
Purpose : put insertion text into string after a certain char |
207
|
|
|
|
|
|
|
Returns : nothing. this is OOP you know. |
208
|
|
|
|
|
|
|
Argument : |
209
|
|
|
|
|
|
|
1 - the text to insert |
210
|
|
|
|
|
|
|
2 - the 1-offset position to insert at |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 m_rand_insert |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Usage : $proto->m_rand_insert('text'); |
216
|
|
|
|
|
|
|
Purpose : put insertion text into string at some random place |
217
|
|
|
|
|
|
|
Returns : nothing. this is OOP you know. |
218
|
|
|
|
|
|
|
Argument : |
219
|
|
|
|
|
|
|
1- the text to insert at some random place in the string. When is someone |
220
|
|
|
|
|
|
|
going to write something to automatically generate this assinine |
221
|
|
|
|
|
|
|
butt-obvious documentation from my fresh, crispy clean with no |
222
|
|
|
|
|
|
|
caffeine source code?! sounds like a good master's project for some |
223
|
|
|
|
|
|
|
AI weenie. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 m_chunk_of_junk |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Usage : $proto->m_chunk_of_junk($chunk_size) |
228
|
|
|
|
|
|
|
Purpose : put a string of junk chars of length $chunk_size into |
229
|
|
|
|
|
|
|
string at some random place |
230
|
|
|
|
|
|
|
Returns : nothing. this is OOP you know. |
231
|
|
|
|
|
|
|
Argument : How long you want the chunk of junk to be. Actually it isnt |
232
|
|
|
|
|
|
|
how long you *want* it to be. It is how long it will be whether |
233
|
|
|
|
|
|
|
you want it that way or not. Computers are like that. Stubborn |
234
|
|
|
|
|
|
|
lil suckers. Fast, useful, but not so obliging. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 BUGS |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
There are rougly 3,562,803 bugs in this code. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 AUTHOR |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Terrence M. Brannon |
247
|
|
|
|
|
|
|
CPAN ID: TBONE |
248
|
|
|
|
|
|
|
metaperl.org computation |
249
|
|
|
|
|
|
|
tbone@cpan.org |
250
|
|
|
|
|
|
|
http://www.metaperl.org |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 COPYRIGHT |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
This program is free software; you can redistribute |
255
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
The full text of the license can be found in the |
258
|
|
|
|
|
|
|
LICENSE file included with this module. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 SEE ALSO |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
#################### main pod documentation end ################### |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
1; |
271
|
|
|
|
|
|
|
# The preceding line will help the module return a true value |
272
|
|
|
|
|
|
|
|