line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::FilterManager; |
2
|
98
|
|
|
98
|
|
463
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
98
|
|
|
98
|
|
153
|
|
|
98
|
|
|
98
|
|
2328
|
|
|
98
|
|
|
|
|
465
|
|
|
98
|
|
|
|
|
147
|
|
|
98
|
|
|
|
|
432
|
|
|
98
|
|
|
|
|
2483
|
|
|
98
|
|
|
|
|
177
|
|
|
98
|
|
|
|
|
3427
|
|
3
|
98
|
|
|
98
|
|
502
|
use parent 'DTL::Fast::Replacer'; |
|
98
|
|
|
|
|
158
|
|
|
98
|
|
|
|
|
610
|
|
4
|
|
|
|
|
|
|
|
5
|
98
|
|
|
98
|
|
7056
|
use DTL::Fast::Template; |
|
98
|
|
|
|
|
202
|
|
|
98
|
|
|
|
|
2984
|
|
6
|
98
|
|
|
98
|
|
512
|
use Scalar::Util qw(weaken); |
|
98
|
|
|
|
|
183
|
|
|
98
|
|
|
|
|
72071
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new |
9
|
|
|
|
|
|
|
{ |
10
|
1776
|
|
|
1776
|
0
|
4927
|
my( $proto, %kwargs ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
1776
|
|
33
|
|
|
6447
|
$proto = ref $proto || $proto; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $self = $proto->SUPER::new( |
15
|
|
|
|
|
|
|
'filters' => [], |
16
|
|
|
|
|
|
|
'filters_number' => 0, |
17
|
1776
|
|
|
|
|
6788
|
'replacement' => $kwargs{'replacement'}, # if strings were back-uped before |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
1776
|
100
|
|
|
|
4795
|
if( $self->{'replacement'} ) |
21
|
|
|
|
|
|
|
{ |
22
|
784
|
|
|
|
|
2029
|
weaken($self->{'replacement'}); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
1776
|
100
|
|
|
|
4098
|
if( $kwargs{'filters'} ) |
26
|
|
|
|
|
|
|
{ |
27
|
4
|
50
|
|
|
|
10
|
if( ref $kwargs{'filters'} eq 'ARRAY' ) |
28
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
|
|
0
|
$self->add_filters($kwargs{'filters'}); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else |
32
|
|
|
|
|
|
|
{ |
33
|
4
|
|
|
|
|
13
|
$self->parse_filters($kwargs{'filters'}); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
1776
|
|
|
|
|
6967
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub filter |
41
|
|
|
|
|
|
|
{ |
42
|
470
|
|
|
470
|
0
|
667
|
my $self = shift; |
43
|
470
|
|
|
|
|
678
|
my $value = shift; |
44
|
470
|
|
|
|
|
608
|
my $context = shift; |
45
|
|
|
|
|
|
|
|
46
|
470
|
|
|
|
|
897
|
$self->{'safe'} = 0; |
47
|
|
|
|
|
|
|
|
48
|
470
|
|
|
|
|
612
|
foreach my $filter (@{$self->{'filters'}}) |
|
470
|
|
|
|
|
1019
|
|
49
|
|
|
|
|
|
|
{ |
50
|
515
|
50
|
|
|
|
2092
|
$value = $filter->filter($self, $value, $context) |
51
|
|
|
|
|
|
|
if defined $filter; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
464
|
|
|
|
|
2192
|
return $value; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub parse_filters |
58
|
|
|
|
|
|
|
{ |
59
|
4
|
|
|
4
|
0
|
5
|
my $self = shift; |
60
|
4
|
|
|
|
|
6
|
my $filter_string = shift; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
16
|
$filter_string =~ s/(^\s+|\s+$)//gsi; |
63
|
4
|
|
|
|
|
22
|
return $self->add_filters([split /\s*\|+\s*/x, $filter_string]); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub add_filters |
67
|
|
|
|
|
|
|
{ |
68
|
467
|
|
|
467
|
0
|
693
|
my $self = shift; |
69
|
467
|
|
|
|
|
649
|
my $filter_names = shift; |
70
|
|
|
|
|
|
|
|
71
|
467
|
|
|
|
|
928
|
foreach my $filter_name (@$filter_names) |
72
|
|
|
|
|
|
|
{ |
73
|
514
|
|
|
|
|
1244
|
$self->add_filter($filter_name); |
74
|
|
|
|
|
|
|
} |
75
|
466
|
|
|
|
|
1065
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub add_filter |
79
|
|
|
|
|
|
|
{ |
80
|
515
|
|
|
515
|
0
|
742
|
my $self = shift; |
81
|
515
|
|
|
|
|
778
|
my $filter_name = shift; |
82
|
|
|
|
|
|
|
|
83
|
515
|
|
|
|
|
1853
|
my @arguments = split /\s*\:\s*/x, $self->backup_strings($filter_name); |
84
|
515
|
|
|
|
|
1059
|
$filter_name = shift @arguments; |
85
|
|
|
|
|
|
|
|
86
|
515
|
100
|
66
|
|
|
1956
|
if( |
87
|
|
|
|
|
|
|
not exists $DTL::Fast::FILTER_HANDLERS{$filter_name} |
88
|
|
|
|
|
|
|
and exists $DTL::Fast::KNOWN_FILTERS{$filter_name} |
89
|
|
|
|
|
|
|
) |
90
|
|
|
|
|
|
|
{ |
91
|
85
|
|
|
|
|
50465
|
require Module::Load; |
92
|
85
|
|
|
|
|
65416
|
Module::Load::load($DTL::Fast::KNOWN_FILTERS{$filter_name}); |
93
|
85
|
|
|
|
|
1033
|
$DTL::Fast::LOADED_MODULES{$DTL::Fast::KNOWN_FILTERS{$filter_name}} = time; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
515
|
100
|
|
|
|
1316
|
if( exists $DTL::Fast::FILTER_HANDLERS{$filter_name} ) |
97
|
|
|
|
|
|
|
{ |
98
|
513
|
|
|
|
|
860
|
my $args = []; |
99
|
|
|
|
|
|
|
|
100
|
513
|
|
|
|
|
1040
|
foreach my $argument (@arguments) |
101
|
|
|
|
|
|
|
{ |
102
|
353
|
|
33
|
|
|
1337
|
push @$args, $self->get_backup_or_variable($argument) // $argument; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
513
|
|
|
|
|
767
|
push @{$self->{'filters'}}, $DTL::Fast::FILTER_HANDLERS{$filter_name}->new($args); |
|
513
|
|
|
|
|
2685
|
|
106
|
|
|
|
|
|
|
|
107
|
512
|
|
|
|
|
1132
|
$self->{'filters_number'}++; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else |
110
|
|
|
|
|
|
|
{ |
111
|
2
|
|
|
|
|
19
|
warn $self->get_parse_error( "unknown filter $filter_name" ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
514
|
|
|
|
|
1282
|
return $self; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |