| 1 | package DTL::Fast::FilterManager; | ||||||||||||||||||||||||||||
| 2 | 98 | ▶ | use strict; use utf8; use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 98 | ▶ | use parent 'DTL::Fast::Replacer'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 98 | ▶ | use DTL::Fast::Template; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 98 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub new | ||||||||||||||||||||||||||||
| 9 | { | ||||||||||||||||||||||||||||
| 10 | 1776 | ▶ | my( $proto, %kwargs ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1776 | ▶ | $proto = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | my $self = $proto->SUPER::new( | ||||||||||||||||||||||||||||
| 15 | 'filters' => [], | ||||||||||||||||||||||||||||
| 16 | 'filters_number' => 0, | ||||||||||||||||||||||||||||
| 17 | 1776 | 'replacement' => $kwargs{'replacement'}, # if strings were back-uped before | |||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1776 | ▶ | if( $self->{'replacement'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||
| 22 | 784 | weaken($self->{'replacement'}); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1776 | ▶ | if( $kwargs{'filters'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 4 | ▶ | if( ref $kwargs{'filters'} eq 'ARRAY' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 0 | $self->add_filters($kwargs{'filters'}); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else | ||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | 4 | $self->parse_filters($kwargs{'filters'}); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1776 | return $self; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub filter | ||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 470 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 470 | my $value = shift; | |||||||||||||||||||||||||||
| 44 | 470 | my $context = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 470 | $self->{'safe'} = 0; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 470 | foreach my $filter (@{$self->{'filters'}}) | |||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 515 | ▶ | $value = $filter->filter($self, $value, $context) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | if defined $filter; | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 464 | return $value; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub parse_filters | ||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_filters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 4 | my $filter_string = shift; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | $filter_string =~ s/(^\s+|\s+$)//gsi; | |||||||||||||||||||||||||||
| 63 | 4 | return $self->add_filters([split /\s*\|+\s*/x, $filter_string]); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | sub add_filters | ||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | 467 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add_filters: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 467 | my $filter_names = shift; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 467 | foreach my $filter_name (@$filter_names) | |||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 514 | $self->add_filter($filter_name); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 466 | return $self; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub add_filter | ||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 515 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add_filter: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 515 | my $filter_name = shift; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 515 | my @arguments = split /\s*\:\s*/x, $self->backup_strings($filter_name); | |||||||||||||||||||||||||||
| 84 | 515 | $filter_name = shift @arguments; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 515 | ▶ | if( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $DTL::Fast::FILTER_HANDLERS{$filter_name} and exists $DTL::Fast::KNOWN_FILTERS{$filter_name}
MC/DC100%2/2
not exists $DTL::Fast::FILTER_HANDLERS{$filter_name} and exists $DTL::Fast::KNOWN_FILTERS{$filter_name}
not exists $DTL::Fast::FILTER_HANDLERS{$filter_name}
exists $DTL::Fast::KNOWN_FILTERS{$filter_name}
Truth table100%3/3
not(A) and B
A= not exists $DTL::Fast::FILTER_HANDLERS{$filter_name}B= exists $DTL::Fast::KNOWN_FILTERS{$filter_name}
| |||||||||||||||||||||||||||||
| 87 | not exists $DTL::Fast::FILTER_HANDLERS{$filter_name} | ||||||||||||||||||||||||||||
| 88 | and exists $DTL::Fast::KNOWN_FILTERS{$filter_name} | ||||||||||||||||||||||||||||
| 89 | ) | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 85 | require Module::Load; | |||||||||||||||||||||||||||
| 92 | 85 | Module::Load::load($DTL::Fast::KNOWN_FILTERS{$filter_name}); | |||||||||||||||||||||||||||
| 93 | 85 | $DTL::Fast::LOADED_MODULES{$DTL::Fast::KNOWN_FILTERS{$filter_name}} = time; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 515 | ▶ | if( exists $DTL::Fast::FILTER_HANDLERS{$filter_name} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||
| 98 | 513 | my $args = []; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 513 | foreach my $argument (@arguments) | |||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||
| 102 | 353 | ▶ | push @$args, $self->get_backup_or_variable($argument) // $argument; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->get_backup_or_variable($argument) // $argument
MC/DC0%0/2
$self->get_backup_or_variable($argument) // $argument
$self->get_backup_or_variable($argument)
$argument
Truth table33%1/3
A // B
A= $self->get_backup_or_variable($argument)B= $argument
| |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 513 | push @{$self->{'filters'}}, $DTL::Fast::FILTER_HANDLERS{$filter_name}->new($args); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 512 | $self->{'filters_number'}++; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | else | ||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 2 | warn $self->get_parse_error( "unknown filter $filter_name" ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 514 | return $self; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 98 | 1; | |||||||||||||||||||||||||||