line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
10
|
|
|
10
|
|
3346
|
use strict; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
649
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Filter::Regex; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Filter::Regex::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: regexp-based match/replace filter |
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
1515
|
use Moose; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
70
|
|
8
|
10
|
|
|
10
|
|
67218
|
use MooseX::Attribute::Chained; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
435
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Filter'; |
10
|
|
|
|
|
|
|
|
11
|
10
|
|
|
10
|
|
62
|
use HTML::FormFu::Constants qw( $EMPTY_STR ); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
3392
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has match => ( is => 'rw', traits => ['Chained'] ); |
14
|
|
|
|
|
|
|
has replace => ( is => 'rw', traits => ['Chained'] ); |
15
|
|
|
|
|
|
|
has eval => ( is => 'rw', traits => ['Chained'] ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub filter { |
18
|
12
|
|
|
12
|
0
|
35
|
my ( $self, $value ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
12
|
50
|
|
|
|
48
|
return if !defined $value; |
21
|
|
|
|
|
|
|
|
22
|
12
|
50
|
|
|
|
340
|
my $match = defined $self->match ? $self->match : qr/./; |
23
|
12
|
100
|
|
|
|
362
|
my $replace = defined $self->replace ? $self->replace : $EMPTY_STR; |
24
|
|
|
|
|
|
|
|
25
|
12
|
100
|
|
|
|
413
|
if ( $self->eval ) { |
26
|
4
|
|
|
|
|
60
|
$value =~ s/$match/$replace/gee; |
|
3
|
|
|
|
|
194
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
8
|
|
|
|
|
109
|
$value =~ s/$match/$replace/g; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
12
|
|
|
|
|
59
|
return $value; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
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.07 |
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 |