File Coverage

blib/lib/DTL/Fast/Renderer.pm
Criterion Covered Total %
statement 29 29 100.0
branch 2 2 100.0
condition 4 5 80.0
subroutine 8 8 100.0
pod 0 3 0.0
total 43 47 91.4


line stmt bran cond sub pod time code
1             package DTL::Fast::Renderer;
2 98     98   35104 use strict;
  98         975  
  98         4499  
3 98     98   38698 use utf8;
  98         1641  
  98         1008  
4 98     98   3811 use warnings FATAL => 'all';
  98         179  
  98         4061  
5 98     98   1126 use parent 'DTL::Fast::Replacer';
  98         880  
  98         2524  
6              
7 98     98   36435 use DTL::Fast::Context;
  98         269  
  98         15697  
8              
9             sub new
10             {
11 3344     3344 0 11964 my ( $proto, %kwargs ) = @_;
12              
13 3344         6318 $kwargs{chunks} = [ ];
14              
15 3344         11131 return $proto->SUPER::new(%kwargs);
16             }
17              
18             sub add_chunk
19             {
20 6671     6671 0 10837 my ( $self, $chunk ) = @_;
21              
22 6671 100       14199 push @{$self->{chunks}}, $chunk if (defined $chunk);
  3810         7289  
23 6671         12421 return $self;
24             }
25              
26             sub render
27             {
28 4454     4454 0 7812 my ( $self, $context, $global_safe ) = @_;
29              
30 4454   66     18637 $global_safe ||= $context->{ns}->[- 1]->{_dtl_safe};
31              
32 4454         7032 my $result = [ ];
33              
34 4454         6619 foreach my $chunk (@{$self->{chunks}})
  4454         8597  
35             {
36 6122   100     16947 push @$result, $chunk->render($context, $global_safe) // '';
37             }
38              
39 4421         14421 return join '', @$result;
40             }
41              
42             1;