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

filter: Statementstmt 100% 50 / 50 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 6 totaltotal 91.6% 66 / 72 SCAR 13.9
CC
4
Cov
100%
render
3.0
parse_tag_chunk
2.0
BEGIN
1.0
CRAP 4.0
« blib/lib/DTL/Fast/Replacer/Replacement.pm ↑ Summary blib/lib/DTL/Fast/Tag/Now.pm »
1 package DTL::Fast::Tag::Ifequal;
2 3 ▶use strict; use utf8; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use parent 'DTL::Fast::Tag::If';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 $DTL::Fast::TAG_HANDLERS{'ifequal'} = __PACKAGE__;
6  
7 3 ▶use DTL::Fast::Tag::If::Condition;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use DTL::Fast::Expression::Operator::Binary::Eq;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #@Override
11 16 ▶sub get_close_tag{ return 'endifequal';}
Subroutine get_close_tag: called CC=1 SCAR=0.0
Pod undocumented
12  
13 #@Override
14 sub parse_parameters
15 {
16 32 ▶ my $self = shift;
Subroutine parse_parameters: called CC=1 SCAR=0.0
Pod undocumented
17  
18 32 $self->{'conditions'} = [];
19 32 my $sources = $self->parse_sources($self->{'parameter'});
20 32 return $self->add_main_condition($sources);
21 }
22  
23 #@Override
24 sub parse_tag_chunk
25 {
26 64 ▶ my( $self, $tag_name, $tag_param, $chunk_lines ) = @_;
Subroutine parse_tag_chunk: called CC=2 SCAR=6.9
Pod undocumented
27
28 64 my $result = undef;
29  
30 64 ▶ if( $tag_name eq 'else' )
Branch: 1 branch
BranchTrueFalseTotal
if ($tag_name eq 'else') { } 32 32 64
31 {
32 32 $self->add_condition(1);
33 32 $DTL::Fast::Template::CURRENT_TEMPLATE_LINE += $chunk_lines;
34 }
35 else
36 {
37 32 $result = $self->SUPER::parse_tag_chunk($tag_name, $tag_param, $chunk_lines);
38 }
39
40 64 return $result;
41 }
42  
43 #@Override
44 sub render
45 {
46 32 ▶ my $self = shift;
Subroutine render: called CC=3 SCAR=11.0
Pod undocumented
47 32 my $context = shift;
48 32 my $result = '';
49
50 32 foreach my $condition (@{$self->{'conditions'}})
51 {
52 48 ▶ if( $condition->is_true($context) )
Branch: 1 branch
BranchTrueFalseTotal
if ($condition->is_true($context)) 32 16 48
53 {
54 32 $result = $condition->render($context);
55 32 last;
56 }
57 }
58 32 return $result;
59 }
60  
61 sub add_main_condition
62 {
63 16 ▶ my $self = shift;
Subroutine add_main_condition: called CC=1 SCAR=0.0
Pod undocumented
64 16 my $sources = shift;
65 16 return $self->add_condition(DTL::Fast::Expression::Operator::Binary::Eq->new(@{$sources}[0,1]));
66 }
67  
68 #@Override
69 sub add_condition
70 {
71 64 ▶ my $self = shift;
Subroutine add_condition: called CC=1 SCAR=0.0
Pod undocumented
72 64 my $condition = shift;
73 64 push @{$self->{'conditions'}}, DTL::Fast::Tag::If::Condition->new($condition);
74 64 return $self;
75 }
76  
77 3 1;
« blib/lib/DTL/Fast/Replacer/Replacement.pm ↑ Summary blib/lib/DTL/Fast/Tag/Now.pm »