line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Regexp::VerbalExpressions; |
2
|
4
|
|
|
4
|
|
88775
|
use 5.008005; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
170
|
|
3
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
133
|
|
4
|
4
|
|
|
4
|
|
31
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
167
|
|
5
|
4
|
|
|
4
|
|
3286
|
use parent qw/Exporter/; |
|
4
|
|
|
|
|
5383
|
|
|
4
|
|
|
|
|
21
|
|
6
|
4
|
|
|
4
|
|
5648
|
use overload fallback => 1, q{""} => \&source, 'qr' => \®ex; |
|
4
|
|
|
|
|
3400
|
|
|
4
|
|
|
|
|
40
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw/verex/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
38
|
|
|
38
|
0
|
64
|
my $class = shift; |
14
|
38
|
|
|
|
|
367
|
return bless { |
15
|
|
|
|
|
|
|
s => '', |
16
|
|
|
|
|
|
|
modifiers => { |
17
|
|
|
|
|
|
|
i => 0, |
18
|
|
|
|
|
|
|
m => 0, |
19
|
|
|
|
|
|
|
s => 0, |
20
|
|
|
|
|
|
|
x => 0, |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
global_matching => 0, |
23
|
|
|
|
|
|
|
}, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
38
|
|
|
38
|
0
|
57153
|
sub verex { __PACKAGE__->new() } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub add { |
29
|
118
|
|
|
118
|
1
|
174
|
my ($self, $value) = @_; |
30
|
118
|
|
|
|
|
312
|
$self->{s} .= $value; |
31
|
118
|
|
|
|
|
921
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub regex { |
35
|
36
|
|
|
36
|
0
|
46
|
my $self = shift; |
36
|
36
|
|
|
|
|
58
|
my $enabled = my $disabled = ''; |
37
|
36
|
|
|
|
|
46
|
for my $modifier (sort keys %{$self->{modifiers}}) { |
|
36
|
|
|
|
|
208
|
|
38
|
144
|
100
|
|
|
|
275
|
if ($self->{modifiers}{$modifier}) { |
39
|
5
|
|
|
|
|
9
|
$enabled .= $modifier; |
40
|
|
|
|
|
|
|
} else { |
41
|
139
|
|
|
|
|
207
|
$disabled .= $modifier; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
36
|
|
|
|
|
1547
|
return qr/(?$enabled-$disabled:$self->{s})/; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
*compile = \®ex; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub source { |
49
|
1
|
|
|
1
|
0
|
300
|
my $self = shift; |
50
|
1
|
|
|
|
|
13
|
return $self->{s}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
*raw = *value = \&source; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub find { |
55
|
29
|
|
|
29
|
1
|
43
|
my ($self, $value) = @_; |
56
|
29
|
|
|
|
|
88
|
return $self->add('(?:' . quotemeta($value) . ')'); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
*then = \&find; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub start_of_line { |
61
|
31
|
|
|
31
|
1
|
44
|
my $self = shift; |
62
|
31
|
|
|
|
|
73
|
return $self->add('^'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub end_of_line { |
66
|
17
|
|
|
17
|
1
|
30
|
my $self = shift; |
67
|
17
|
|
|
|
|
34
|
return $self->add('$'); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub maybe { |
71
|
5
|
|
|
5
|
1
|
10
|
my ($self, $value) = @_; |
72
|
5
|
|
|
|
|
16
|
return $self->add('(?:' . quotemeta($value) . ')?'); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub anything { |
76
|
10
|
|
|
10
|
1
|
15
|
my $self = shift; |
77
|
10
|
|
|
|
|
21
|
return $self->add('(?:.*)'); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub anything_but { |
81
|
2
|
|
|
2
|
1
|
6
|
my ($self, $value) = @_; |
82
|
2
|
|
|
|
|
31
|
return $self->add('(?:[^' . quotemeta($value) . ']*)'); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub something { |
86
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
87
|
1
|
|
|
|
|
4
|
return $self->add('(?:.+)'); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub something_but { |
91
|
1
|
|
|
1
|
0
|
3
|
my ($self, $value) = @_; |
92
|
1
|
|
|
|
|
6
|
return $self->add('(?:[^' . quotemeta($value) . ']+)'); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub line_break { |
96
|
5
|
|
|
5
|
1
|
25
|
my $self = shift; |
97
|
5
|
|
|
|
|
11
|
return $self->add('(?:\n|(?:\r\n))'); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
*br = \&line_break; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub tab { |
102
|
4
|
|
|
4
|
1
|
7
|
my $self = shift; |
103
|
4
|
|
|
|
|
13
|
return $self->add('\t'); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub word { |
107
|
6
|
|
|
6
|
1
|
8
|
my $self = shift; |
108
|
6
|
|
|
|
|
13
|
return $self->add('\w+'); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub any { |
112
|
2
|
|
|
2
|
1
|
5
|
my ($self, $value) = @_; |
113
|
2
|
|
|
|
|
9
|
return $self->add('[' . quotemeta($value) . ']'); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
*any_of = \&any; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub range { |
118
|
2
|
|
|
2
|
1
|
8
|
my ($self, @args) = @_; |
119
|
2
|
|
|
|
|
5
|
my $value = '['; |
120
|
2
|
|
|
|
|
10
|
for (my $i = 0; $i < @args; $i += 2) { |
121
|
3
|
|
|
|
|
16
|
$value .= quotemeta($args[$i]) . '-' . quotemeta($args[$i + 1]); |
122
|
|
|
|
|
|
|
} |
123
|
2
|
|
|
|
|
3
|
$value .= ']'; |
124
|
2
|
|
|
|
|
7
|
return $self->add($value); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub multiple { |
128
|
0
|
|
|
0
|
1
|
0
|
my ($self, $value) = @_; |
129
|
0
|
|
|
|
|
0
|
$self->add(quotemeta($value) . '+'); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub or { |
133
|
2
|
|
|
2
|
1
|
5
|
my ($self, $value) = @_; |
134
|
2
|
|
|
|
|
6
|
$self->add('|'); |
135
|
2
|
100
|
|
|
|
12
|
return defined $value ? $self->find($value) : $self; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
*alternatively = \∨ |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub replace { |
140
|
3
|
|
|
3
|
1
|
6
|
my ($self, $source, $value) = @_; |
141
|
3
|
|
|
|
|
9
|
my $re = $self->regex; |
142
|
3
|
100
|
|
|
|
11
|
if ($self->{global_matching}) { |
143
|
2
|
|
|
|
|
17
|
$source =~ s/$re/$value/g; |
144
|
|
|
|
|
|
|
} else { |
145
|
1
|
|
|
|
|
10
|
$source =~ s/$re/$value/; |
146
|
|
|
|
|
|
|
} |
147
|
3
|
|
|
|
|
24
|
return $source; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _build_modifier { |
151
|
5
|
|
|
5
|
|
8
|
my ($self, $modifier, $value) = @_; |
152
|
5
|
100
|
|
|
|
11
|
if (!defined $value) { |
153
|
|
|
|
|
|
|
# XXX verex->with_any_case; |
154
|
2
|
|
|
|
|
4
|
$self->{modifiers}{$modifier} = 1; |
155
|
|
|
|
|
|
|
} else { |
156
|
3
|
50
|
|
|
|
14
|
$self->{modifiers}{$modifier} = $value ? 1 : 0; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub with_any_case { |
161
|
3
|
|
|
3
|
1
|
5
|
my ($self, $value) = @_; |
162
|
3
|
|
|
|
|
12
|
$self->_build_modifier(i => $value); |
163
|
3
|
|
|
|
|
7
|
return $self; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub stop_at_first { |
167
|
2
|
|
|
2
|
1
|
4
|
my ($self, $value) = @_; |
168
|
2
|
50
|
|
|
|
6
|
if (!defined $value) { |
169
|
0
|
|
|
|
|
0
|
$self->{global_matching} = 1; |
170
|
|
|
|
|
|
|
} else { |
171
|
2
|
50
|
|
|
|
7
|
$self->{global_matching} = $value ? 1 : 0; |
172
|
|
|
|
|
|
|
} |
173
|
2
|
|
|
|
|
8
|
return $self; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub search_one_line { |
177
|
2
|
|
|
2
|
1
|
4
|
my ($self, $value) = @_; |
178
|
2
|
|
|
|
|
6
|
$self->_build_modifier(m => $value); |
179
|
2
|
|
|
|
|
6
|
return $self; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |
183
|
|
|
|
|
|
|
__END__ |