Venus::Replace - Replace Class
Replace Class for Perl 5
package main; use Venus::Replace; my $replace = Venus::Replace->new( string => 'hello world', regexp => '(world)', substr => 'universe', ); # $replace->captures;
This package provides methods for manipulating regexp replacement data.
This package has the following attributes:
flags(Str)
This attribute is read-write, accepts (Str) values, is optional, and defaults to ''.
(Str)
''
regexp(Regexp)
This attribute is read-write, accepts (Regexp) values, is optional, and defaults to qr//.
(Regexp)
qr//
string(Str)
substr(Str)
This package inherits behaviors from:
Venus::Kind::Utility
This package integrates behaviors from:
Venus::Role::Explainable
Venus::Role::Stashable
This package provides the following methods:
captures() (arrayref)
The captures method returns the capture groups from the result object which contains information about the results of the regular expression operation. This method can return a list of values in list-context.
Since 0.01
0.01
# given: synopsis; my $captures = $replace->captures; # ["world"]
count() (number)
The count method returns the number of match occurrences from the result object which contains information about the results of the regular expression operation.
# given: synopsis; my $count = $replace->count; # 1
evaluate() (arrayref)
The evaluate method performs the regular expression operation and returns an arrayref representation of the results.
# given: synopsis; my $evaluate = $replace->evaluate; # [ # "(world)", # "hello universe", # 1, # [6, 6], # [11, 11], # {}, # "hello world", # ]
package main; use Venus::Replace; my $replace = Venus::Replace->new( string => 'hello world', regexp => 'world)(', substr => 'universe', ); my $evaluate = $replace->evaluate; # Exception! (isa Venus::Replace::Error) (see error_on_evaluate)
explain() (string)
The explain method returns the subject of the regular expression operation and is used in stringification operations.
# given: synopsis; my $explain = $replace->explain; # "hello universe"
get() (string)
The get method returns the subject of the regular expression operation.
# given: synopsis; my $get = $replace->get; # "hello universe"
initial() (string)
The initial method returns the unaltered string from the result object which contains information about the results of the regular expression operation.
# given: synopsis; my $initial = $replace->initial; # "hello world"
last_match_end() (maybe[within[arrayref, number]])
The last_match_end method returns an array of offset positions into the string where the capture(s) stopped matching from the result object which contains information about the results of the regular expression operation.
# given: synopsis; my $last_match_end = $replace->last_match_end; # [11, 11]
last_match_start() (maybe[within[arrayref, number]])
The last_match_start method returns an array of offset positions into the string where the capture(s) matched from the result object which contains information about the results of the regular expression operation.
# given: synopsis; my $last_match_start = $replace->last_match_start; # [6, 6]
matched() (maybe[string])
The matched method returns the portion of the string that matched from the result object which contains information about the results of the regular expression operation.
# given: synopsis; my $matched = $replace->matched; # "world"
named_captures() (hashref)
The named_captures method returns a hash containing the requested named regular expressions and captured string pairs from the result object which contains information about the results of the regular expression operation.
# given: synopsis; my $named_captures = $replace->named_captures; # {}
package main; use Venus::Replace; my $replace = Venus::Replace->new( string => 'hello world', regexp => '(?<locale>world)', substr => 'universe', ); my $named_captures = $replace->named_captures; # { locale => ["world"] }
postmatched() (Maybe[string])
The postmatched method returns the portion of the string after the regular expression matched from the result object which contains information about the results of the regular expression operation.
# given: synopsis; my $postmatched = $replace->postmatched; # ""
prematched() (Maybe[string])
The prematched method returns the portion of the string before the regular expression matched from the result object which contains information about the results of the regular expression operation.
# given: synopsis; my $prematched = $replace->prematched; # "hello "
set(string $data) (string)
The set method sets the subject of the regular expression operation.
# given: synopsis; my $set = $replace->set('hello universe'); # "hello universe"
This package may raise the following errors:
error_on_evaluate
This package may raise an error_on_evaluate exception.
example 1
# given: synopsis; my $input = { throw => 'error_on_evaluate', error => 'Exception!', }; my $error = $replace->catch('error', $input); # my $name = $error->name; # "on_evaluate" # my $message = $error->message; # "Exception!"
This package overloads the following operators:
("")
This package overloads the "" operator.
""
# given: synopsis; my $result = "$replace"; # "hello universe"
example 2
# given: synopsis; my $result = "$replace, $replace"; # "hello universe, hello universe"
(.)
This package overloads the . operator.
.
# given: synopsis; my $result = $replace . ', welcome'; # "hello universe, welcome"
(eq)
This package overloads the eq operator.
eq
# given: synopsis; my $result = $replace eq 'hello universe'; # 1
(ne)
This package overloads the ne operator.
ne
# given: synopsis; my $result = $replace ne 'Hello universe'; # 1
(qr)
This package overloads the qr operator.
qr
# given: synopsis; my $result = 'hello universe, welcome' =~ qr/$replace/; # 1
(~~)
This package overloads the ~~ operator.
~~
# given: synopsis; my $result = $replace ~~ 'hello universe'; # 1
Awncorp, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2000, Awncorp, awncorp@cpan.org.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.