AutoFilter/Parser.pm

filter: Statementstmt 100% 45 / 45 Branchbran 92.8% 13 / 14 Conditioncond 80.0% 4 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 8 / 8 Podpod 100% 5 / 5 totaltotal 95.0% 76 / 80 SCAR 24.9
CC
12
Cov
97%
split_text
7.0
new
3.0
has_skip_field
3.0
CRAP 12.0
↑ Summary AutoFilter.pm »
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'
l!l
312
MC/DC100%1/1
$params->{'AUTO_FILTER'} || 'html'
$params->{'AUTO_FILTER'}
Truth table100%2/2
A
A= $params->{'AUTO_FILTER'}
Aresult
11
00
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
l!l&&r!l&&!r
1140
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
my $tokens = $self->SUPER::split_text(@args) or return 0 17 17
25  
26 17 for my $token ( @{$tokens} ) {
27 51 ▶ next if !ref $token;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $token 32 19 51
28 19 ▶ next if !ref $token->[2]; # Skip ITEXT (<foo>$bar</foo>)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $token->[2] 1 18 19
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
BranchTrueFalseTotal
if $self->has_skip_field(\%fields) 8 10 18
32 10 ▶ next if ! %fields;
Branch: 1 branch
BranchTrueFalseTotal
unless %fields 1 9 10
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
BranchTrueFalseTotal
if $skip_directives->{$field} 8 26 34
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
BranchTrueFalseTotal
unless $skip_directives_list 14 15 29
65  
66 15 my %skip_directives = map { $_ => 1 } @{$skip_directives_list};
67 15 return \%skip_directives;
68 }
69  
70 4 1;
71  
72 __END__
↑ Summary AutoFilter.pm »