line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::FilterManager; |
2
|
98
|
|
|
98
|
|
533
|
use strict; |
|
98
|
|
|
|
|
226
|
|
|
98
|
|
|
|
|
2187
|
|
3
|
98
|
|
|
98
|
|
688
|
use utf8; |
|
98
|
|
|
|
|
168
|
|
|
98
|
|
|
|
|
376
|
|
4
|
98
|
|
|
98
|
|
2017
|
use warnings FATAL => 'all'; |
|
98
|
|
|
|
|
178
|
|
|
98
|
|
|
|
|
2673
|
|
5
|
98
|
|
|
98
|
|
513
|
use parent 'DTL::Fast::Replacer'; |
|
98
|
|
|
|
|
177
|
|
|
98
|
|
|
|
|
414
|
|
6
|
|
|
|
|
|
|
|
7
|
98
|
|
|
98
|
|
5894
|
use DTL::Fast::Template; |
|
98
|
|
|
|
|
196
|
|
|
98
|
|
|
|
|
2657
|
|
8
|
98
|
|
|
98
|
|
454
|
use Scalar::Util qw(weaken); |
|
98
|
|
|
|
|
187
|
|
|
98
|
|
|
|
|
49544
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new |
11
|
|
|
|
|
|
|
{ |
12
|
1776
|
|
|
1776
|
0
|
5289
|
my ( $proto, %kwargs ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
1776
|
|
33
|
|
|
6285
|
$proto = ref $proto || $proto; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $self = $proto->SUPER::new( |
17
|
|
|
|
|
|
|
filters => [ ], |
18
|
|
|
|
|
|
|
filters_number => 0, |
19
|
|
|
|
|
|
|
replacement => $kwargs{replacement}, # if strings were back-uped before |
20
|
1776
|
|
|
|
|
5876
|
); |
21
|
|
|
|
|
|
|
|
22
|
1776
|
100
|
|
|
|
4575
|
if ($self->{replacement}) |
23
|
|
|
|
|
|
|
{ |
24
|
784
|
|
|
|
|
1868
|
weaken($self->{replacement}); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
1776
|
100
|
|
|
|
4020
|
if ($kwargs{filters}) |
28
|
|
|
|
|
|
|
{ |
29
|
4
|
50
|
|
|
|
11
|
if (ref $kwargs{filters} eq 'ARRAY') |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
|
|
0
|
$self->add_filters($kwargs{filters}); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else |
34
|
|
|
|
|
|
|
{ |
35
|
4
|
|
|
|
|
13
|
$self->parse_filters($kwargs{filters}); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1776
|
|
|
|
|
5406
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub filter |
43
|
|
|
|
|
|
|
{ |
44
|
470
|
|
|
470
|
0
|
818
|
my $self = shift; |
45
|
470
|
|
|
|
|
766
|
my $value = shift; |
46
|
470
|
|
|
|
|
697
|
my $context = shift; |
47
|
|
|
|
|
|
|
|
48
|
470
|
|
|
|
|
843
|
$self->{safe} = 0; |
49
|
|
|
|
|
|
|
|
50
|
470
|
|
|
|
|
691
|
foreach my $filter (@{$self->{filters}}) |
|
470
|
|
|
|
|
933
|
|
51
|
|
|
|
|
|
|
{ |
52
|
515
|
50
|
|
|
|
1890
|
$value = $filter->filter($self, $value, $context) |
53
|
|
|
|
|
|
|
if (defined $filter); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
464
|
|
|
|
|
2281
|
return $value; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub parse_filters |
60
|
|
|
|
|
|
|
{ |
61
|
4
|
|
|
4
|
0
|
8
|
my $self = shift; |
62
|
4
|
|
|
|
|
7
|
my $filter_string = shift; |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
20
|
$filter_string =~ s/(^\s+|\s+$)//gsi; |
65
|
4
|
|
|
|
|
22
|
return $self->add_filters([ split /\s*\|+\s*/x, $filter_string ]); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub add_filters |
69
|
|
|
|
|
|
|
{ |
70
|
467
|
|
|
467
|
0
|
811
|
my $self = shift; |
71
|
467
|
|
|
|
|
803
|
my $filter_names = shift; |
72
|
|
|
|
|
|
|
|
73
|
467
|
|
|
|
|
1004
|
foreach my $filter_name (@$filter_names) |
74
|
|
|
|
|
|
|
{ |
75
|
514
|
|
|
|
|
1269
|
$self->add_filter($filter_name); |
76
|
|
|
|
|
|
|
} |
77
|
466
|
|
|
|
|
991
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub add_filter |
81
|
|
|
|
|
|
|
{ |
82
|
515
|
|
|
515
|
0
|
798
|
my $self = shift; |
83
|
515
|
|
|
|
|
877
|
my $filter_name = shift; |
84
|
|
|
|
|
|
|
|
85
|
515
|
|
|
|
|
1751
|
my @arguments = split /\s*\:\s*/x, $self->backup_strings($filter_name); |
86
|
515
|
|
|
|
|
1221
|
$filter_name = shift @arguments; |
87
|
|
|
|
|
|
|
|
88
|
515
|
100
|
66
|
|
|
1878
|
if ( |
89
|
|
|
|
|
|
|
not exists $DTL::Fast::FILTER_HANDLERS{$filter_name} |
90
|
|
|
|
|
|
|
and exists $DTL::Fast::KNOWN_FILTERS{$filter_name} |
91
|
|
|
|
|
|
|
) |
92
|
|
|
|
|
|
|
{ |
93
|
85
|
|
|
|
|
29067
|
require Module::Load; |
94
|
85
|
|
|
|
|
50220
|
Module::Load::load($DTL::Fast::KNOWN_FILTERS{$filter_name}); |
95
|
85
|
|
|
|
|
1260
|
$DTL::Fast::LOADED_MODULES{$DTL::Fast::KNOWN_FILTERS{$filter_name}} = time; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
515
|
100
|
|
|
|
1275
|
if (exists $DTL::Fast::FILTER_HANDLERS{$filter_name}) |
99
|
|
|
|
|
|
|
{ |
100
|
513
|
|
|
|
|
963
|
my $args = [ ]; |
101
|
|
|
|
|
|
|
|
102
|
513
|
|
|
|
|
1025
|
foreach my $argument (@arguments) |
103
|
|
|
|
|
|
|
{ |
104
|
353
|
|
33
|
|
|
1210
|
push @$args, $self->get_backup_or_variable($argument) // $argument; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
513
|
|
|
|
|
836
|
push @{$self->{filters}}, $DTL::Fast::FILTER_HANDLERS{$filter_name}->new($args); |
|
513
|
|
|
|
|
2271
|
|
108
|
|
|
|
|
|
|
|
109
|
512
|
|
|
|
|
1051
|
$self->{filters_number}++; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else |
112
|
|
|
|
|
|
|
{ |
113
|
2
|
|
|
|
|
20
|
warn $self->get_parse_error( "unknown filter $filter_name" ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
514
|
|
|
|
|
1429
|
return $self; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |