| 1 | # Copyrights 2003,2007-2021 by [Mark Overmeer]. | ||||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||||||||
| 5 | # This code is part of perl distribution OODoc-Template. It is licensed under | ||||||||||||||||||||||||||||||||||
| 6 | # the same terms as Perl itself: https://spdx.org/licenses/Artistic-2.0.html | ||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | package OODoc::Template; | ||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 10 | $VERSION = '0.17'; | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 10 | ▶ | use Log::Report 'oodoc-template'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use IO::File (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | use Data::Dumper qw(Dumper); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 10 | my @default_markers = ('<!--{', '}-->', '<!--{/', '}-->'); | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | sub new(@) | ||||||||||||||||||||||||||||||||||
| 27 | 11 | ▶ | { my ($class, %args) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 28 | 11 | (bless {}, $class)->init(\%args); | |||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | sub init($) | ||||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 11 | $self->{cached} = {}; | |||||||||||||||||||||||||||||||||
| 35 | 11 | $self->{macros} = {}; | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 11 | my $s = $self; weaken $s; # avoid circular ref | |||||||||||||||||||||||||||||||||
| 38 | 11 | ▶ | $args->{template} ||= sub { $s->includeTemplate(@_) }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$args->{"template"} ||= sub {
$s->includeTemplate(@_);
}
MC/DC0%0/2
$args->{"template"} ||= sub {
$s->includeTemplate(@_);
}
$args->{"template"}
sub {
$s->includeTemplate(@_);
}
Truth table33%1/3
A ||= B
A= $args->{"template"}B= sub {
$s->includeTemplate(@_);
}
| |||||||||||||||||||||||||||||||||||
| 39 | 11 | ▶ | $args->{macro} ||= sub { $s->defineMacro(@_) }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$args->{"macro"} ||= sub {
$s->defineMacro(@_);
}
MC/DC0%0/2
$args->{"macro"} ||= sub {
$s->defineMacro(@_);
}
$args->{"macro"}
sub {
$s->defineMacro(@_);
}
Truth table33%1/3
A ||= B
A= $args->{"macro"}B= sub {
$s->defineMacro(@_);
}
| |||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 11 | ▶ | $args->{search} ||= '.'; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"search"} ||= "."
MC/DC100%1/1
$args->{"search"} ||= "."
$args->{"search"}
Truth table100%2/2
A
A= $args->{"search"}
| |||||||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | $args->{markers} ||= \@default_markers; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"markers"} ||= \@default_markers
MC/DC100%1/1
$args->{"markers"} ||= \@default_markers
$args->{"markers"}
Truth table100%2/2
A
A= $args->{"markers"}
| |||||||||||||||||||||||||||||||||||
| 43 | 11 | ▶ | $args->{define} ||= sub { shift; (1, @_) }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.4
Condition33%1/3
$args->{"define"} ||= sub {
shift();
1, @_;
}
MC/DC0%0/2
$args->{"define"} ||= sub {
shift();
1, @_;
}
$args->{"define"}
sub {
shift();
1, @_;
}
Truth table33%1/3
A ||= B
A= $args->{"define"}B= sub {
shift();
1, @_;
}
| |||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 11 | $self->pushValues($args); | |||||||||||||||||||||||||||||||||
| 46 | 11 | $self; | |||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | sub process($) | ||||||||||||||||||||||||||||||||||
| 51 | 111 | ▶ | { my ($self, $templ) = (shift, shift); | ||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=31 SCAR=34.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 111 | ▶ | my $values = @_==1 ? shift : @_ ? {@_} : {}; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 111 | ▶ | my $tree # parse with real copy | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 56 | = ref $templ eq 'SCALAR' ? $self->parseTemplate($$templ) | ||||||||||||||||||||||||||||||||||
| 57 | : ref $templ eq 'ARRAY' ? $templ | ||||||||||||||||||||||||||||||||||
| 58 | : $self->parseTemplate("$templ"); | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 111 | ▶ | defined $tree | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | or return (); | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 111 | ▶ | $self->pushValues($values) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | if keys %$values; | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 111 | my @output; | |||||||||||||||||||||||||||||||||
| 67 | 111 | foreach my $node (@$tree) | |||||||||||||||||||||||||||||||||
| 68 | 337 | ▶ | { unless(ref $node) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | 224 | { push @output, $node; | |||||||||||||||||||||||||||||||||
| 70 | 224 | next; | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 113 | my ($tag, $attr, $then, $else) = @$node; | |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | 113 | my %attrs; | |||||||||||||||||||||||||||||||||
| 76 | 113 | ▶ | while(my($k, $v) = each %$attr) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | { $attrs{$k} = ref $v ne 'ARRAY' ? $v | ||||||||||||||||||||||||||||||||||
| 78 | 5 | : @$v==1 ? scalar $self->valueFor(@{$v->[0]}) | |||||||||||||||||||||||||||||||||
| 79 | : join '', | ||||||||||||||||||||||||||||||||||
| 80 | 53 | ▶ | map {ref $_ eq 'ARRAY' ? scalar $self->valueFor(@$_) : $_} | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 81 | @$v; | ||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 113 | (my $value, my $attrs, $then, $else) | |||||||||||||||||||||||||||||||||
| 85 | = $self->valueFor($tag, \%attrs, $then, $else); | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 113 | ▶ | unless(defined $then || defined $else) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $then or defined $else
MC/DC100%2/2
defined $then or defined $else
defined $then
defined $else
Truth table100%3/3
A or B
A= defined $thenB= defined $else
| |||||||||||||||||||||||||||||||||||
| 88 | 74 | ▶ | { defined $value | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 89 | or next; | ||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | 60 | ▶ | ref $value ne 'ARRAY' && ref $value ne 'HASH' | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value ne "ARRAY" and ref $value ne "HASH"
MC/DC0%0/2
ref $value ne "ARRAY" and ref $value ne "HASH"
ref $value ne "ARRAY"
ref $value ne "HASH"
Truth table33%1/3
A and B
A= ref $value ne "ARRAY"B= ref $value ne "HASH"
| |||||||||||||||||||||||||||||||||||
| 92 | or error __x"value for {tag} is {value}, must be single" | ||||||||||||||||||||||||||||||||||
| 93 | , tag => $tag, value => $value; | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 60 | push @output, $value; | |||||||||||||||||||||||||||||||||
| 96 | 60 | next; | |||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 39 | ▶ | my $take_else | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
!defined($value) || ref $value eq 'ARRAY' && @$value == 0
ref $value eq "ARRAY" and @$value == 0
MC/DC100%3/3
!defined($value) || ref $value eq 'ARRAY' && @$value == 0
!defined($value)
ref $value eq "ARRAY"
@$value == 0
Truth table100%4/4
not(A) || B and C
A= !defined($value)B= ref $value eq "ARRAY"C= @$value == 0
| |||||||||||||||||||||||||||||||||||
| 100 | = !defined $value || (ref $value eq 'ARRAY' && @$value==0); | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | 39 | ▶ | my $container = $take_else ? $else : $then; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 39 | ▶ | defined $container | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 105 | or next; | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | 27 | ▶ | $self->pushValues($attrs) if keys %$attrs; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 27 | ▶ | if($take_else) | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 110 | 6 | { my ($nest_out, $nest_tree) = $self->process($container); | |||||||||||||||||||||||||||||||||
| 111 | 6 | push @output, $nest_out; | |||||||||||||||||||||||||||||||||
| 112 | 6 | $node->[3] = $nest_tree; | |||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||
| 114 | elsif(ref $value eq 'HASH') | ||||||||||||||||||||||||||||||||||
| 115 | 3 | { my ($nest_out, $nest_tree) = $self->process($container, $value); | |||||||||||||||||||||||||||||||||
| 116 | 3 | push @output, $nest_out; | |||||||||||||||||||||||||||||||||
| 117 | 3 | $node->[2] = $nest_tree; | |||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | elsif(ref $value eq 'ARRAY') | ||||||||||||||||||||||||||||||||||
| 120 | 11 | { foreach my $data (@$value) | |||||||||||||||||||||||||||||||||
| 121 | 16 | { my ($nest_out, $nest_tree) = $self->process($container, $data); | |||||||||||||||||||||||||||||||||
| 122 | 16 | push @output, $nest_out; | |||||||||||||||||||||||||||||||||
| 123 | 16 | $node->[2] = $nest_tree; | |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||
| 126 | else | ||||||||||||||||||||||||||||||||||
| 127 | 7 | { my ($nest_out, $nest_tree) = $self->process($container); | |||||||||||||||||||||||||||||||||
| 128 | 7 | push @output, $nest_out; | |||||||||||||||||||||||||||||||||
| 129 | 7 | $node->[2] = $nest_tree; | |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 27 | ▶ | $self->popValues if keys %$attrs; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | 111 | ▶ | $self->popValues if keys %$values; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||
| 137 | 111 | ▶ | wantarray ? (join('', @output), $tree) # LIST context | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 138 | : defined wantarray ? join('', @output) # SCALAR context | ||||||||||||||||||||||||||||||||||
| 139 | : print @output; # VOID context | ||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | sub processFile($;@) | ||||||||||||||||||||||||||||||||||
| 144 | 6 | ▶ | { my ($self, $filename) = (shift, shift); | ||||||||||||||||||||||||||||||||
|
Subroutine
processFile: called CC=10 SCAR=23.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 6 | ▶ | my $values = @_==1 ? shift : {@_}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 147 | 6 | ▶ | $values->{source} ||= $filename; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$values->{"source"} ||= $filename
MC/DC0%0/2
$values->{"source"} ||= $filename
$values->{"source"}
$filename
Truth table66%2/3
A ||= B
A= $values->{"source"}B= $filename
| |||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | 6 | my $cache = $self->{cached}; | |||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | 6 | my ($output, $tree, $template); | |||||||||||||||||||||||||||||||||
| 152 | 6 | ▶ | if(exists $cache->{$filename}) | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 153 | 4 | { $tree = $cache->{$filename}; | |||||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | $output = $self->process($tree, $values) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 155 | if defined $tree; | ||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | elsif($template = $self->loadFile($filename)) | ||||||||||||||||||||||||||||||||||
| 158 | 1 | { ($output, $tree) = $self->process($template, $values); | |||||||||||||||||||||||||||||||||
| 159 | 1 | $cache->{$filename} = $tree; | |||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||
| 161 | else | ||||||||||||||||||||||||||||||||||
| 162 | 1 | { $tree = $cache->{$filename} = undef; | |||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 6 | ▶ | defined $tree || defined wantarray | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $tree or defined wantarray
MC/DC0%0/2
defined $tree or defined wantarray
defined $tree
defined wantarray
Truth table66%2/3
A or B
A= defined $treeB= defined wantarray
| |||||||||||||||||||||||||||||||||||
| 166 | or error __x"cannot find template file {fn}", fn => $filename; | ||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||
| 168 | 6 | ▶ | wantarray ? ($output, $tree) # LIST context | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 169 | : defined wantarray ? $output # SCALAR context | ||||||||||||||||||||||||||||||||||
| 170 | : print $output; # VOID context | ||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||
| 174 | sub defineMacro($$$$) | ||||||||||||||||||||||||||||||||||
| 175 | 1 | ▶ | { my ($self, $tag, $attrs, $then, $else) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
defineMacro: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 176 | my $name = delete $attrs->{name} | ||||||||||||||||||||||||||||||||||
| 177 | 1 | ▶ | or error __x"macro requires a name"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | defined $else | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 180 | and error __x"macros cannot have an else part ({macro})",macro => $name; | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | 1 | my %attrs = %$attrs; # for closure | |||||||||||||||||||||||||||||||||
| 183 | 1 | $attrs{markers} = $self->valueFor('markers'); | |||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | $self->{macros}{$name} = | ||||||||||||||||||||||||||||||||||
| 186 | 2 | ▶ | sub { my ($tag, $at) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 187 | 2 | $self->process($then, +{%attrs, %$at}); | |||||||||||||||||||||||||||||||||
| 188 | 1 | }; | |||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 1 | (); | |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | sub valueFor($;$$$) | ||||||||||||||||||||||||||||||||||
| 196 | 235 | ▶ | { my ($self, $tag, $attrs, $then, $else) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
valueFor: called CC=12 SCAR=26.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | #warn "Looking for $tag"; | ||||||||||||||||||||||||||||||||||
| 199 | #warn Dumper $self->{values}; | ||||||||||||||||||||||||||||||||||
| 200 | 235 | ▶ | for(my $set = $self->{values}; defined $set; $set = $set->{NEXT}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 201 | 283 | { my $v = $set->{$tag}; | |||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | 283 | ▶ | if(defined $v) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 204 | { # HASH defines container | ||||||||||||||||||||||||||||||||||
| 205 | # ARRAY defines container loop | ||||||||||||||||||||||||||||||||||
| 206 | # object or other things can be stored as well, but may get | ||||||||||||||||||||||||||||||||||
| 207 | # stringified. | ||||||||||||||||||||||||||||||||||
| 208 | 211 | ▶ | return wantarray ? ($v, $attrs, $then, $else) : $v | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 209 | if ref $v ne 'CODE'; | ||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | return wantarray | ||||||||||||||||||||||||||||||||||
| 212 | 33 | ▶ | ? $v->($tag, $attrs, $then, $else) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 213 | : ($v->($tag, $attrs, $then, $else))[0] | ||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | return wantarray ? (undef, $attrs, $then, $else) : undef | ||||||||||||||||||||||||||||||||||
| 217 | 72 | ▶ | if exists $set->{$tag}; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 68 | my $code = $set->{DYNAMIC}; | |||||||||||||||||||||||||||||||||
| 220 | 68 | ▶ | if(defined $code) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 221 | 0 | { my ($value, @other) = $code->($tag, $attrs, $then, $else); | |||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | return wantarray ? ($value, @other) : $value | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 223 | if defined $value; | ||||||||||||||||||||||||||||||||||
| 224 | # and continue the search otherwise | ||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||
| 228 | 20 | ▶ | wantarray ? (undef, $attrs, $then, $else) : undef; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||
| 232 | sub allValuesFor($;$$$) | ||||||||||||||||||||||||||||||||||
| 233 | 2 | ▶ | { my ($self, $tag, $attrs, $then, $else) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
allValuesFor: called CC=7 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 234 | 2 | my @values; | |||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | 2 | ▶ | for(my $set = $self->{values}; defined $set; $set = $set->{NEXT}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 237 | { | ||||||||||||||||||||||||||||||||||
| 238 | 4 | ▶ | if(defined(my $v = $set->{$tag})) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 239 | 2 | ▶ | { my $t = ref $v eq 'CODE' ? $v->($tag, $attrs, $then, $else) : $v; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | push @values, $t if defined $t; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | if(defined(my $code = $set->{DYNAMIC})) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | 0 | { my $t = $code->($tag, $attrs, $then, $else); | |||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | push @values, $t if defined $t; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||
| 249 | 2 | @values; | |||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||
| 253 | sub pushValues($) | ||||||||||||||||||||||||||||||||||
| 254 | 68 | ▶ | { my ($self, $attrs) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
pushValues: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | 68 | ▶ | if(my $markers = $attrs->{markers}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 257 | { my @markers = ref $markers eq 'ARRAY' ? @$markers | ||||||||||||||||||||||||||||||||||
| 258 | 14 | ▶ | : map {s/\\\,//g; $_} split /(?!<\\)\,\s*/, $markers; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||
| 260 | 14 | ▶ | push @markers, $markers[0] . '/' | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 261 | if @markers==2; | ||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||
| 263 | 14 | ▶ | push @markers, $markers[1] | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 264 | if @markers==3; | ||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||
| 266 | $attrs->{markers} | ||||||||||||||||||||||||||||||||||
| 267 | 14 | ▶ | = [ map { ref $_ eq 'Regexp' ? $_ : qr/\Q$_/ } @markers ]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||
| 270 | 68 | ▶ | if(my $search = $attrs->{search}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 271 | 11 | ▶ | { $attrs->{search} = [ split /\:/, $search ] | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 272 | if ref $search ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||
| 275 | 68 | $self->{values} = { %$attrs, NEXT => $self->{values} }; | |||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | sub popValues() | ||||||||||||||||||||||||||||||||||
| 280 | 57 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
popValues: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 281 | 57 | $self->{values} = $self->{values}{NEXT}; | |||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | sub includeTemplate($$$) | ||||||||||||||||||||||||||||||||||
| 286 | 7 | ▶ | { my ($self, $tag, $attrs, $then, $else) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
includeTemplate: called CC=10 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||
| 288 | 7 | ▶ | defined $then || defined $else | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $then or defined $else
MC/DC0%0/2
defined $then or defined $else
defined $then
defined $else
Truth table33%1/3
A or B
A= defined $thenB= defined $else
| |||||||||||||||||||||||||||||||||||
| 289 | and error __x"template is not a container"; | ||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | 7 | ▶ | if(my $fn = $attrs->{file}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 292 | 5 | { my $output = $self->processFile($fn, $attrs); | |||||||||||||||||||||||||||||||||
| 293 | $output = $self->processFile($attrs->{alt}, $attrs) | ||||||||||||||||||||||||||||||||||
| 294 | 5 | ▶ | if !defined $output && $attrs->{alt}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $output and $attrs->{"alt"}
MC/DC50%1/2
not defined $output and $attrs->{"alt"}
not defined $output
$attrs->{"alt"}
Truth table66%2/3
not(A) and B
A= not defined $outputB= $attrs->{"alt"}
| |||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | 5 | ▶ | defined $output | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 297 | or error __x"cannot find template file {fn}", fn => $fn; | ||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | 5 | return ($output); | |||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||
| 302 | 2 | ▶ | if(my $name = $attrs->{macro}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 303 | 2 | ▶ | { my $macro = $self->{macros}{$name} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 304 | or error __x"cannot find macro {name}", name => $name; | ||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||
| 306 | 2 | return $macro->($tag, $attrs, $then, $else); | |||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | error __x"file or macro attribute required for template in {source}" | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->valueFor('source') || '??'
MC/DC0%0/1
$self->valueFor('source') || '??'
$self->valueFor('source')
Truth table0%0/2
A
A= $self->valueFor('source')
| |||||||||||||||||||||||||||||||||||
| 310 | , source => $self->valueFor('source') || '??'; | ||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||
| 314 | sub loadFile($) | ||||||||||||||||||||||||||||||||||
| 315 | 2 | ▶ | { my ($self, $relfn) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
loadFile: called CC=9 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 316 | 2 | my $absfn; | |||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||
| 318 | 2 | ▶ | if(File::Spec->file_name_is_absolute($relfn)) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 319 | 0 | { my $fn = File::Spec->canonpath($relfn); | |||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | $absfn = $fn if -f $fn; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | 2 | ▶ | unless($absfn) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 324 | 2 | { my @srcs = map { @$_ } $self->allValuesFor('search'); | |||||||||||||||||||||||||||||||||
| 325 | 2 | foreach my $dir (@srcs) | |||||||||||||||||||||||||||||||||
| 326 | 3 | { $absfn = File::Spec->rel2abs($relfn, $dir); | |||||||||||||||||||||||||||||||||
| 327 | 3 | ▶ | last if -f $absfn; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 328 | 2 | $absfn = undef; | |||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | 2 | ▶ | defined $absfn | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 333 | or return undef; | ||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||
| 335 | 1 | my $in = IO::File->new($absfn, 'r'); | |||||||||||||||||||||||||||||||||
| 336 | 1 | ▶ | unless(defined $in) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | { my $source = $self->valueFor('source') || '??'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->valueFor('source') || '??'
MC/DC0%0/1
$self->valueFor('source') || '??'
$self->valueFor('source')
Truth table0%0/2
A
A= $self->valueFor('source')
| |||||||||||||||||||||||||||||||||||
| 338 | 0 | fault __x"Cannot read from {fn} in {file}", fn => $absfn, file=>$source; | |||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||
| 341 | 1 | \(join '', $in->getlines); # auto-close in | |||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||
| 345 | sub parse($@) | ||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | { my ($self, $template) = (shift, shift); | ||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 347 | 0 | $self->process(\$template, @_); | |||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||
| 351 | sub parseTemplate($) | ||||||||||||||||||||||||||||||||||
| 352 | 105 | ▶ | { my ($self, $template) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
parseTemplate: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||
| 354 | 105 | ▶ | defined $template | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 355 | or return undef; | ||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||
| 357 | 105 | my $markers = $self->valueFor('markers'); | |||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||
| 359 | # Remove white-space escapes | ||||||||||||||||||||||||||||||||||
| 360 | 105 | $template =~ s! \\ (?: \s* (?: \\ \s*)? \n)+ | |||||||||||||||||||||||||||||||||
| 361 | (?: \s* (?= $markers->[0] | $markers->[3] ))? | ||||||||||||||||||||||||||||||||||
| 362 | !!mgx; | ||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||
| 364 | 105 | my @frags; | |||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||
| 366 | # NOT_$tag supported for backwards compat | ||||||||||||||||||||||||||||||||||
| 367 | 105 | ▶ | while( $template =~ s!^(.*?) # text before container | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 368 | $markers->[0] \s* | ||||||||||||||||||||||||||||||||||
| 369 | (?: IF \s* )? | ||||||||||||||||||||||||||||||||||
| 370 | (NOT (?:_|\s+) )? | ||||||||||||||||||||||||||||||||||
| 371 | ([\w.-]+) \s* # tag | ||||||||||||||||||||||||||||||||||
| 372 | (.*?) \s* # attributes | ||||||||||||||||||||||||||||||||||
| 373 | $markers->[1] | ||||||||||||||||||||||||||||||||||
| 374 | !!xs | ||||||||||||||||||||||||||||||||||
| 375 | ) | ||||||||||||||||||||||||||||||||||
| 376 | 109 | { push @frags, $1; | |||||||||||||||||||||||||||||||||
| 377 | 109 | my ($not, $tag, $attr) = ($2, $3, $4); | |||||||||||||||||||||||||||||||||
| 378 | 109 | my ($then, $else); | |||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||
| 380 | 109 | ▶ | if($template =~ s! (.*?) # contained | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 381 | ( $markers->[2] | ||||||||||||||||||||||||||||||||||
| 382 | \s* \Q$tag\E \s* # "our" tag | ||||||||||||||||||||||||||||||||||
| 383 | $markers->[3] | ||||||||||||||||||||||||||||||||||
| 384 | ) | ||||||||||||||||||||||||||||||||||
| 385 | !!xs) | ||||||||||||||||||||||||||||||||||
| 386 | 40 | { $then = $1; | |||||||||||||||||||||||||||||||||
| 387 | 40 | my $endline = $2; | |||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||
| 390 | 109 | ▶ | if($not) { ($then, $else) = (undef, $then) } | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 391 | elsif(!defined $then) { } | ||||||||||||||||||||||||||||||||||
| 392 | elsif($then =~ s! $markers->[0] | ||||||||||||||||||||||||||||||||||
| 393 | \s* ELSE (?:_|\s+) | ||||||||||||||||||||||||||||||||||
| 394 | \Q$tag\E \s* | ||||||||||||||||||||||||||||||||||
| 395 | $markers->[1] | ||||||||||||||||||||||||||||||||||
| 396 | (.*) | ||||||||||||||||||||||||||||||||||
| 397 | !!xs) | ||||||||||||||||||||||||||||||||||
| 398 | { # ELSE_$tag for backwards compat | ||||||||||||||||||||||||||||||||||
| 399 | 5 | $else = $1; | |||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||
| 402 | 109 | push @frags, [$tag, $self->parseAttrs($attr), $then, $else]; | |||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||
| 405 | 105 | push @frags, $template; | |||||||||||||||||||||||||||||||||
| 406 | 105 | \@frags; | |||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||
| 410 | sub parseAttrs($) | ||||||||||||||||||||||||||||||||||
| 411 | 113 | ▶ | { my ($self, $string) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
parseAttrs: called CC=13 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | 113 | my %attrs; | |||||||||||||||||||||||||||||||||
| 414 | 113 | ▶ | while( $string =~ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 415 | s!^\s* (?: '([^']+)' # attribute name (might be quoted) | ||||||||||||||||||||||||||||||||||
| 416 | | "([^"]+)" | ||||||||||||||||||||||||||||||||||
| 417 | | (\w+) | ||||||||||||||||||||||||||||||||||
| 418 | ) | ||||||||||||||||||||||||||||||||||
| 419 | \s* (?: \= \>? \s* # an optional value | ||||||||||||||||||||||||||||||||||
| 420 | ( \"[^"]*\" # dquoted value | ||||||||||||||||||||||||||||||||||
| 421 | | \'[^']*\' # squoted value | ||||||||||||||||||||||||||||||||||
| 422 | | \$\{ [^}]+ \} # complex variable | ||||||||||||||||||||||||||||||||||
| 423 | | [^\s,]+ # unquoted value | ||||||||||||||||||||||||||||||||||
| 424 | ) | ||||||||||||||||||||||||||||||||||
| 425 | )? | ||||||||||||||||||||||||||||||||||
| 426 | \s* \,? # optionally separated by commas | ||||||||||||||||||||||||||||||||||
| 427 | !!xs) | ||||||||||||||||||||||||||||||||||
| 428 | 57 | ▶ | { my ($k, $v) = ($1||$2||$3, $4); | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$1 || $2 || $3
$1 or $2
MC/DC0%0/3
$1 || $2 || $3
$1
$2
$3
Truth table25%1/4
A or B || C
A= $1B= $2C= $3
| |||||||||||||||||||||||||||||||||||
| 429 | 57 | ▶ | unless(defined $v) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 430 | 11 | { $attrs{$k} = 1; | |||||||||||||||||||||||||||||||||
| 431 | 11 | next; | |||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||
| 434 | 46 | ▶ | if($v =~ m/^\'(.*)\'$/) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 435 | { # Single quoted parameter, no interpolation | ||||||||||||||||||||||||||||||||||
| 436 | 11 | $attrs{$k} = $1; | |||||||||||||||||||||||||||||||||
| 437 | 11 | next; | |||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||
| 440 | 35 | $v =~ s/^\"(.*)\"$/$1/; | |||||||||||||||||||||||||||||||||
| 441 | 35 | my @v = split /( \$\{[^\}]+\} | \$\w+ )/x, $v; | |||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||
| 443 | 35 | ▶ | if(@v==1 && $v[0] !~ m/^\$/) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@v == 1 and not $v[0] =~ /^\$/
MC/DC50%1/2
@v == 1 and not $v[0] =~ /^\$/
@v == 1
not $v[0] =~ /^\$/
Truth table66%2/3
A and not(B)
A= @v == 1B= not $v[0] =~ /^\$/
| |||||||||||||||||||||||||||||||||||
| 444 | 23 | { $attrs{$k} = $v[0]; | |||||||||||||||||||||||||||||||||
| 445 | 23 | next; | |||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||
| 448 | 12 | my @steps; | |||||||||||||||||||||||||||||||||
| 449 | 12 | foreach (@v) | |||||||||||||||||||||||||||||||||
| 450 | 36 | ▶ | { if( m/^ (?: \$(\w+) | \$\{ (\w+) \s* \} ) $/x ) | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 451 | 12 | { push @steps, [ $+ ]; | |||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||
| 453 | elsif( m/^ \$\{ (\w+) \s* ([^\}]+? \s* ) \} $/x ) | ||||||||||||||||||||||||||||||||||
| 454 | 4 | { push @steps, [ $1, $self->parseAttrs($2) ]; | |||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||
| 456 | else | ||||||||||||||||||||||||||||||||||
| 457 | 20 | ▶ | { push @steps, $_ if length $_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||
| 461 | 12 | $attrs{$k} = \@steps; | |||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||
| 464 | 113 | ▶ | error __x"attribute error in '{tag}'", tag => $_[1] | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 465 | if length $string; | ||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||
| 467 | 113 | \%attrs; | |||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||
| 471 | 10 | 1; | |||||||||||||||||||||||||||||||||