line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
2
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
93
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Template::AutoFilter::Parser; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.140770'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: parses TT templates and automatically adds filters to tokens |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
10
|
use base 'Template::Parser'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2369
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
15
|
|
|
15
|
1
|
31
|
my ( $class, $params ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
15
|
|
|
|
|
88
|
my $self = $class->SUPER::new( $params ); |
16
|
15
|
|
100
|
|
|
2526
|
$self->{AUTO_FILTER} = $params->{AUTO_FILTER} || 'html'; |
17
|
15
|
|
66
|
|
|
74
|
$self->{SKIP_DIRECTIVES} = $self->make_skip_directives( $params->{SKIP_DIRECTIVES} ) || $self->default_skip_directives; |
18
|
|
|
|
|
|
|
|
19
|
15
|
|
|
|
|
107
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub split_text { |
23
|
17
|
|
|
17
|
1
|
65152
|
my ( $self, @args ) = @_; |
24
|
17
|
50
|
|
|
|
96
|
my $tokens = $self->SUPER::split_text( @args ) or return; |
25
|
|
|
|
|
|
|
|
26
|
17
|
|
|
|
|
3072
|
for my $token ( @{$tokens} ) { |
|
17
|
|
|
|
|
41
|
|
27
|
51
|
100
|
|
|
|
127
|
next if !ref $token; |
28
|
19
|
100
|
|
|
|
61
|
next if !ref $token->[2]; # Skip ITEXT ($bar) |
29
|
|
|
|
|
|
|
|
30
|
18
|
|
|
|
|
25
|
my %fields = grep { !ref } @{$token->[2]}; # filter out nested fields, they don't matter for our decision of whether there is a filter already |
|
134
|
|
|
|
|
347
|
|
|
18
|
|
|
|
|
37
|
|
31
|
18
|
100
|
|
|
|
77
|
next if $self->has_skip_field( \%fields ); |
32
|
10
|
100
|
|
|
|
52
|
next if ! %fields; |
33
|
|
|
|
|
|
|
|
34
|
9
|
|
|
|
|
17
|
push @{$token->[2]}, qw( FILTER | IDENT ), $self->{AUTO_FILTER}; |
|
9
|
|
|
|
|
54
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
17
|
|
|
|
|
59
|
return $tokens; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub has_skip_field { |
41
|
18
|
|
|
18
|
1
|
34
|
my ( $self, $fields ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
18
|
|
|
|
|
36
|
my $skip_directives = $self->{SKIP_DIRECTIVES}; |
44
|
|
|
|
|
|
|
|
45
|
18
|
|
|
|
|
24
|
for my $field ( keys %{$fields} ) { |
|
18
|
|
|
|
|
82
|
|
46
|
34
|
100
|
|
|
|
166
|
return 1 if $skip_directives->{$field}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
10
|
|
|
|
|
44
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub default_skip_directives { |
53
|
14
|
|
|
14
|
1
|
25
|
my ( $self ) = @_; |
54
|
14
|
|
|
|
|
144
|
my @skip_directives = qw( |
55
|
|
|
|
|
|
|
CALL SET DEFAULT INCLUDE PROCESS WRAPPER BLOCK IF UNLESS ELSIF ELSE |
56
|
|
|
|
|
|
|
END SWITCH CASE FOREACH FOR WHILE FILTER USE MACRO TRY CATCH FINAL |
57
|
|
|
|
|
|
|
THROW NEXT LAST RETURN STOP CLEAR META TAGS DEBUG ASSIGN PERL RAWPERL |
58
|
|
|
|
|
|
|
); |
59
|
14
|
|
|
|
|
36
|
return $self->make_skip_directives( \@skip_directives ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub make_skip_directives { |
63
|
29
|
|
|
29
|
1
|
50
|
my ( $self, $skip_directives_list ) = @_; |
64
|
29
|
100
|
|
|
|
205
|
return if !$skip_directives_list; |
65
|
|
|
|
|
|
|
|
66
|
15
|
|
|
|
|
35
|
my %skip_directives = map { $_ => 1 } @{$skip_directives_list}; |
|
490
|
|
|
|
|
1041
|
|
|
15
|
|
|
|
|
32
|
|
67
|
15
|
|
|
|
|
126
|
return \%skip_directives; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |