line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DDG::Block::Blockable::Triggers; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:DDG'; |
3
|
|
|
|
|
|
|
# ABSTRACT: A package which reflects the triggers of a blockable plugin. |
4
|
|
|
|
|
|
|
$DDG::Block::Blockable::Triggers::VERSION = '1017'; |
5
|
11
|
|
|
11
|
|
65
|
use Moo; |
|
11
|
|
|
|
|
26
|
|
|
11
|
|
|
|
|
67
|
|
6
|
11
|
|
|
11
|
|
3586
|
use Carp; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
4916
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @words_types = qw( |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
start |
11
|
|
|
|
|
|
|
end |
12
|
|
|
|
|
|
|
startend |
13
|
|
|
|
|
|
|
any |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @regexp_types = qw( |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
query_raw |
20
|
|
|
|
|
|
|
query |
21
|
|
|
|
|
|
|
query_lc |
22
|
|
|
|
|
|
|
query_nowhitespace |
23
|
|
|
|
|
|
|
query_nowhitespace_nodash |
24
|
|
|
|
|
|
|
query_clean |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $default_regexp_type = 'query_raw'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has triggers => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
default => sub {{}}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has block_type => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
predicate => 'has_block_type', |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
35
|
|
|
35
|
0
|
171
|
sub get { shift->triggers } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add { |
43
|
47
|
|
|
47
|
0
|
143
|
my ( $self, @args ) = @_; |
44
|
47
|
|
|
|
|
81
|
my %params; |
45
|
47
|
100
|
|
|
|
192
|
if (ref $args[0] eq 'CODE') { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
46
|
2
|
|
|
|
|
6
|
%params = $args[0]->(); |
47
|
|
|
|
|
|
|
} elsif (ref $args[0] eq 'HASH') { |
48
|
0
|
|
|
|
|
0
|
%params = %{$args[0]}; |
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
} elsif (ref $args[0] eq 'Regexp') { |
50
|
7
|
|
|
|
|
23
|
%params = ( $default_regexp_type => [@args] ); |
51
|
|
|
|
|
|
|
} else { |
52
|
38
|
100
|
|
|
|
93
|
if (scalar @args > 2) { |
53
|
5
|
|
|
|
|
25
|
%params = ( $args[0] => [@args[1..(scalar @args-1)]] ); |
54
|
|
|
|
|
|
|
} else { |
55
|
33
|
|
|
|
|
94
|
%params = ( $args[0] => $args[1] ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
47
|
|
|
|
|
139
|
for (keys %params) { |
59
|
47
|
|
|
|
|
79
|
my $trigger_type = $_; |
60
|
47
|
100
|
|
|
|
133
|
my @triggers = ref $params{$trigger_type} eq 'ARRAY' ? @{$params{$trigger_type}} : ($params{$trigger_type}); |
|
14
|
|
|
|
|
33
|
|
61
|
47
|
50
|
|
|
|
114
|
croak 'no trigger values given' unless @triggers; |
62
|
47
|
|
|
|
|
115
|
$self->add_triggers($trigger_type, @triggers); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub add_triggers { |
67
|
47
|
|
|
47
|
0
|
101
|
my ( $self, $trigger_type, @add_triggers ) = @_; |
68
|
47
|
|
|
|
|
71
|
my @triggers; |
69
|
47
|
|
|
|
|
86
|
for (@add_triggers) { |
70
|
57
|
100
|
|
|
|
149
|
push @triggers, ref $_ eq 'CODE' ? $_->() : $_; |
71
|
|
|
|
|
|
|
} |
72
|
47
|
100
|
|
|
|
98
|
if (grep { $_ eq $trigger_type } @words_types) { |
|
188
|
50
|
|
|
|
388
|
|
73
|
39
|
50
|
66
|
|
|
180
|
croak "You can't add trigger types of the other block-type" if $self->has_block_type && $self->block_type ne 'Words'; |
74
|
39
|
|
|
|
|
128
|
$self->block_type('Words'); |
75
|
48
|
|
|
|
|
92
|
} elsif (grep { $_ eq $trigger_type } @regexp_types) { |
76
|
8
|
100
|
100
|
|
|
131
|
croak "You can't add trigger types of the other block-type" if $self->has_block_type && $self->block_type ne 'Regexp'; |
77
|
7
|
|
|
|
|
22
|
$self->block_type('Regexp'); |
78
|
7
|
|
|
|
|
19
|
for (@triggers) { |
79
|
9
|
50
|
|
|
|
25
|
croak 'You may only give compiled regexps to regexp trigger types (like qr/reverse (.*)/i)' unless ref $_ eq 'Regexp'; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
46
|
50
|
|
|
|
127
|
croak "your trigger_type '".$trigger_type."' is unknown" unless $self->has_block_type; |
83
|
46
|
100
|
|
|
|
194
|
$self->triggers->{$_} = [] unless defined $self->triggers->{$_}; |
84
|
46
|
|
|
|
|
81
|
push @{$self->triggers->{$_}}, @triggers; |
|
46
|
|
|
|
|
232
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |