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