line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::MechanicalTurk::FilterChain; |
2
|
19
|
|
|
19
|
|
20089
|
use strict; |
|
19
|
|
|
|
|
29
|
|
|
19
|
|
|
|
|
1958
|
|
3
|
19
|
|
|
19
|
|
1290
|
use warnings; |
|
19
|
|
|
|
|
1417
|
|
|
19
|
|
|
|
|
591
|
|
4
|
19
|
|
|
19
|
|
783
|
use Net::Amazon::MechanicalTurk::BaseObject; |
|
19
|
|
|
|
|
34
|
|
|
19
|
|
|
|
|
14771
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw{ Net::Amazon::MechanicalTurk::BaseObject }; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# This module is used for managing "around style" interceptors for your code. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Net::Amazon::MechanicalTurk::FilterChain->attributes(qw{ |
15
|
|
|
|
|
|
|
filters |
16
|
|
|
|
|
|
|
}); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub init { |
19
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
20
|
1
|
|
|
|
|
32
|
$self->setAttributes(@_); |
21
|
1
|
50
|
|
|
|
5
|
$self->filters([]) unless $self->filters; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub execute { |
25
|
7
|
|
|
7
|
0
|
59
|
my ($self, $code, @params) = @_; |
26
|
7
|
|
|
|
|
25
|
my $filters = $self->filters; |
27
|
7
|
100
|
|
|
|
13
|
if ($#{$filters} < 0) { |
|
7
|
|
|
|
|
24
|
|
28
|
|
|
|
|
|
|
# bypass chain creation |
29
|
1
|
|
|
|
|
4
|
return $code->(@params); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
6
|
|
|
|
|
19
|
return createChain($filters, 0, $code, \@params)->(); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub filterCount { |
37
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
38
|
0
|
|
|
|
|
0
|
return $#{$self->filters} + 1; |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub addFilter { |
42
|
5
|
|
|
5
|
0
|
2593
|
my ($self, @params) = @_; |
43
|
5
|
100
|
|
|
|
31
|
if ($#params > 0) { |
|
|
50
|
|
|
|
|
|
44
|
4
|
|
|
|
|
20
|
unshift(@{$self->filters}, [@params]); |
|
4
|
|
|
|
|
17
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($#params == 0) { |
47
|
1
|
|
|
|
|
2
|
unshift(@{$self->filters}, $params[0]); |
|
1
|
|
|
|
|
4
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub hasFilter { |
52
|
0
|
|
|
0
|
0
|
0
|
my ($self, $code) = @_; |
53
|
0
|
|
|
|
|
0
|
my $filters = $self->filters; |
54
|
0
|
|
|
|
|
0
|
foreach my $filter (@$filters) { |
55
|
0
|
0
|
|
|
|
0
|
if (UNIVERSAL::isa($filter, "ARRAY")) { |
56
|
0
|
0
|
|
|
|
0
|
return 1 if ($filter->[0] == $code); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
0
|
0
|
|
|
|
0
|
return 1 if ($filter == $code); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub removeAllFilters { |
65
|
2
|
|
|
2
|
0
|
968
|
my $self = shift; |
66
|
2
|
|
|
|
|
15
|
$self->filters([]); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub removeFilter { |
70
|
1
|
|
|
1
|
0
|
772
|
my ($self, $code) = @_; |
71
|
1
|
|
|
|
|
4
|
my $filters = $self->filters; |
72
|
1
|
|
|
|
|
4
|
for (my $i=0; $i<=$#{$filters}; $i++) { |
|
3
|
|
|
|
|
11
|
|
73
|
2
|
100
|
|
|
|
8
|
if (UNIVERSAL::isa($filters->[$i], "ARRAY")) { |
74
|
1
|
50
|
|
|
|
4
|
next unless ($filters->[$i][0] == $code); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
1
|
50
|
|
|
|
6
|
next unless ($filters->[$i] == $code); |
78
|
|
|
|
|
|
|
} |
79
|
1
|
|
|
|
|
3
|
splice(@{$filters}, $i, 1); |
|
1
|
|
|
|
|
2
|
|
80
|
1
|
|
|
|
|
3
|
$i--; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub createChain { |
85
|
14
|
|
|
14
|
0
|
27
|
my ($filters, $pos, $target, $params) = @_; |
86
|
14
|
100
|
66
|
|
|
43
|
if (!defined($filters) or $pos > $#{$filters}) { |
|
14
|
|
|
|
|
54
|
|
87
|
|
|
|
|
|
|
return sub { |
88
|
14
|
|
|
14
|
|
16004692
|
return $target->(@$params); |
89
|
6
|
|
|
|
|
37
|
}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
|
|
|
|
|
|
# A filter is either a CODE block |
93
|
|
|
|
|
|
|
# or an array where the 1st item is the CODE block |
94
|
|
|
|
|
|
|
# and the rest of the parameters are sent to the block. |
95
|
8
|
|
|
|
|
13
|
my $filter = $filters->[$pos]; |
96
|
8
|
|
|
|
|
13
|
my @filterParams; |
97
|
8
|
100
|
|
|
|
33
|
if (UNIVERSAL::isa($filter, "ARRAY")) { |
98
|
5
|
|
|
|
|
14
|
@filterParams = @$filter; |
99
|
5
|
|
|
|
|
11
|
$filter = shift(@filterParams); |
100
|
|
|
|
|
|
|
} |
101
|
8
|
|
|
|
|
29
|
my $chain = createChain($filters, $pos+1, $target, $params); |
102
|
|
|
|
|
|
|
return sub { |
103
|
8
|
|
|
8
|
|
963
|
return $filter->($chain, $params, @filterParams); |
104
|
8
|
|
|
|
|
57
|
}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
return 1; |