lib/Template/Plugin/Filter.pm

filter: Statementstmt 81.1% 43 / 53 Branchbran 50.0% 7 / 14 Conditioncond 41.6% 5 / 12 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 80.0% 12 / 15 Podpod 14.2% 1 / 7 totaltotal 63.3% 69 / 109 CC 11 SCAR 12.1
CC
11
Cov
70%
merge_config
6.0
merge_args
6.0
new
5.7
CRAP 3.3
« lib/Template/Iterator.pm ↑ Summary lib/Template/Plugin/Procedural.pm »
1 #============================================================= -*-Perl-*-
2 #
3 # Template::Plugin::Filter
4 #
5 # DESCRIPTION
6 # Template Toolkit module implementing a base class plugin
7 # object which acts like a filter and can be used with the
8 # FILTER directive.
9 #
10 # AUTHOR
11 # Andy Wardley <abw@wardley.org>
12 #
13 # COPYRIGHT
14 # Copyright (C) 2001-2022 Andy Wardley. All Rights Reserved.
15 #
16 # This module is free software; you can redistribute it and/or
17 # modify it under the same terms as Perl itself.
18 #
19 #============================================================================
20  
21 package Template::Plugin::Filter;
22  
23 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use base 'Template::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use Scalar::Util 'weaken', 'isweak';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28  
29 5 our $VERSION = '3.106';
30 5 ▶our $DYNAMIC = 0 unless defined $DYNAMIC;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Template::Plugin::Filter::DYNAMIC 5 0 5
31  
32  
33 8 ▶sub new {
Subroutine new: called CC=5 SCAR=17.4
Pod documented
34 8 my ($class, $context, @args) = @_;
35 8 ▶ my $config = @args && ref $args[-1] eq 'HASH' ? pop(@args) : { };
Branch: 1 branch
BranchTrueFalseTotal
@args && ref $args[-1] eq 'HASH' ? : 0 8 8
Condition33%1/3
@args and ref $args[-1] eq "HASH"
!ll&&!rl&&r
800
MC/DC0%0/2
@args and ref $args[-1] eq "HASH"
@args ref $args[-1] eq "HASH"
Truth table33%1/3
A and B
A= @argsB= ref $args[-1] eq "HASH"
ABresult
0X0
100
111
36  
37 # look for $DYNAMIC
38 8 my $dynamic;
39 {
40 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 8 $dynamic = ${"$class\::DYNAMIC"};
42 }
43 8 ▶ $dynamic //= $DYNAMIC;
Condition33%1/3
$dynamic //= $Template::Plugin::Filter::DYNAMIC
l!l&&r!l&&!r
080
MC/DC0%0/2
$dynamic //= $Template::Plugin::Filter::DYNAMIC
$dynamic $Template::Plugin::Filter::DYNAMIC
Truth table33%1/3
A //= B
A= $dynamicB= $Template::Plugin::Filter::DYNAMIC
ABresult
1X1
011
000
44  
45 8 my $self = bless {
46 _CONTEXT => $context,
47 _DYNAMIC => $dynamic,
48 _ARGS => \@args,
49 _CONFIG => $config,
50 }, $class;
51  
52 8 ▶ return $self->init($config)
Condition33%1/3
$self->init($config) || $class->error($self->error)
l!l&&r!l&&!r
800
MC/DC0%0/2
$self->init($config) || $class->error($self->error)
$self->init($config) $class->error($self->error)
Truth table33%1/3
A || B
A= $self->init($config)B= $class->error($self->error)
ABresult
1X1
011
000
53 || $class->error($self->error());
54 }
55  
56  
57 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
58 1 my ($self, $config) = @_;
59 1 return $self;
60 }
61  
62  
63 9 ▶sub factory {
Subroutine factory: called CC=4 SCAR=13.9
Pod undocumented
64 9 my $self = shift;
65 9 my $this = $self;
66  
67 # avoid a memory leak
68 weaken( $this->{_CONTEXT} ) if ref $this->{_CONTEXT}
69 9 ▶ && !isweak $this->{_CONTEXT};
Branch: 1 branch
BranchTrueFalseTotal
if ref $this->{"_CONTEXT"} and not builtin::is_weak($this->{"_CONTEXT"}) 8 1 9
Condition66%2/3
ref $this->{"_CONTEXT"} and not builtin::is_weak($this->{"_CONTEXT"})
!ll&&!rl&&r
018
MC/DC50%1/2
ref $this->{"_CONTEXT"} and not builtin::is_weak($this->{"_CONTEXT"})
ref $this->{"_CONTEXT"} not builtin::is_weak($this->{"_CONTEXT"})
Truth table66%2/3
A and not(B)
A= ref $this->{"_CONTEXT"}B= not builtin::is_weak($this->{"_CONTEXT"})
ABresult
0X0
100
111
70  
71 9 ▶ if ($self->{ _DYNAMIC }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_DYNAMIC'}) { } 7 2 9
72 6 ▶ return [ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
73 6 my ($context, @args) = @_;
74 6 ▶ my $config = ref $args[-1] eq 'HASH' ? pop(@args) : { };
Branch: 1 branch
BranchTrueFalseTotal
ref $args[-1] eq 'HASH' ? : 0 6 6
75  
76 6 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
77 6 $this->filter(shift, \@args, $config);
78 6 };
79 7 }, 1 ];
80 }
81 else {
82 2 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
83 2 $this->filter(shift);
84 2 };
85 }
86 }
87  
88 0 ▶sub filter {
Subroutine filter: not called CC=1 SCAR=6.9
Pod undocumented
89 0 my ($self, $text, $args, $config) = @_;
90 0 return $text;
91 }
92  
93  
94 0 ▶sub merge_config {
Subroutine merge_config: not called CC=2 SCAR=17.9
Pod undocumented
95 0 my ($self, $newcfg) = @_;
96 0 my $owncfg = $self->{ _CONFIG };
97 0 ▶ return $owncfg unless $newcfg;
Branch: 1 branch
BranchTrueFalseTotal
unless $newcfg 0 0 0
98 0 return { %$owncfg, %$newcfg };
99 }
100  
101  
102 0 ▶sub merge_args {
Subroutine merge_args: not called CC=2 SCAR=17.9
Pod undocumented
103 0 my ($self, $newargs) = @_;
104 0 my $ownargs = $self->{ _ARGS };
105 0 ▶ return $ownargs unless $newargs;
Branch: 1 branch
BranchTrueFalseTotal
unless $newargs 0 0 0
106 0 return [ @$ownargs, @$newargs ];
107 }
108  
109  
110 7 ▶sub install_filter {
Subroutine install_filter: called CC=1 SCAR=0.0
Pod undocumented
111 7 my ($self, $name) = @_;
112 7 $self->{ _CONTEXT }->define_filter( $name => $self->factory );
113 7 return $self;
114 }
115  
116  
117  
118 5 1;
119  
120 __END__
« lib/Template/Iterator.pm ↑ Summary lib/Template/Plugin/Procedural.pm »