| 1 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package HTML::FormFu::Filter::Regex; | ||||||||||
| 4 | 10 | $HTML::FormFu::Filter::Regex::VERSION = '2.06'; | |||||||||
| 5 | # ABSTRACT: regexp-based match/replace filter | ||||||||||
| 6 | |||||||||||
| 7 | 10 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 10 | ▶ | use MooseX::Attribute::Chained; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 10 | extends 'HTML::FormFu::Filter'; | |||||||||
| 10 | |||||||||||
| 11 | 10 | ▶ | use HTML::FormFu::Constants qw( $EMPTY_STR ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 10 | has match => ( is => 'rw', traits => ['Chained'] ); | |||||||||
| 14 | 10 | has replace => ( is => 'rw', traits => ['Chained'] ); | |||||||||
| 15 | 10 | has eval => ( is => 'rw', traits => ['Chained'] ); | |||||||||
| 16 | |||||||||||
| 17 | sub filter { | ||||||||||
| 18 | 12 | ▶ | my ( $self, $value ) = @_; | ||||||||
|
Subroutine
filter: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||
| 19 | |||||||||||
| 20 | 12 | ▶ | return if !defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | |||||||||||
| 22 | 12 | ▶ | my $match = defined $self->match ? $self->match : qr/./; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 12 | ▶ | my $replace = defined $self->replace ? $self->replace : $EMPTY_STR; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | 12 | ▶ | if ( $self->eval ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 4 | $value =~ s/$match/$replace/gee; | |||||||||
| 27 | } | ||||||||||
| 28 | else { | ||||||||||
| 29 | 8 | $value =~ s/$match/$replace/g; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 12 | return $value; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 10 | __PACKAGE__->meta->make_immutable; | |||||||||
| 36 | |||||||||||
| 37 | 10 | 1; | |||||||||
| 38 | |||||||||||
| 39 | __END__ | ||||||||||
| 40 | |||||||||||
| 41 | =pod | ||||||||||
| 42 | |||||||||||
| 43 | =encoding UTF-8 | ||||||||||
| 44 | |||||||||||
| 45 | =head1 NAME | ||||||||||
| 46 | |||||||||||
| 47 | HTML::FormFu::Filter::Regex - regexp-based match/replace filter | ||||||||||
| 48 | |||||||||||
| 49 | =head1 VERSION | ||||||||||
| 50 | |||||||||||
| 51 | version 2.06 | ||||||||||
| 52 | |||||||||||
| 53 | =head1 SYNOPSIS | ||||||||||
| 54 | |||||||||||
| 55 | The following filter would turn C<1234-5678> into C<****-****>. | ||||||||||
| 56 | |||||||||||
| 57 | type: Regex | ||||||||||
| 58 | match: \d | ||||||||||
| 59 | replace: * | ||||||||||
| 60 | |||||||||||
| 61 | =head1 DESCRIPTION | ||||||||||
| 62 | |||||||||||
| 63 | Regular expression-based match / replace filter. | ||||||||||
| 64 | |||||||||||
| 65 | =head1 METHODS | ||||||||||
| 66 | |||||||||||
| 67 | =head2 match | ||||||||||
| 68 | |||||||||||
| 69 | A regex object or string to be used in the "left-hand side" of a C<s///g> | ||||||||||
| 70 | regular expression. | ||||||||||
| 71 | |||||||||||
| 72 | Default Value: qr/./ | ||||||||||
| 73 | |||||||||||
| 74 | =head2 replace | ||||||||||
| 75 | |||||||||||
| 76 | A string to be used in the "right-hand side" of a C<s///g> regular | ||||||||||
| 77 | expression. The string will replace every occurrence of L</match>. | ||||||||||
| 78 | |||||||||||
| 79 | Default Value: '' | ||||||||||
| 80 | |||||||||||
| 81 | =head2 eval | ||||||||||
| 82 | |||||||||||
| 83 | Arguments: $bool | ||||||||||
| 84 | |||||||||||
| 85 | If true, the regex modifier C</e> is used, so that the contents of the | ||||||||||
| 86 | L</replace> string are C<eval>'d. | ||||||||||
| 87 | |||||||||||
| 88 | This allows the use of variables such as C<$1> or any other perl expression. | ||||||||||
| 89 | |||||||||||
| 90 | =head1 AUTHOR | ||||||||||
| 91 | |||||||||||
| 92 | Carl Franks, C<cfranks@cpan.org> | ||||||||||
| 93 | |||||||||||
| 94 | =head1 LICENSE | ||||||||||
| 95 | |||||||||||
| 96 | This library is free software, you can redistribute it and/or modify it under | ||||||||||
| 97 | the same terms as Perl itself. | ||||||||||
| 98 | |||||||||||
| 99 | =head1 AUTHOR | ||||||||||
| 100 | |||||||||||
| 101 | Carl Franks <cpan@fireartist.com> | ||||||||||
| 102 | |||||||||||
| 103 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 104 | |||||||||||
| 105 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||
| 106 | |||||||||||
| 107 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 108 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||