| 1 | package DTL::Fast::Tag::Block; | ||||||||||||||
| 2 | 2 | ▶ | 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 | 2 | ▶ | use parent 'DTL::Fast::Tag'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 2 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 2 | our $VERSION = '1.00'; | |||||||||||||
| 8 | |||||||||||||||
| 9 | 2 | $DTL::Fast::TAG_HANDLERS{'block'} = __PACKAGE__; | |||||||||||||
| 10 | |||||||||||||||
| 11 | #@Override | ||||||||||||||
| 12 | 27 | ▶ | sub get_close_tag{return 'endblock';} | ||||||||||||
|
Subroutine
get_close_tag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | #@Override | ||||||||||||||
| 15 | sub parse_parameters | ||||||||||||||
| 16 | { | ||||||||||||||
| 17 | 26 | ▶ | my( $self ) = @_; | ||||||||||||
|
Subroutine
parse_parameters: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 26 | $self->{'block_name'} = $self->{'parameter'}; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 26 | ▶ | die $self->get_parse_error("no name specified in the block tag") if not $self->{'block_name'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | # registering block within template | ||||||||||||||
| 24 | 25 | ▶ | if ( exists $DTL::Fast::Template::CURRENT_TEMPLATE->{'blocks'}->{$self->{'block_name'}} ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | { | ||||||||||||||
| 26 | die $self->get_parse_error( | ||||||||||||||
| 27 | sprintf( | ||||||||||||||
| 28 | "block name `%s` must be unique in the template" | ||||||||||||||
| 29 | , $self->{'block_name'} | ||||||||||||||
| 30 | ) | ||||||||||||||
| 31 | , 'Reason' => sprintf( | ||||||||||||||
| 32 | 'block `%s` was already defined at line %s' | ||||||||||||||
| 33 | , $self->{'block_name'} | ||||||||||||||
| 34 | 1 | , $DTL::Fast::Template::CURRENT_TEMPLATE->{'blocks'}->{$self->{'block_name'}}->{'_template_line'} | |||||||||||||
| 35 | ) | ||||||||||||||
| 36 | ); | ||||||||||||||
| 37 | } | ||||||||||||||
| 38 | else | ||||||||||||||
| 39 | { | ||||||||||||||
| 40 | 24 | $DTL::Fast::Template::CURRENT_TEMPLATE->{'blocks'}->{$self->{'block_name'}} = $self; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 24 | return $self; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | #@Override | ||||||||||||||
| 47 | sub render | ||||||||||||||
| 48 | { | ||||||||||||||
| 49 | 24 | ▶ | my( $self, $context ) = @_; | ||||||||||||
|
Subroutine
render: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||
| 50 | |||||||||||||||
| 51 | 24 | my $result; | |||||||||||||
| 52 | |||||||||||||||
| 53 | 24 | $context->push_scope(); | |||||||||||||
| 54 | 24 | my $ns = $context->{'ns'}->[-1]; | |||||||||||||
| 55 | |||||||||||||||
| 56 | 24 | $ns->{'_dtl_rendering_block'} = $self; | |||||||||||||
| 57 | |||||||||||||||
| 58 | 24 | ▶ | if ( $ns->{'_dtl_descendants'} ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | { | ||||||||||||||
| 60 | # template with inheritance | ||||||||||||||
| 61 | 16 | foreach my $descendant (@{$ns->{'_dtl_descendants'}}) | |||||||||||||
| 62 | { | ||||||||||||||
| 63 | 24 | ▶ | if ( $descendant == $self ) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 64 | { | ||||||||||||||
| 65 | 0 | $result = $self->SUPER::render($context); | |||||||||||||
| 66 | 0 | last; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | elsif($descendant->{'blocks'}->{$self->{'block_name'}}) | ||||||||||||||
| 69 | { | ||||||||||||||
| 70 | 16 | $ns->{'_dtl_rendering_template'} = $descendant; | |||||||||||||
| 71 | 16 | $result = $descendant->{'blocks'}->{$self->{'block_name'}}->SUPER::render($context); | |||||||||||||
| 72 | 16 | last; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | } | ||||||||||||||
| 75 | } | ||||||||||||||
| 76 | else | ||||||||||||||
| 77 | { | ||||||||||||||
| 78 | # simple template | ||||||||||||||
| 79 | 8 | $result = $self->SUPER::render($context); | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | 18 | $context->pop_scope(); | |||||||||||||
| 82 | |||||||||||||||
| 83 | 18 | return $result; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 2 | 1; | |||||||||||||