File Coverage

blib/lib/DTL/Fast/Tag/BlockSuper.pm
Criterion Covered Total %
statement 30 30 100.0
branch 3 6 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 39 45 86.6


line stmt bran cond sub pod time code
1             package DTL::Fast::Tag::BlockSuper;
2 1     1   593 use strict; use utf8; use warnings FATAL => 'all';
  1     1   2  
  1     1   35  
  1         6  
  1         2  
  1         5  
  1         33  
  1         1  
  1         46  
3 1     1   5 use parent 'DTL::Fast::Tag::Simple';
  1         3  
  1         5  
4              
5             $DTL::Fast::TAG_HANDLERS{'block_super'} = __PACKAGE__;
6              
7             #@Override
8             sub render
9             {
10 2     2 0 3 my( $self, $context ) = @_;
11 2         2 my $result = '';
12            
13 2         2 my $ns = $context->{'ns'}->[-1];
14            
15 2 50 33     9 if ( # there is an inheritance and we are in block
16             my $descendants = $ns->{'_dtl_descendants'}
17             and exists $ns->{'_dtl_rendering_block'}
18             )
19             {
20 2         2 my $current_template = $ns->{'_dtl_rendering_template'};
21 2         2 my $current_block_name = $ns->{'_dtl_rendering_block'}->{'block_name'};
22            
23 2         6 for( my $i = 0; $i < scalar @$descendants; $i++ )
24             {
25 2 50       5 if ( $descendants->[$i] == $current_template ) # found self
26             {
27 2         4 for( my $j = $i + 1; $j < scalar @$descendants; $j++ )
28             {
29 2 50       7 if ( $descendants->[$j]->{'blocks'}->{$current_block_name} ) # found parent block
30             {
31 2         5 $context->push_scope();
32 2         3 $ns->{'_dtl_rendering_template'} = $descendants->[$j];
33 2         5 $ns->{'_dtl_rendering_block'} = $descendants->[$j]->{'blocks'}->{$current_block_name};
34            
35 2         14 $result = $descendants->[$j]->{'blocks'}->{$current_block_name}->SUPER::render($context);
36            
37 2         5 $context->pop_scope();
38 2         2 last;
39             }
40            
41             }
42 2         2 last;
43             }
44            
45             }
46             }
47            
48 2         5 return $result;
49             }
50              
51             1;