| 1 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | package Template::AutoFilter::Parser; | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 4 | our $VERSION = '0.140770'; # VERSION | |||||||||||||||||||
| 7 | # ABSTRACT: parses TT templates and automatically adds filters to tokens | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | ▶ | use base 'Template::Parser'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||
| 13 | 15 | ▶ | my ( $class, $params ) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 15 | my $self = $class->SUPER::new( $params ); | |||||||||||||||||||
| 16 | 15 | ▶ | $self->{AUTO_FILTER} = $params->{AUTO_FILTER} || 'html'; | ||||||||||||||||||
|
Condition100%2/2
$params->{'AUTO_FILTER'} || 'html'
MC/DC100%1/1
$params->{'AUTO_FILTER'} || 'html'
$params->{'AUTO_FILTER'}
Truth table100%2/2
A
A= $params->{'AUTO_FILTER'}
| |||||||||||||||||||||
| 17 | 15 | ▶ | $self->{SKIP_DIRECTIVES} = $self->make_skip_directives( $params->{SKIP_DIRECTIVES} ) || $self->default_skip_directives; | ||||||||||||||||||
|
Condition66%2/3
$self->make_skip_directives($params->{'SKIP_DIRECTIVES'}) || $self->default_skip_directives
MC/DC0%0/2
$self->make_skip_directives($params->{'SKIP_DIRECTIVES'}) || $self->default_skip_directives
$self->make_skip_directives($params->{'SKIP_DIRECTIVES'})
$self->default_skip_directives
Truth table66%2/3
A || B
A= $self->make_skip_directives($params->{'SKIP_DIRECTIVES'})B= $self->default_skip_directives
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 15 | return $self; | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | sub split_text { | ||||||||||||||||||||
| 23 | 17 | ▶ | my ( $self, @args ) = @_; | ||||||||||||||||||
|
Subroutine
split_text: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||
| 24 | 17 | ▶ | my $tokens = $self->SUPER::split_text( @args ) or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 17 | for my $token ( @{$tokens} ) { | |||||||||||||||||||
| 27 | 51 | ▶ | next if !ref $token; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 19 | ▶ | next if !ref $token->[2]; # Skip ITEXT (<foo>$bar</foo>) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 18 | my %fields = grep { !ref } @{$token->[2]}; # filter out nested fields, they don't matter for our decision of whether there is a filter already | |||||||||||||||||||
| 31 | 18 | ▶ | next if $self->has_skip_field( \%fields ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 10 | ▶ | next if ! %fields; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 9 | push @{$token->[2]}, qw( FILTER | IDENT ), $self->{AUTO_FILTER}; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 17 | return $tokens; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub has_skip_field { | ||||||||||||||||||||
| 41 | 18 | ▶ | my ( $self, $fields ) = @_; | ||||||||||||||||||
|
Subroutine
has_skip_field: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 18 | my $skip_directives = $self->{SKIP_DIRECTIVES}; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 18 | for my $field ( keys %{$fields} ) { | |||||||||||||||||||
| 46 | 34 | ▶ | return 1 if $skip_directives->{$field}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 10 | return 0; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub default_skip_directives { | ||||||||||||||||||||
| 53 | 14 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
default_skip_directives: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 54 | 14 | 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 | return $self->make_skip_directives( \@skip_directives ); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | sub make_skip_directives { | ||||||||||||||||||||
| 63 | 29 | ▶ | my ( $self, $skip_directives_list ) = @_; | ||||||||||||||||||
|
Subroutine
make_skip_directives: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 64 | 29 | ▶ | return if !$skip_directives_list; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 15 | my %skip_directives = map { $_ => 1 } @{$skip_directives_list}; | |||||||||||||||||||
| 67 | 15 | return \%skip_directives; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 4 | 1; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||