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