line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Venus::Replace; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
71
|
use 5.018; |
|
3
|
|
|
|
|
10
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
72
|
|
6
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
98
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
16
|
use Venus::Class 'attr', 'base', 'with'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
21
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
base 'Venus::Kind::Utility'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Venus::Role::Explainable'; |
13
|
|
|
|
|
|
|
with 'Venus::Role::Stashable'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use overload ( |
16
|
|
|
|
|
|
|
'""' => 'explain', |
17
|
1
|
|
|
1
|
|
4
|
'eq' => sub{"$_[0]" eq "$_[1]"}, |
18
|
1
|
|
|
1
|
|
3
|
'ne' => sub{"$_[0]" ne "$_[1]"}, |
19
|
1
|
|
|
1
|
|
4
|
'qr' => sub{qr{@{[quotemeta("$_[0]")]}}}, |
|
1
|
|
|
|
|
4
|
|
20
|
3
|
|
|
|
|
35
|
'~~' => 'explain', |
21
|
|
|
|
|
|
|
fallback => 1, |
22
|
3
|
|
|
3
|
|
25
|
); |
|
3
|
|
|
|
|
7
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# ATTRIBUTES |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
attr 'flags'; |
27
|
|
|
|
|
|
|
attr 'regexp'; |
28
|
|
|
|
|
|
|
attr 'string'; |
29
|
|
|
|
|
|
|
attr 'substr'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# BUILDERS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub build_self { |
34
|
25
|
|
|
25
|
0
|
61
|
my ($self, $data) = @_; |
35
|
|
|
|
|
|
|
|
36
|
25
|
50
|
|
|
|
81
|
$self->flags('') if !$self->flags; |
37
|
25
|
50
|
|
|
|
87
|
$self->regexp(qr//) if !defined $self->regexp; |
38
|
25
|
50
|
|
|
|
69
|
$self->string('') if !defined $self->string; |
39
|
25
|
50
|
|
|
|
82
|
$self->substr('') if !defined $self->substr; |
40
|
|
|
|
|
|
|
|
41
|
25
|
|
|
|
|
56
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub captures { |
47
|
1
|
|
|
1
|
1
|
5
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
33
|
|
|
6
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
6
|
my $string = $self->initial; |
52
|
1
|
|
|
|
|
5
|
my $last_match_start = $self->last_match_start; |
53
|
1
|
|
|
|
|
5
|
my $last_match_end = $self->last_match_end; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
3
|
my $captures = []; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
10
|
for (my $i = 1; $i < @$last_match_end; $i++) { |
58
|
1
|
|
50
|
|
|
7
|
my $start = $last_match_start->[$i] || 0; |
59
|
1
|
|
50
|
|
|
4
|
my $end = $last_match_end->[$i] || 0; |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
7
|
push @$captures, substr $string, $start, $end - $start; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
1
|
50
|
|
|
|
6
|
return wantarray ? (@$captures) : $captures; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub count { |
68
|
1
|
|
|
1
|
1
|
7
|
my ($self) = @_; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
33
|
|
|
6
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
9
|
return $evaluation->[2]; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub evaluate { |
76
|
24
|
|
|
24
|
1
|
44
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
24
|
|
|
|
|
47
|
my $captures = 0; |
79
|
24
|
|
|
|
|
60
|
my $flags = $self->flags; |
80
|
24
|
|
|
|
|
48
|
my @matches = (); |
81
|
24
|
|
|
|
|
64
|
my $regexp = $self->regexp; |
82
|
24
|
|
|
|
|
53
|
my $string = $self->string; |
83
|
24
|
|
|
|
|
55
|
my $substr = $self->substr; |
84
|
24
|
|
|
|
|
54
|
my $initial = "$string"; |
85
|
|
|
|
|
|
|
|
86
|
24
|
|
|
|
|
37
|
local $@; |
87
|
2
|
|
50
|
2
|
|
1058
|
eval join ';', ( |
|
2
|
|
|
|
|
1040
|
|
|
2
|
|
|
|
|
45
|
|
|
24
|
|
|
|
|
2111
|
|
88
|
|
|
|
|
|
|
'$captures = (' . '$string =~ s/$regexp/$substr/' . ($flags // '') . ')', |
89
|
|
|
|
|
|
|
'@matches = ([@-], [@+], {%-})', |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
24
|
|
|
|
|
106
|
my $error = $@; |
93
|
|
|
|
|
|
|
|
94
|
24
|
100
|
|
|
|
76
|
if ($error) { |
95
|
1
|
|
|
|
|
15
|
$self->throw('error_on_evaluate', $error)->error; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
23
|
|
|
|
|
110
|
return $self->stash(evaluation => [ |
99
|
|
|
|
|
|
|
$regexp, |
100
|
|
|
|
|
|
|
$string, |
101
|
|
|
|
|
|
|
$captures, |
102
|
|
|
|
|
|
|
@matches, |
103
|
|
|
|
|
|
|
$initial, |
104
|
|
|
|
|
|
|
]); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub explain { |
108
|
14
|
|
|
14
|
1
|
468
|
my ($self) = @_; |
109
|
|
|
|
|
|
|
|
110
|
14
|
|
|
|
|
37
|
return $self->get; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub get { |
114
|
15
|
|
|
15
|
1
|
30
|
my ($self) = @_; |
115
|
|
|
|
|
|
|
|
116
|
15
|
|
66
|
|
|
54
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
117
|
|
|
|
|
|
|
|
118
|
15
|
|
|
|
|
105
|
return $evaluation->[1]; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub initial { |
122
|
5
|
|
|
5
|
1
|
13
|
my ($self) = @_; |
123
|
|
|
|
|
|
|
|
124
|
5
|
|
66
|
|
|
14
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
125
|
|
|
|
|
|
|
|
126
|
5
|
|
|
|
|
20
|
return $evaluation->[6]; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub last_match_end { |
130
|
5
|
|
|
5
|
1
|
11
|
my ($self) = @_; |
131
|
|
|
|
|
|
|
|
132
|
5
|
|
66
|
|
|
14
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
133
|
|
|
|
|
|
|
|
134
|
5
|
|
|
|
|
15
|
return $evaluation->[4]; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub last_match_start { |
138
|
5
|
|
|
5
|
1
|
10
|
my ($self) = @_; |
139
|
|
|
|
|
|
|
|
140
|
5
|
|
66
|
|
|
16
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
141
|
|
|
|
|
|
|
|
142
|
5
|
|
|
|
|
17
|
return $evaluation->[3]; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub matched { |
146
|
1
|
|
|
1
|
1
|
4
|
my ($self) = @_; |
147
|
|
|
|
|
|
|
|
148
|
1
|
|
33
|
|
|
5
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
|
|
11
|
my $string = $self->initial; |
151
|
1
|
|
|
|
|
8
|
my $last_match_start = $self->last_match_start; |
152
|
1
|
|
|
|
|
5
|
my $last_match_end = $self->last_match_end; |
153
|
|
|
|
|
|
|
|
154
|
1
|
|
50
|
|
|
4
|
my $start = $last_match_start->[0] || 0; |
155
|
1
|
|
50
|
|
|
7
|
my $end = $last_match_end->[0] || 0; |
156
|
|
|
|
|
|
|
|
157
|
1
|
|
|
|
|
9
|
return substr $string, $start, $end - $start; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub named_captures { |
161
|
2
|
|
|
2
|
1
|
9
|
my ($self) = @_; |
162
|
|
|
|
|
|
|
|
163
|
2
|
|
33
|
|
|
8
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
164
|
|
|
|
|
|
|
|
165
|
2
|
|
|
|
|
14
|
return $evaluation->[5]; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub prematched { |
169
|
1
|
|
|
1
|
1
|
6
|
my ($self) = @_; |
170
|
|
|
|
|
|
|
|
171
|
1
|
|
33
|
|
|
4
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
172
|
|
|
|
|
|
|
|
173
|
1
|
|
|
|
|
7
|
my $string = $self->initial; |
174
|
1
|
|
|
|
|
7
|
my $last_match_start = $self->last_match_start; |
175
|
1
|
|
|
|
|
7
|
my $last_match_end = $self->last_match_end; |
176
|
|
|
|
|
|
|
|
177
|
1
|
|
50
|
|
|
6
|
my $start = $last_match_start->[0] || 0; |
178
|
1
|
|
50
|
|
|
4
|
my $end = $last_match_end->[0] || 0; |
179
|
|
|
|
|
|
|
|
180
|
1
|
|
|
|
|
6
|
return substr $string, 0, $start; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub postmatched { |
184
|
1
|
|
|
1
|
1
|
3
|
my ($self) = @_; |
185
|
|
|
|
|
|
|
|
186
|
1
|
|
33
|
|
|
5
|
my $evaluation = $self->stash('evaluation') || $self->evaluate; |
187
|
|
|
|
|
|
|
|
188
|
1
|
|
|
|
|
4
|
my $string = $self->initial; |
189
|
1
|
|
|
|
|
3
|
my $last_match_start = $self->last_match_start; |
190
|
1
|
|
|
|
|
4
|
my $last_match_end = $self->last_match_end; |
191
|
|
|
|
|
|
|
|
192
|
1
|
|
50
|
|
|
4
|
my $start = $last_match_start->[0] || 0; |
193
|
1
|
|
50
|
|
|
4
|
my $end = $last_match_end->[0] || 0; |
194
|
|
|
|
|
|
|
|
195
|
1
|
|
|
|
|
7
|
return substr $string, $end; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub set { |
199
|
1
|
|
|
1
|
1
|
6
|
my ($self, $string) = @_; |
200
|
|
|
|
|
|
|
|
201
|
1
|
|
|
|
|
5
|
$self->string($string); |
202
|
|
|
|
|
|
|
|
203
|
1
|
|
|
|
|
4
|
my $evaluation = $self->evaluate; |
204
|
|
|
|
|
|
|
|
205
|
1
|
|
|
|
|
8
|
return $evaluation->[1]; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# ERRORS |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub error_on_evaluate { |
211
|
2
|
|
|
2
|
1
|
7
|
my ($self, $error) = @_; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
return { |
214
|
2
|
|
|
|
|
9
|
name => 'on.evaluate', |
215
|
|
|
|
|
|
|
message => $error, |
216
|
|
|
|
|
|
|
}; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 NAME |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Venus::Replace - Replace Class |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 ABSTRACT |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Replace Class for Perl 5 |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 SYNOPSIS |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
package main; |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
use Venus::Replace; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
my $replace = Venus::Replace->new( |
242
|
|
|
|
|
|
|
string => 'hello world', |
243
|
|
|
|
|
|
|
regexp => '(world)', |
244
|
|
|
|
|
|
|
substr => 'universe', |
245
|
|
|
|
|
|
|
); |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
# $replace->captures; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 DESCRIPTION |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
This package provides methods for manipulating regexp replacement data. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=cut |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
This package has the following attributes: |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head2 flags |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
flags(Str) |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This attribute is read-write, accepts C<(Str)> values, is optional, and defaults to C<''>. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head2 regexp |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
regexp(Regexp) |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
This attribute is read-write, accepts C<(Regexp)> values, is optional, and defaults to C. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=cut |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head2 string |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
string(Str) |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
This attribute is read-write, accepts C<(Str)> values, is optional, and defaults to C<''>. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=cut |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head2 substr |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
substr(Str) |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
This attribute is read-write, accepts C<(Str)> values, is optional, and defaults to C<''>. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=cut |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 INHERITS |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
This package inherits behaviors from: |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
L |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=cut |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head1 INTEGRATES |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
This package integrates behaviors from: |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
L |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
L |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=cut |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=head1 METHODS |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
This package provides the following methods: |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=cut |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=head2 captures |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
captures() (ArrayRef) |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
The captures method returns the capture groups from the result object which |
324
|
|
|
|
|
|
|
contains information about the results of the regular expression operation. |
325
|
|
|
|
|
|
|
This method can return a list of values in list-context. |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
I> |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=over 4 |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=item captures example 1 |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
# given: synopsis; |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
my $captures = $replace->captures; |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# ["world"] |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=back |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=cut |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
=head2 count |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
count() (Num) |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
The count method returns the number of match occurrences from the result object |
348
|
|
|
|
|
|
|
which contains information about the results of the regular expression |
349
|
|
|
|
|
|
|
operation. |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
I> |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=over 4 |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=item count example 1 |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# given: synopsis; |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
my $count = $replace->count; |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# 1 |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
=back |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
=cut |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
=head2 evaluate |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
evaluate() (ArrayRef) |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
The evaluate method performs the regular expression operation and returns an |
372
|
|
|
|
|
|
|
arrayref representation of the results. |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
I> |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=over 4 |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
=item evaluate example 1 |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
# given: synopsis; |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
my $evaluate = $replace->evaluate; |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
# [ |
385
|
|
|
|
|
|
|
# "(world)", |
386
|
|
|
|
|
|
|
# "hello universe", |
387
|
|
|
|
|
|
|
# 1, |
388
|
|
|
|
|
|
|
# [6, 6], |
389
|
|
|
|
|
|
|
# [11, 11], |
390
|
|
|
|
|
|
|
# {}, |
391
|
|
|
|
|
|
|
# "hello world", |
392
|
|
|
|
|
|
|
# ] |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=back |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=over 4 |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
=item evaluate example 2 |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
package main; |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
use Venus::Replace; |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
my $replace = Venus::Replace->new( |
405
|
|
|
|
|
|
|
string => 'hello world', |
406
|
|
|
|
|
|
|
regexp => 'world)(', |
407
|
|
|
|
|
|
|
substr => 'universe', |
408
|
|
|
|
|
|
|
); |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
my $evaluate = $replace->evaluate; |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
# Exception! (isa Venus::Replace::Error) (see error_on_evaluate) |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
=back |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=cut |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=head2 explain |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
explain() (Str) |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
The explain method returns the subject of the regular expression operation and |
423
|
|
|
|
|
|
|
is used in stringification operations. |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
I> |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=over 4 |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=item explain example 1 |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
# given: synopsis; |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
my $explain = $replace->explain; |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
# "hello universe" |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
=back |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
=cut |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
=head2 get |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
get() (Str) |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
The get method returns the subject of the regular expression operation. |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
I> |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
=over 4 |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
=item get example 1 |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
# given: synopsis; |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
my $get = $replace->get; |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
# "hello universe" |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=back |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
=cut |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
=head2 initial |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
initial() (Str) |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
The initial method returns the unaltered string from the result object which |
468
|
|
|
|
|
|
|
contains information about the results of the regular expression operation. |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
I> |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
=over 4 |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
=item initial example 1 |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
# given: synopsis; |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
my $initial = $replace->initial; |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
# "hello world" |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
=back |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
=cut |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
=head2 last_match_end |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
last_match_end() (Maybe[ArrayRef[Int]]) |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
The last_match_end method returns an array of offset positions into the string |
491
|
|
|
|
|
|
|
where the capture(s) stopped matching from the result object which contains |
492
|
|
|
|
|
|
|
information about the results of the regular expression operation. |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
I> |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
=over 4 |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
=item last_match_end example 1 |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
# given: synopsis; |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
my $last_match_end = $replace->last_match_end; |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
# [11, 11] |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
=back |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
=cut |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=head2 last_match_start |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
last_match_start() (Maybe[ArrayRef[Int]]) |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
The last_match_start method returns an array of offset positions into the |
515
|
|
|
|
|
|
|
string where the capture(s) matched from the result object which contains |
516
|
|
|
|
|
|
|
information about the results of the regular expression operation. |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
I> |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=over 4 |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
=item last_match_start example 1 |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
# given: synopsis; |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
my $last_match_start = $replace->last_match_start; |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
# [6, 6] |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
=back |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=cut |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
=head2 matched |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
matched() (Maybe[Str]) |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
The matched method returns the portion of the string that matched from the |
539
|
|
|
|
|
|
|
result object which contains information about the results of the regular |
540
|
|
|
|
|
|
|
expression operation. |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
I> |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=over 4 |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
=item matched example 1 |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
# given: synopsis; |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
my $matched = $replace->matched; |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
# "world" |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
=back |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
=cut |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
=head2 named_captures |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
named_captures() (HashRef) |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
The named_captures method returns a hash containing the requested named regular |
563
|
|
|
|
|
|
|
expressions and captured string pairs from the result object which contains |
564
|
|
|
|
|
|
|
information about the results of the regular expression operation. |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
I> |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
=over 4 |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
=item named_captures example 1 |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
# given: synopsis; |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
my $named_captures = $replace->named_captures; |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
# {} |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=back |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
=over 4 |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
=item named_captures example 2 |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
package main; |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
use Venus::Replace; |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
my $replace = Venus::Replace->new( |
589
|
|
|
|
|
|
|
string => 'hello world', |
590
|
|
|
|
|
|
|
regexp => '(?world)', |
591
|
|
|
|
|
|
|
substr => 'universe', |
592
|
|
|
|
|
|
|
); |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
my $named_captures = $replace->named_captures; |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
# { locale => ["world"] } |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
=back |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
=cut |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=head2 postmatched |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
postmatched() (Maybe[Str) |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
The postmatched method returns the portion of the string after the regular |
607
|
|
|
|
|
|
|
expression matched from the result object which contains information about the |
608
|
|
|
|
|
|
|
results of the regular expression operation. |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
I> |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
=over 4 |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
=item postmatched example 1 |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
# given: synopsis; |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
my $postmatched = $replace->postmatched; |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
# "" |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=back |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
=cut |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
=head2 prematched |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
prematched() (Maybe[Str) |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
The prematched method returns the portion of the string before the regular |
631
|
|
|
|
|
|
|
expression matched from the result object which contains information about the |
632
|
|
|
|
|
|
|
results of the regular expression operation. |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
I> |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
=over 4 |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
=item prematched example 1 |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
# given: synopsis; |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
my $prematched = $replace->prematched; |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
# "hello " |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
=back |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
=cut |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
=head2 set |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
set(Str $data) (Str) |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
The set method sets the subject of the regular expression operation. |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
I> |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
=over 4 |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
=item set example 1 |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
# given: synopsis; |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
my $set = $replace->set('hello universe'); |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
# "hello universe" |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
=back |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
=cut |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
=head1 ERRORS |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
This package may raise the following errors: |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
=cut |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
=over 4 |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
=item error: C |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
This package may raise an error_on_evaluate exception. |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
B |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
# given: synopsis; |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
my @args = ('Exception!'); |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
my $error = $replace->throw('error_on_evaluate', @args)->catch('error'); |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
# my $name = $error->name; |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
# "on_evaluate" |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
# my $message = $error->message; |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
# "Exception!" |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
=back |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
=head1 OPERATORS |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
This package overloads the following operators: |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
=cut |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
=over 4 |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
=item operation: C<(.)> |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
This package overloads the C<.> operator. |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
B |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
# given: synopsis; |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
my $result = $replace . ', welcome'; |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
# "hello universe, welcome" |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
=back |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
=over 4 |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
=item operation: C<(eq)> |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
This package overloads the C operator. |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
B |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
# given: synopsis; |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
my $result = $replace eq 'hello universe'; |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
# 1 |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
=back |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
=over 4 |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
=item operation: C<(ne)> |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
This package overloads the C operator. |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
B |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
# given: synopsis; |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
my $result = $replace ne 'Hello universe'; |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
# 1 |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
=back |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
=over 4 |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
=item operation: C<(qr)> |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
This package overloads the C operator. |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
B |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
# given: synopsis; |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
my $result = 'hello universe, welcome' =~ qr/$replace/; |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
# 1 |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
=back |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
=over 4 |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
=item operation: C<("")> |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
This package overloads the C<""> operator. |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
B |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
# given: synopsis; |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
my $result = "$replace"; |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
# "hello universe" |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
B |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
# given: synopsis; |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
my $result = "$replace, $replace"; |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
# "hello universe, hello universe" |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
=back |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
=over 4 |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
=item operation: C<(~~)> |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
This package overloads the C<~~> operator. |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
B |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
# given: synopsis; |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
my $result = $replace ~~ 'hello universe'; |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
# 1 |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
=back |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
=head1 AUTHORS |
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
Awncorp, C |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
=cut |
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
=head1 LICENSE |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
Copyright (C) 2000, Al Newkirk. |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
823
|
|
|
|
|
|
|
the terms of the Apache license version 2.0. |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
=cut |