| 1 | package Net::Amazon::MechanicalTurk::FilterChain; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Net::Amazon::MechanicalTurk::BaseObject; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.00'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | 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 | 1 | Net::Amazon::MechanicalTurk::FilterChain->attributes(qw{ | |||||||||||||||||||||||||||
| 15 | filters | ||||||||||||||||||||||||||||
| 16 | }); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | 1 | $self->setAttributes(@_); | |||||||||||||||||||||||||||
| 21 | 1 | ▶ | $self->filters([]) unless $self->filters; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 7 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 7 | my ($self, $code, @params) = @_; | |||||||||||||||||||||||||||
| 26 | 7 | my $filters = $self->filters; | |||||||||||||||||||||||||||
| 27 | 7 | ▶ | if ($#{$filters} < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | # bypass chain creation | ||||||||||||||||||||||||||||
| 29 | 1 | return $code->(@params); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else { | ||||||||||||||||||||||||||||
| 32 | 6 | return createChain($filters, 0, $code, \@params)->(); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub filterCount { | ||||||||||||||||||||||||||
|
Subroutine
filterCount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 0 | return $#{$self->filters} + 1; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 5 | ▶ | sub addFilter { | ||||||||||||||||||||||||||
|
Subroutine
addFilter: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 5 | my ($self, @params) = @_; | |||||||||||||||||||||||||||
| 43 | 5 | ▶ | if ($#params > 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | 4 | unshift(@{$self->filters}, [@params]); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | elsif ($#params == 0) { | ||||||||||||||||||||||||||||
| 47 | 1 | unshift(@{$self->filters}, $params[0]); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub hasFilter { | ||||||||||||||||||||||||||
|
Subroutine
hasFilter: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | my ($self, $code) = @_; | |||||||||||||||||||||||||||
| 53 | 0 | my $filters = $self->filters; | |||||||||||||||||||||||||||
| 54 | 0 | foreach my $filter (@$filters) { | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (UNIVERSAL::isa($filter, "ARRAY")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return 1 if ($filter->[0] == $code); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return 1 if ($filter == $code); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub removeAllFilters { | ||||||||||||||||||||||||||
|
Subroutine
removeAllFilters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 2 | $self->filters([]); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub removeFilter { | ||||||||||||||||||||||||||
|
Subroutine
removeFilter: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 1 | my ($self, $code) = @_; | |||||||||||||||||||||||||||
| 71 | 1 | my $filters = $self->filters; | |||||||||||||||||||||||||||
| 72 | 1 | ▶ | for (my $i=0; $i<=$#{$filters}; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | if (UNIVERSAL::isa($filters->[$i], "ARRAY")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | next unless ($filters->[$i][0] == $code); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||
| 77 | 1 | ▶ | next unless ($filters->[$i] == $code); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 1 | splice(@{$filters}, $i, 1); | |||||||||||||||||||||||||||
| 80 | 1 | $i--; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 14 | ▶ | sub createChain { | ||||||||||||||||||||||||||
|
Subroutine
createChain: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 14 | my ($filters, $pos, $target, $params) = @_; | |||||||||||||||||||||||||||
| 86 | 14 | ▶ | if (!defined($filters) or $pos > $#{$filters}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $filters or $pos > $#{$filters;}
MC/DC50%1/2
not defined $filters or $pos > $#{$filters;}
not defined $filters
$pos > $#{$filters;}
Truth table66%2/3
not(A) or B
A= not defined $filtersB= $pos > $#{$filters;}
| |||||||||||||||||||||||||||||
| 87 | 10 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | 10 | return $target->(@$params); | |||||||||||||||||||||||||||
| 89 | 6 | }; | |||||||||||||||||||||||||||
| 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 | my $filter = $filters->[$pos]; | |||||||||||||||||||||||||||
| 96 | 8 | my @filterParams; | |||||||||||||||||||||||||||
| 97 | 8 | ▶ | if (UNIVERSAL::isa($filter, "ARRAY")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 5 | @filterParams = @$filter; | |||||||||||||||||||||||||||
| 99 | 5 | $filter = shift(@filterParams); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 8 | my $chain = createChain($filters, $pos+1, $target, $params); | |||||||||||||||||||||||||||
| 102 | 8 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 103 | 8 | return $filter->($chain, $params, @filterParams); | |||||||||||||||||||||||||||
| 104 | 8 | }; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | return 1; | |||||||||||||||||||||||||||