| 1 | package Template::EmbeddedPerl::RenderFrame; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 276 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 7 | 276 | bless { | |||||||||||||||||||||||||||
| 8 | render_stack => [], | ||||||||||||||||||||||||||||
| 9 | named_content => {}, | ||||||||||||||||||||||||||||
| 10 | named_content_checkpoints => [], | ||||||||||||||||||||||||||||
| 11 | }, $_[0]; | ||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | 510 | ▶ | sub render_stack { $_[0]->{render_stack} } | ||||||||||||||||||||||||||
|
Subroutine
render_stack: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 407 | ▶ | sub current_scope { $_[0]->{render_stack}->[-1] } | ||||||||||||||||||||||||||
|
Subroutine
current_scope: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 432 | ▶ | sub push_render { | ||||||||||||||||||||||||||
|
Subroutine
push_render: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 432 | my ($self, %entry) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 432 | my $stack = $self->{render_stack}; | |||||||||||||||||||||||||||
| 20 | 432 | for my $index (0 .. $#$stack) { | |||||||||||||||||||||||||||
| 21 | 180 | my $active = $stack->[$index]; | |||||||||||||||||||||||||||
| 22 | 180 | ▶ | if (defined $entry{cycle_key}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | next unless defined($active->{cycle_key}) | ||||||||||||||||||||||||||||
| 24 | 59 | ▶ | && $active->{cycle_key} eq $entry{cycle_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $active->{"cycle_key"} and $active->{"cycle_key"} eq $entry{"cycle_key"}
MC/DC100%2/2
defined $active->{"cycle_key"} and $active->{"cycle_key"} eq $entry{"cycle_key"}
defined $active->{"cycle_key"}
$active->{"cycle_key"} eq $entry{"cycle_key"}
Truth table100%3/3
A and B
A= defined $active->{"cycle_key"}B= $active->{"cycle_key"} eq $entry{"cycle_key"}
| |||||||||||||||||||||||||||||
| 25 | } else { | ||||||||||||||||||||||||||||
| 26 | 121 | ▶ | next if defined $active->{cycle_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 86 | ▶ | next unless $active->{kind} eq $entry{kind}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 3 | ▶ | next unless $active->{identifier} eq $entry{identifier}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | my @cycle = (@$stack[$index .. $#$stack], \%entry); | |||||||||||||||||||||||||||
| 32 | die 'Render cycle detected: ' | ||||||||||||||||||||||||||||
| 33 | 3 | . join(' -> ', map { "$_->{kind} $_->{identifier}" } @cycle) | |||||||||||||||||||||||||||
| 34 | . "\n"; | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 429 | $entry{layouts} = []; | |||||||||||||||||||||||||||
| 38 | 429 | push @{$self->{named_content_checkpoints}}, { | |||||||||||||||||||||||||||
| 39 | 47 | map { $_ => [@{$self->{named_content}{$_}}] } | |||||||||||||||||||||||||||
| 40 | 429 | keys %{$self->{named_content}} | |||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | 429 | push @$stack, \%entry; | |||||||||||||||||||||||||||
| 43 | 429 | return \%entry; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 429 | ▶ | sub pop_render { | ||||||||||||||||||||||||||
|
Subroutine
pop_render: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 429 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 48 | 429 | my $entry = pop @{$self->{render_stack}}; | |||||||||||||||||||||||||||
| 49 | 429 | my $named_content_checkpoint = pop @{$self->{named_content_checkpoints}}; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 429 | ▶ | if ($args{failed}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 111 | ▶ | if (@{$self->{render_stack}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 30 | $self->{named_content} = $named_content_checkpoint; | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 81 | $self->{named_content} = {}; | |||||||||||||||||||||||||||
| 56 | 81 | delete $self->{default_body}; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 429 | return $entry; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 40 | ▶ | sub register_layout { | ||||||||||||||||||||||||||
|
Subroutine
register_layout: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 40 | my ($self, $identifier, @args) = @_; | |||||||||||||||||||||||||||
| 65 | 40 | push @{$self->current_scope->{layouts}}, [$identifier, \@args]; | |||||||||||||||||||||||||||
| 66 | 40 | return; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 290 | ▶ | sub take_layouts { | ||||||||||||||||||||||||||
|
Subroutine
take_layouts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 290 | my ($self) = @_; | |||||||||||||||||||||||||||
| 71 | 290 | my @layouts = splice @{$self->current_scope->{layouts}}; | |||||||||||||||||||||||||||
| 72 | 290 | return \@layouts; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 68 | ▶ | sub with_transaction { | ||||||||||||||||||||||||||
|
Subroutine
with_transaction: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 68 | my ($self, $callback) = @_; | |||||||||||||||||||||||||||
| 77 | my $named_content = { | ||||||||||||||||||||||||||||
| 78 | 7 | map { $_ => [@{$self->{named_content}{$_}}] } | |||||||||||||||||||||||||||
| 79 | 68 | keys %{$self->{named_content}} | |||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||
| 81 | 68 | my $scope = $self->current_scope; | |||||||||||||||||||||||||||
| 82 | 68 | ▶ | my $layouts = $scope ? [@{$scope->{layouts}}] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 68 | my $had_default_body = exists $self->{default_body}; | |||||||||||||||||||||||||||
| 84 | 68 | my $default_body = $self->{default_body}; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 68 | my ($ok, $output, $error); | |||||||||||||||||||||||||||
| 87 | 68 | $ok = eval { | |||||||||||||||||||||||||||
| 88 | 68 | $output = $callback->(); | |||||||||||||||||||||||||||
| 89 | 42 | 1; | |||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||
| 91 | 68 | ▶ | $error = $@ unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 68 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 26 | $self->{named_content} = $named_content; | |||||||||||||||||||||||||||
| 95 | 26 | ▶ | $scope->{layouts} = $layouts if $scope; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 26 | ▶ | if ($had_default_body) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 4 | $self->{default_body} = $default_body; | |||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||
| 99 | 22 | delete $self->{default_body}; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 26 | die $error; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 42 | return $output; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 93 | ▶ | sub with_body { | ||||||||||||||||||||||||||
|
Subroutine
with_body: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 108 | 93 | my ($self, $body, $callback) = @_; | |||||||||||||||||||||||||||
| 109 | 93 | local $self->{default_body} = $body; | |||||||||||||||||||||||||||
| 110 | 93 | return $callback->(); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 65 | ▶ | sub default_body { | ||||||||||||||||||||||||||
|
Subroutine
default_body: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 65 | my ($self) = @_; | |||||||||||||||||||||||||||
| 115 | 65 | ▶ | return defined($self->{default_body}) ? $self->{default_body} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 34 | ▶ | sub append_content { | ||||||||||||||||||||||||||
|
Subroutine
append_content: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 34 | my ($self, $name, $value) = @_; | |||||||||||||||||||||||||||
| 120 | 34 | push @{$self->{named_content}{$name}}, $value; | |||||||||||||||||||||||||||
| 121 | 34 | return; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 13 | ▶ | sub replace_content { | ||||||||||||||||||||||||||
|
Subroutine
replace_content: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | 13 | my ($self, $name, $value) = @_; | |||||||||||||||||||||||||||
| 126 | 13 | $self->{named_content}{$name} = [$value]; | |||||||||||||||||||||||||||
| 127 | 13 | return; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 90 | ▶ | sub content { | ||||||||||||||||||||||||||
|
Subroutine
content: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 131 | 90 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 132 | 90 | ▶ | return join '', @{$self->{named_content}{$name} || []}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'named_content'}{$name} || []
MC/DC100%1/1
$self->{'named_content'}{$name} || []
$self->{'named_content'}{$name}
Truth table100%2/2
A
A= $self->{'named_content'}{$name}
| |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 13 | ▶ | sub has_content { | ||||||||||||||||||||||||||
|
Subroutine
has_content: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 13 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 137 | 13 | ▶ | return length $self->content($name) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 24 | 1; | |||||||||||||||||||||||||||