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