blib/lib/DTL/Fast/Tag/With.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 94.2% 49 / 52 CC 5 SCAR 8.2
CC
5
Cov
100%
parse_parameters
4.0
render
2.0
BEGIN
1.0
CRAP 2.3
« blib/lib/DTL/Fast/Filter/Pluralize.pm ↑ Summary blib/lib/DTL/Fast/Cache/Runtime.pm »
1 package DTL::Fast::Tag::With;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use parent 'DTL::Fast::Tag';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 $DTL::Fast::TAG_HANDLERS{with} = __PACKAGE__;
8  
9 #@Override
10 35 ▶sub get_close_tag {return 'endwith';}
Subroutine get_close_tag: called CC=1 SCAR=0.0
Pod undocumented
11  
12 #@Override
13 sub parse_parameters
14 23 ▶{
Subroutine parse_parameters: called CC=4 SCAR=13.9
Pod undocumented
15 23 my $self = shift;
16  
17 23 $self->{mappings} = { };
18 23 ▶ if ($self->{parameter} =~ /^\s*(.+?)\s+as\s+(.+)\s*$/s) # legacy
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'parameter'} =~ /^\s*(.+?)\s+as\s+(.+)\s*$/s) { } 1 22 23
19 {
20 1 $self->{mappings}->{$2} = DTL::Fast::Expression->new($1);
21 }
22 else # modern
23 {
24 22 my @parts = ();
25 22 my $string = $self->backup_strings($self->{parameter});
26  
27 22 ▶ while ( $string =~ s{^
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^ \s* ([^\s\=]+) \s*\=\s* ([^\s\=]+) \s* //x) 36 21 57
28 \s*
29 ([^\s\=]+)
30 \s*\=\s*
31 ([^\s\=]+)
32 \s*
33 }{}x
34 )
35 {
36 36 $self->{mappings}->{$1} = $self->get_backup_or_variable($2);
37 }
38  
39 21 ▶ if ($string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string) 2 19 21
40 die $self->get_parse_error(
41 "there is an error in `with` parameters"
42 , 'Passed parameters' => $self->{parameter}
43 2 );
44 }
45 }
46  
47 20 return $self;
48 }
49  
50 #@Override
51 sub render
52 14 ▶{
Subroutine render: called CC=2 SCAR=6.9
Pod undocumented
53 14 my $self = shift;
54 14 my $context = shift;
55  
56 14 my %vars = ();
57 14 foreach my $key (keys(%{$self->{mappings}}))
58 {
59 24 $vars{$key} = $self->{mappings}->{$key}->render($context);
60 }
61  
62 14 $context->push_scope()->set(%vars);
63  
64 14 my $result = $self->SUPER::render($context);
65  
66 10 $context->pop_scope();
67  
68 10 return $result;
69 }
70  
71 4 1;
« blib/lib/DTL/Fast/Filter/Pluralize.pm ↑ Summary blib/lib/DTL/Fast/Cache/Runtime.pm »