| 1 | package DTL::Fast::Tag::With; | ||||||||||
| 2 | 4 | ▶ | 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 | 4 | ▶ | use parent 'DTL::Fast::Tag'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | $DTL::Fast::TAG_HANDLERS{'with'} = __PACKAGE__; | |||||||||
| 6 | |||||||||||
| 7 | #@Override | ||||||||||
| 8 | 35 | ▶ | sub get_close_tag{return 'endwith';} | ||||||||
|
Subroutine
get_close_tag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 9 | |||||||||||
| 10 | #@Override | ||||||||||
| 11 | sub parse_parameters | ||||||||||
| 12 | { | ||||||||||
| 13 | 23 | ▶ | my $self = shift; | ||||||||
|
Subroutine
parse_parameters: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 14 | |||||||||||
| 15 | 23 | $self->{'mappings'} = {}; | |||||||||
| 16 | 23 | ▶ | if( $self->{'parameter'} =~ /^\s*(.+?)\s+as\s+(.+)\s*$/s ) # legacy | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | { | ||||||||||
| 18 | 1 | $self->{'mappings'}->{$2} = DTL::Fast::Expression->new($1); | |||||||||
| 19 | } | ||||||||||
| 20 | else # modern | ||||||||||
| 21 | { | ||||||||||
| 22 | 22 | my @parts = (); | |||||||||
| 23 | 22 | my $string = $self->backup_strings($self->{'parameter'}); | |||||||||
| 24 | |||||||||||
| 25 | 22 | ▶ | while ( $string =~ s{^ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | \s* | ||||||||||
| 27 | ([^\s\=]+) | ||||||||||
| 28 | \s*\=\s* | ||||||||||
| 29 | ([^\s\=]+) | ||||||||||
| 30 | \s* | ||||||||||
| 31 | }{}x | ||||||||||
| 32 | ) | ||||||||||
| 33 | { | ||||||||||
| 34 | 36 | $self->{'mappings'}->{$1} = $self->get_backup_or_variable($2); | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 21 | ▶ | if ( $string ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | die $self->get_parse_error( | ||||||||||
| 39 | "there is an error in `with` parameters" | ||||||||||
| 40 | 2 | , 'Passed parameters' => $self->{'parameter'} | |||||||||
| 41 | ); | ||||||||||
| 42 | } | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 20 | return $self; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | #@Override | ||||||||||
| 49 | sub render | ||||||||||
| 50 | { | ||||||||||
| 51 | 14 | ▶ | my $self = shift; | ||||||||
|
Subroutine
render: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 52 | 14 | my $context = shift; | |||||||||
| 53 | |||||||||||
| 54 | 14 | my %vars = (); | |||||||||
| 55 | 14 | foreach my $key (keys(%{$self->{'mappings'}})) | |||||||||
| 56 | { | ||||||||||
| 57 | 24 | $vars{$key} = $self->{'mappings'}->{$key}->render($context); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 14 | $context->push_scope()->set(%vars); | |||||||||
| 61 | |||||||||||
| 62 | 14 | my $result = $self->SUPER::render($context); | |||||||||
| 63 | |||||||||||
| 64 | 10 | $context->pop_scope(); | |||||||||
| 65 | |||||||||||
| 66 | 10 | return $result; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 4 | 1; | |||||||||