| 1 | package Template::Plex; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use version; our $VERSION = version->declare('v0.4.0'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use feature qw<say isa refaliasing>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | no warnings "experimental"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Log::OK; #Allow control of logging from the command line | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Symbol qw<delete_package>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use constant KEY_OFFSET=>0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | use enum ("plex_=0",qw<meta_ args_ sub_ package_ init_done_flag_ skip_ | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | cache_ | ||||||||||||||||||||||||||||
| 20 | slots_ parent_ default_result_ | ||||||||||||||||||||||||||||
| 21 | 1 | ▶ | >); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use constant KEY_COUNT=>default_result_ - plex_ +1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #Template::Plex::Internal uses the field name constants so import it AFTER | ||||||||||||||||||||||||||||
| 26 | #we define them | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Template::Plex::Internal; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | our %top_level_cache; | |||||||||||||||||||||||||||
| 30 | sub new { | ||||||||||||||||||||||||||||
| 31 | 4 | ▶ | my ($package, $plex)=@_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 4 | my $self=[]; | |||||||||||||||||||||||||||
| 33 | 4 | $self->[plex_]=$plex; | |||||||||||||||||||||||||||
| 34 | 4 | $self->[cache_]={}; | |||||||||||||||||||||||||||
| 35 | 4 | bless $self, $package; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | sub get_cache { | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $_[0][cache_]; | ||||||||||||||||||||||||||
|
Subroutine
get_cache: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | #Returns a template loaded and intialised | ||||||||||||||||||||||||||||
| 42 | sub load { | ||||||||||||||||||||||||||||
| 43 | 4 | ▶ | my ($self, $path, $vars, %opts)=@_; | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 4 | my $template; | |||||||||||||||||||||||||||
| 45 | 4 | ▶ | if(ref($self)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 3 | Log::OK::TRACE and log_trace __PACKAGE__." instance load called for $path"; | |||||||||||||||||||||||||||
| 47 | 3 | \my %fields=$self->args; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 3 | my %options=$self->meta->%{qw<root use base>}; #copy | |||||||||||||||||||||||||||
| 50 | 3 | ▶ | $template=Template::Plex::Internal->new(\&Template::Plex::Internal::_prepare_template, $path, $vars?$vars:\%fields, %opts?%opts:%options); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else{ | ||||||||||||||||||||||||||||
| 54 | 1 | Log::OK::TRACE and log_trace __PACKAGE__." class load called for $path"; | |||||||||||||||||||||||||||
| 55 | #called on package | ||||||||||||||||||||||||||||
| 56 | 1 | $template=Template::Plex::Internal->new(\&Template::Plex::Internal::_prepare_template, $path, $vars, %opts); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 4 | $template->setup; | |||||||||||||||||||||||||||
| 60 | 4 | $template; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | #Returns a template which was already loaded can called from the callers position | ||||||||||||||||||||||||||||
| 64 | sub cache { | ||||||||||||||||||||||||||||
| 65 | 1 | ▶ | my ($self, $id, $path, $vars, %opts)=@_; | ||||||||||||||||||||||||||
|
Subroutine
cache: called CC=7 SCAR=27.5
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 1 | Log::OK::TRACE and log_trace __PACKAGE__." cache: $path"; | |||||||||||||||||||||||||||
| 67 | 1 | ▶ | $id//=$path.join "", caller; #Set if undefined | ||||||||||||||||||||||||||
|
Condition33%1/3
$id //= $path . join("", caller)
MC/DC0%0/2
$id //= $path . join("", caller)
$id
$path . join("", caller)
Truth table33%1/3
A //= B
A= $idB= $path . join("", caller)
| |||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if(ref($self)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | $self->[cache_]{$id} and return $self->[cache_]{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | my $template=$self->load($path, $vars,%opts); | |||||||||||||||||||||||||||
| 72 | 1 | ▶ | $self->[cache_]{$id}//=$template; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->[7]{$id} //= $template
MC/DC0%0/2
$self->[7]{$id} //= $template
$self->[7]{$id}
$template
Truth table33%1/3
A //= B
A= $self->[7]{$id}B= $template
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | else{ | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $top_level_cache{$id} and return $top_level_cache{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my $template=$self->load($path, $vars,%opts); | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | $top_level_cache{$id}//=$template; | ||||||||||||||||||||||||||
|
Condition0%0/3
$Template::Plex::top_level_cache{$id} //= $template
MC/DC0%0/2
$Template::Plex::top_level_cache{$id} //= $template
$Template::Plex::top_level_cache{$id}
$template
Truth table0%0/3
A //= B
A= $Template::Plex::top_level_cache{$id}B= $template
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | sub immediate { | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my ($self, $id, $path, $vars, @opts)=@_; | ||||||||||||||||||||||||||
|
Subroutine
immediate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | Log::OK::TRACE and log_trace __PACKAGE__." cache: $path"; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | $id//=$path.join "", caller; #Set if undefined | ||||||||||||||||||||||||||
|
Condition0%0/3
$id //= $path . join("", caller)
MC/DC0%0/2
$id //= $path . join("", caller)
$id
$path . join("", caller)
Truth table0%0/3
A //= B
A= $idB= $path . join("", caller)
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my $template=$self->cache($id, $path, $vars,@opts); | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | return $template->render if $template; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ""; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub _plex_ { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $_[0][Template::Plex::plex_]; | ||||||||||||||||||||||||||
|
Subroutine
_plex_: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 5 | ▶ | sub meta :lvalue { $_[0][Template::Plex::meta_]; } | ||||||||||||||||||||||||||
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 5 | ▶ | sub args :lvalue{ $_[0][Template::Plex::args_]; } | ||||||||||||||||||||||||||
|
Subroutine
args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 10 | ▶ | sub init_done_flag:lvalue{ $_[0][Template::Plex::init_done_flag_]; } | ||||||||||||||||||||||||||
|
Subroutine
init_done_flag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub _render { | ||||||||||||||||||||||||||||
| 106 | #sub in plex requires self as first argument | ||||||||||||||||||||||||||||
| 107 | 8 | ▶ | return $_[0][sub_](@_); | ||||||||||||||||||||||||||
|
Subroutine
_render: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub skip { | ||||||||||||||||||||||||||||
| 111 | 4 | ▶ | Log::OK::DEBUG and log_debug("Template::Plex: Skipping Template: ".$_[0]->meta->{file}); | ||||||||||||||||||||||||||
|
Subroutine
skip: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 4 | $_[0]->[skip_]->(); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | #A call to this method will run the sub an preparation | ||||||||||||||||||||||||||||
| 116 | #and immediately stop rendering the template | ||||||||||||||||||||||||||||
| 117 | sub _init { | ||||||||||||||||||||||||||||
| 118 | 8 | ▶ | my ($self, $sub)=@_; | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 8 | ▶ | return if $self->[init_done_flag_]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 4 | Log::OK::DEBUG and log_debug("Template::Plex: Initalising Template: ".$self->meta->{file}); | |||||||||||||||||||||||||||
| 122 | 4 | ▶ | unless($self isa Template::Plex){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | #if($self->[meta_]{package} ne caller){ | ||||||||||||||||||||||||||||
| 124 | 0 | Log::OK::ERROR and log_error("Template::Plex: init must only be called within a template: ".$self->meta->{file}); | |||||||||||||||||||||||||||
| 125 | 0 | return; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 4 | $self->pre_init; | |||||||||||||||||||||||||||
| 129 | 4 | $sub->(); | |||||||||||||||||||||||||||
| 130 | 4 | $self->post_init; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 4 | $self->[init_done_flag_]=1; | |||||||||||||||||||||||||||
| 133 | 4 | $self->skip; | |||||||||||||||||||||||||||
| 134 | 0 | ""; #Must return an empty string | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | ▶ | sub pre_init { | |||||||||||||||||||||||||||
|
Subroutine
pre_init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | ▶ | sub post_init { | |||||||||||||||||||||||||||
|
Subroutine
post_init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | ▶ | sub prefix { | |||||||||||||||||||||||||||
|
Subroutine
prefix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | ▶ | sub postfix { | |||||||||||||||||||||||||||
|
Subroutine
postfix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | #Execute the template in setup mode | ||||||||||||||||||||||||||||
| 150 | sub setup { | ||||||||||||||||||||||||||||
| 151 | 4 | ▶ | my $self=shift; | ||||||||||||||||||||||||||
|
Subroutine
setup: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | #Test that the caller is not the template package | ||||||||||||||||||||||||||||
| 153 | 4 | Log::OK::DEBUG and log_debug("Template::Plex: Setup Template: ".$self->meta->{file}); | |||||||||||||||||||||||||||
| 154 | 4 | ▶ | if($self->[meta_]{package} eq caller){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | #Log::OK::ERROR and log_error("Template::Plex: setup must only be called outside a template: ".$self->meta->{file}); | ||||||||||||||||||||||||||||
| 156 | # return; | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | 4 | $self->[init_done_flag_]=undef; | |||||||||||||||||||||||||||
| 159 | 4 | $self->render(@_); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | #Check if an init block was used | ||||||||||||||||||||||||||||
| 162 | 4 | ▶ | unless($self->[init_done_flag_]){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | Log::OK::WARN and log_warn "Template::Plex ignoring no \@{[init{...}]} block in template from ". $self->meta->{file}; | |||||||||||||||||||||||||||
| 164 | 0 | $self->[init_done_flag_]=1; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | 4 | ""; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # Slotting and Inheritance | ||||||||||||||||||||||||||||
| 170 | # | ||||||||||||||||||||||||||||
| 171 | # | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | #Marks a slot in a parent template. | ||||||||||||||||||||||||||||
| 174 | #A child template can fill this out by calling fill_slot on the parent | ||||||||||||||||||||||||||||
| 175 | sub slot { | ||||||||||||||||||||||||||||
| 176 | 6 | ▶ | my ($self, $slot_name, $default_value)=@_; | ||||||||||||||||||||||||||
|
Subroutine
slot: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 6 | ▶ | $slot_name//="default"; #If no name assume default | ||||||||||||||||||||||||||
|
Condition100%2/2
$slot_name //= "default"
MC/DC100%1/1
$slot_name //= "default"
$slot_name
Truth table100%2/2
A
A= $slot_name
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 6 | Log::OK::TRACE and log_trace __PACKAGE__.": Template called slot: $slot_name"; | |||||||||||||||||||||||||||
| 180 | 6 | my $data=$self->[slots_]{$slot_name}; | |||||||||||||||||||||||||||
| 181 | 6 | my $output=""; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 6 | ▶ | $data//=$default_value; | ||||||||||||||||||||||||||
|
Condition66%2/3
$data //= $default_value
MC/DC0%0/2
$data //= $default_value
$data
$default_value
Truth table66%2/3
A //= B
A= $dataB= $default_value
| |||||||||||||||||||||||||||||
| 184 | 6 | ▶ | if($data isa Template::Plex){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | #render template | ||||||||||||||||||||||||||||
| 186 | 3 | ▶ | if($slot_name eq "default"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 2 | Log::OK::TRACE and log_trace __PACKAGE__.": copy default slot"; | |||||||||||||||||||||||||||
| 188 | 2 | ▶ | $output.=$self->[default_result_]//""; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->[10] // ""
MC/DC0%0/1
$self->[10] // ""
$self->[10]
Truth table50%1/2
A
A= $self->[10]
| |||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||
| 191 | 1 | Log::OK::TRACE and log_trace __PACKAGE__.": render non default template slot"; | |||||||||||||||||||||||||||
| 192 | 1 | $output.=$data->render; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | else { | ||||||||||||||||||||||||||||
| 196 | 3 | Log::OK::TRACE and log_trace __PACKAGE__.": render non template slot"; | |||||||||||||||||||||||||||
| 197 | #otherwise treat as text | ||||||||||||||||||||||||||||
| 198 | 3 | ▶ | $output.=$data//""; | ||||||||||||||||||||||||||
|
Condition50%1/2
$data // ""
MC/DC0%0/1
$data // ""
$data
Truth table50%1/2
A
A= $data
| |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | 6 | $output | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | sub fill_slot { | ||||||||||||||||||||||||||||
| 204 | 3 | ▶ | my ($self)=shift; | ||||||||||||||||||||||||||
|
Subroutine
fill_slot: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | 3 | my $parent=$self->[parent_]; | |||||||||||||||||||||||||||
| 206 | 3 | ▶ | unless($parent){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | Log::OK::WARN and log_warn __PACKAGE__.": No parent setup for: ". $self->meta->{file}; | |||||||||||||||||||||||||||
| 208 | 0 | return; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 3 | ▶ | unless(@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | #An unnamed fill spec implies the default slot | ||||||||||||||||||||||||||||
| 213 | 0 | $parent->[slots_]{default}=$self; | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | else{ | ||||||||||||||||||||||||||||
| 216 | 3 | for my ($k,$v)(@_){ | |||||||||||||||||||||||||||
| 217 | 3 | $parent->[slots_]{$k}=$v; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | 3 | ""; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | sub inherit { | ||||||||||||||||||||||||||||
| 225 | 2 | ▶ | my ($self, $path)=@_; | ||||||||||||||||||||||||||
|
Subroutine
inherit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | 2 | Log::OK::DEBUG and log_debug __PACKAGE__.": Inherit: $path"; | |||||||||||||||||||||||||||
| 227 | #If any parent variables have be setup load the parent template | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | #Setup the parent. Cached with path | ||||||||||||||||||||||||||||
| 230 | 2 | my $p=$self->load($path, $self->args, $self->meta->%*); | |||||||||||||||||||||||||||
| 231 | 2 | $p->[slots_]={}; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | #Add this template to the default slot | ||||||||||||||||||||||||||||
| 234 | 2 | $p->[slots_]{default}=$self; | |||||||||||||||||||||||||||
| 235 | 2 | $self->[parent_]=$p; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | sub render { | ||||||||||||||||||||||||||||
| 239 | 10 | ▶ | my ($self, $fields, $top_down)=@_; | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 240 | #We don't call parent render if we are uninitialised | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | #If the template uninitialized, we just do a first pass | ||||||||||||||||||||||||||||
| 245 | 10 | ▶ | unless($self->init_done_flag){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 4 | return $self->_render; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 6 | Log::OK::TRACE and log_trace __PACKAGE__.": render :".$self->meta->{file}." flag: ".($top_down//""); | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | #locate the 'top level' template and call downwards | ||||||||||||||||||||||||||||
| 254 | 6 | my $p=$self; | |||||||||||||||||||||||||||
| 255 | 6 | ▶ | if(!$top_down){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 2 | ▶ | while($p->[parent_]){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 2 | $p=$p->[parent_]; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | 2 | $p->render($fields,1); | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | else{ | ||||||||||||||||||||||||||||
| 262 | #This is Normal template or top of hierarchy | ||||||||||||||||||||||||||||
| 263 | #child has called parent and parent is the top | ||||||||||||||||||||||||||||
| 264 | # | ||||||||||||||||||||||||||||
| 265 | #Turn it around and call back down the chain | ||||||||||||||||||||||||||||
| 266 | # | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 4 | Log::OK::TRACE and log_trace __PACKAGE__.": render: no parent bottom up. assume normal render"; | |||||||||||||||||||||||||||
| 269 | #Check slots. Slots indicate we need to call the child first | ||||||||||||||||||||||||||||
| 270 | 4 | ▶ | if($self->[slots_] and $self->[slots_]->%*){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->[8] and %{$self->[8]}
MC/DC50%1/2
$self->[8] and %{$self->[8]}
$self->[8]
%{$self->[8]}
Truth table66%2/3
A and B
A= $self->[8]B= %{$self->[8]}
| |||||||||||||||||||||||||||||
| 271 | 2 | Log::OK::TRACE and log_trace __PACKAGE__.": render: rendering default slot"; | |||||||||||||||||||||||||||
| 272 | 2 | $self->[default_result_]=$self->[slots_]{default}->render($fields,1); | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | #now call render on self. This renders non hierarchial templates | ||||||||||||||||||||||||||||
| 276 | 4 | Log::OK::TRACE and log_trace __PACKAGE__.": render: rendering body and sub templates"; | |||||||||||||||||||||||||||
| 277 | 4 | my $total=$self->_render($fields); #Call down the chain with top_down flag | |||||||||||||||||||||||||||
| 278 | 4 | $self->[default_result_]=""; #Clear | |||||||||||||||||||||||||||
| 279 | 4 | return $total; | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub parent {$_[0][parent_];} | ||||||||||||||||||||||||||
|
Subroutine
parent: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | sub DESTROY { | ||||||||||||||||||||||||||||
| 292 | 0 | ▶ | delete_package $_[0][package_] if $_[0][package_]; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | #Internal testing use only | ||||||||||||||||||||||||||||
| 296 | sub __internal_test_proxy__ { | ||||||||||||||||||||||||||||
| 297 | 0 | ▶ | "PROXY"; | ||||||||||||||||||||||||||
|
Subroutine
__internal_test_proxy__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 1 | 1; | |||||||||||||||||||||||||||