| 1 | package DDG::Block::Regexp; | ||||||||||||||||||||||||||||
| 2 | 7 | our $AUTHORITY = 'cpan:DDG'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Block implementation to handle regexp based plugins | ||||||||||||||||||||||||||||
| 4 | 7 | $DDG::Block::Regexp::VERSION = '1017'; | |||||||||||||||||||||||||||
| 5 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | with qw( DDG::Block ); | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | sub parse_trigger { | ||||||||||||||||||||||||||||
| 10 | 3 | ▶ | my ( $self, $triggers ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse_trigger: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 3 | for my $key (keys %{$triggers}) { | |||||||||||||||||||||||||||
| 12 | my @triggers = map { | ||||||||||||||||||||||||||||
| 13 | 5 | ▶ | ref $_ eq 'Regexp' ? $_ : qr{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 3 | } @{$triggers->{$key}}; | |||||||||||||||||||||||||||
| 15 | 3 | $triggers->{$key} = \@triggers; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 3 | return $triggers; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub request { | ||||||||||||||||||||||||||||
| 21 | 21 | ▶ | my ( $self, $request ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
request: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 21 | my @results; | |||||||||||||||||||||||||||
| 23 | 21 | for (@{$self->plugin_objs}) { | |||||||||||||||||||||||||||
| 24 | 22 | my $triggers = $_->[0]; | |||||||||||||||||||||||||||
| 25 | 22 | my $plugin = $_->[1]; | |||||||||||||||||||||||||||
| 26 | 22 | for my $trigger (@{$triggers}) { | |||||||||||||||||||||||||||
| 27 | 22 | for my $attr (keys %{$trigger}) { | |||||||||||||||||||||||||||
| 28 | 22 | for (@{$trigger->{$attr}}) { | |||||||||||||||||||||||||||
| 29 | 23 | ▶ | if ( my @matches = $request->$attr =~ m/$_/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 4 | push @results, $self->handle_request_matches($plugin,$request,@matches); | |||||||||||||||||||||||||||
| 31 | 4 | ▶ | return @results if $self->return_one && @results; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->return_one and @results
MC/DC0%0/2
$self->return_one and @results
$self->return_one
@results
Truth table33%1/3
A and B
A= $self->return_oneB= @results
| |||||||||||||||||||||||||||||
| 32 | } else { | ||||||||||||||||||||||||||||
| 33 | 19 | $self->trace("No match with",ref $plugin); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 17 | return @results; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 7 | 1; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | __END__ | ||||||||||||||||||||||||||||