line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DDG::Block::Regexp; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:DDG'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Block implementation to handle regexp based plugins |
4
|
|
|
|
|
|
|
$DDG::Block::Regexp::VERSION = '1016'; |
5
|
9
|
|
|
9
|
|
1459
|
use Moo; |
|
9
|
|
|
|
|
11
|
|
|
9
|
|
|
|
|
46
|
|
6
|
|
|
|
|
|
|
with qw( DDG::Block ); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub parse_trigger { |
10
|
3
|
|
|
3
|
1
|
4
|
my ( $self, $triggers ) = @_; |
11
|
3
|
|
|
|
|
4
|
for my $key (keys %{$triggers}) { |
|
3
|
|
|
|
|
9
|
|
12
|
|
|
|
|
|
|
my @triggers = map { |
13
|
5
|
50
|
|
|
|
15
|
ref $_ eq 'Regexp' ? $_ : qr{$_}; |
14
|
3
|
|
|
|
|
4
|
} @{$triggers->{$key}}; |
|
3
|
|
|
|
|
6
|
|
15
|
3
|
|
|
|
|
9
|
$triggers->{$key} = \@triggers; |
16
|
|
|
|
|
|
|
} |
17
|
3
|
|
|
|
|
6
|
return $triggers; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub request { |
21
|
|
|
|
|
|
|
my ( $self, $request ) = @_; |
22
|
|
|
|
|
|
|
my @results; |
23
|
|
|
|
|
|
|
for (@{$self->plugin_objs}) { |
24
|
|
|
|
|
|
|
my $triggers = $_->[0]; |
25
|
|
|
|
|
|
|
my $plugin = $_->[1]; |
26
|
|
|
|
|
|
|
for my $trigger (@{$triggers}) { |
27
|
|
|
|
|
|
|
for my $attr (keys %{$trigger}) { |
28
|
|
|
|
|
|
|
for (@{$trigger->{$attr}}) { |
29
|
|
|
|
|
|
|
if ( my @matches = $request->$attr =~ m/$_/ ) { |
30
|
|
|
|
|
|
|
push @results, $self->handle_request_matches($plugin,$request,@matches); |
31
|
|
|
|
|
|
|
return @results if $self->return_one && @results; |
32
|
|
|
|
|
|
|
} else { |
33
|
|
|
|
|
|
|
$self->trace("No match with",ref $plugin); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
return @results; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |