| 1 | package Template::EmbeddedPerl::Arguments; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 24 | ▶ | use PPI::Document; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 24 | my %RESERVED_ARGUMENT = map { $_ => 1 } qw(__named_args __context _O self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 366 | ▶ | sub rewrite { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rewrite: called CC=18 SCAR=29.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 366 | my ($class, $template, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 366 | ▶ | my $comment_mark = exists $args{comment_mark} ? $args{comment_mark} : '#'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 366 | ▶ | my $line_start = exists $args{line_start} ? $args{line_start} : '%'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 366 | ▶ | my $open_tag = exists $args{open_tag} ? $args{open_tag} : '<%'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 366 | ▶ | my $close_tag = exists $args{close_tag} ? $args{close_tag} : '%>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 366 | my @lines = $template =~ /.*?(?:\n|\z)/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 366 | ▶ | pop @lines if @lines && $lines[-1] eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@lines and $lines[-1] eq ""
MC/DC0%0/2
@lines and $lines[-1] eq ""
@lines
$lines[-1] eq ""
Truth table33%1/3
A and B
A= @linesB= $lines[-1] eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | my @directive_lines = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 366 | $lines[$_] =~ /^[ \t]*\Q$line_start\E[ \t]+args(?:[ \t]|\n|\z)/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } 0 .. $#lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 366 | ▶ | return ($template, 0) unless @directive_lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 67 | my $start = $directive_lines[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 67 | for my $line_number (0 .. $start - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | next if $lines[$line_number] =~ /^[ \t]*(?:\n|\z)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | next if defined($comment_mark) && length($comment_mark) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $comment_mark and length $comment_mark and $lines[$line_number] =~ /^[ \t]*\Q$comment_mark\E[^\n]*(?:\n|\z)$/
defined $comment_mark and length $comment_mark
MC/DC33%1/3
defined $comment_mark and length $comment_mark and $lines[$line_number] =~ /^[ \t]*\Q$comment_mark\E[^\n]*(?:\n|\z)$/
defined $comment_mark
length $comment_mark
$lines[$line_number] =~ /^[ \t]*\Q$comment_mark\E[^\n]*(?:\n|\z)$/
Truth table50%2/4
A and B and C
A= defined $comment_markB= length $comment_markC= $lines[$line_number] =~ /^[ \t]*\Q$comment_mark\E[^\n]*(?:\n|\z)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | && $lines[$line_number] =~ /^[ \t]*\Q$comment_mark\E[^\n]*(?:\n|\z)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | _error('args must be the first executable directive', $start + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 64 | my ($declaration, $end) = _collect_declaration(\@lines, $start, $line_start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 62 | for my $line_number ($end + 1 .. $#lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 170 | ▶ | next unless $lines[$line_number] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | =~ /^[ \t]*\Q$line_start\E[ \t]+args(?:[ \t]|\n|\z)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | _error('args directive may only appear once', $line_number + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 61 | my $expected_newlines = $declaration =~ tr/\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 61 | ▶ | my $line_boundary = $declaration =~ s/\n\z// ? "\n" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 61 | my $generated = _generate_bindings($declaration, $start + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 51 | my $actual_newlines = $generated =~ tr/\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 51 | ▶ | my $generated_newlines = $expected_newlines - ($line_boundary eq "\n" ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 51 | ▶ | _error('args rewrite could not preserve source lines', $start + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | if $actual_newlines > $generated_newlines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 51 | $generated .= "\n" x ($generated_newlines - $actual_newlines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 51 | splice @lines, $start, $end - $start + 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | "${open_tag}${generated}-${close_tag}${line_boundary}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 51 | return (join('', @lines), 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 64 | ▶ | sub _collect_declaration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_collect_declaration: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 64 | my ($lines, $start, $line_start) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 64 | my $declaration = $lines->[$start]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 64 | $declaration =~ s/^[ \t]*\Q$line_start\E[ \t]+args\b//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 64 | my $end = $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 64 | ▶ | while (!_is_complete($declaration)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 18 | $end++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 18 | ▶ | if ($end > $#$lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$end > $lines->$#* or not $lines->[$end] =~ /^[ \t]*\Q$line_start\E(?!\Q$line_start\E)/
MC/DC50%1/2
$end > $lines->$#* or not $lines->[$end] =~ /^[ \t]*\Q$line_start\E(?!\Q$line_start\E)/
$end > $lines->$#*
not $lines->[$end] =~ /^[ \t]*\Q$line_start\E(?!\Q$line_start\E)/
Truth table66%2/3
A or not(B)
A= $end > $lines->$#*B= not $lines->[$end] =~ /^[ \t]*\Q$line_start\E(?!\Q$line_start\E)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | || $lines->[$end] !~ /^[ \t]*\Q$line_start\E(?!\Q$line_start\E)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | my $message = $declaration =~ /=\s*(?:\n)?\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ? 'args default expression is incomplete' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | : 'incomplete args directive'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | _error($message, $start + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 16 | my $continuation = $lines->[$end]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 16 | $continuation =~ s/^[ \t]*\Q$line_start\E//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 16 | $declaration .= $continuation; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 62 | return ($declaration, $end); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 80 | ▶ | sub _is_complete { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_complete: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 80 | my ($declaration) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 80 | my ($document, $list, $expression) = _parse_declaration($declaration); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 80 | ▶ | return 0 unless $document && $list && $expression; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$document and $list and $expression
$document and $list
MC/DC33%1/3
$document and $list and $expression
$document
$list
$expression
Truth table50%2/4
A and B and C
A= $documentB= $listC= $expression
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 79 | my $structures = $document->find('PPI::Structure'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 79 | ▶ | return 0 if $structures && grep { !$_->finish } @$structures; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$structures and grep {not $_->finish;} @$structures
MC/DC50%1/2
$structures and grep {not $_->finish;} @$structures
$structures
grep {not $_->finish;} @$structures
Truth table66%2/3
A and B
A= $structuresB= grep {not $_->finish;} @$structures
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 65 | ▶ | return 0 if $document->find('PPI::Statement::UnmatchedBrace'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 65 | my @tokens = grep { $_->significant } $expression->tokens; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 65 | ▶ | return 0 unless @tokens; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 65 | ▶ | return 0 if $tokens[-1]->isa('PPI::Token::Operator'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 62 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 61 | ▶ | sub _generate_bindings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_bindings: called CC=19 SCAR=29.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 61 | my ($declaration, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 61 | my ($document, $list, $expression) = _parse_declaration($declaration); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 61 | ▶ | _error('invalid args directive', $line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
$document and $list and $expression and _is_wholly_consumed($document, $list, $expression)
$document and $list and $expression
$document and $list
MC/DC25%1/4
$document and $list and $expression and _is_wholly_consumed($document, $list, $expression)
$document
$list
$expression
_is_wholly_consumed($document, $list, $expression)
Truth table40%2/5
A and B and C and D
A= $documentB= $listC= $expressionD= _is_wholly_consumed($document, $list, $expression)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | unless $document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | && $list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | && $expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | && _is_wholly_consumed($document, $list, $expression); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 58 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | my @part; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 58 | for my $element ($expression->children) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 272 | ▶ | if ($element->isa('PPI::Token::Operator') && $element->content eq ',') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$element->isa("PPI::Token::Operator") and $element->content eq ","
MC/DC100%2/2
$element->isa("PPI::Token::Operator") and $element->content eq ","
$element->isa("PPI::Token::Operator")
$element->content eq ","
Truth table100%3/3
A and B
A= $element->isa("PPI::Token::Operator")B= $element->content eq ","
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 24 | push @parts, [@part]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 24 | @part = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 24 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 248 | push @part, $element; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 58 | push @parts, [@part]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 58 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 58 | my $generated = 'my $__named_args=$__context->named_arguments(\@_);'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 58 | for my $part (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 82 | my @significant = grep { $_->significant } @$part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 82 | ▶ | _error('args directive requires a scalar argument', $line) unless @significant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 82 | my $symbol = shift @significant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 82 | ▶ | _error('args directive accepts only scalar arguments', $line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$symbol->isa("PPI::Token::Symbol") and $symbol->content =~ /^\$([A-Za-z_]\w*)\z/
MC/DC50%1/2
$symbol->isa("PPI::Token::Symbol") and $symbol->content =~ /^\$([A-Za-z_]\w*)\z/
$symbol->isa("PPI::Token::Symbol")
$symbol->content =~ /^\$([A-Za-z_]\w*)\z/
Truth table66%2/3
A and B
A= $symbol->isa("PPI::Token::Symbol")B= $symbol->content =~ /^\$([A-Za-z_]\w*)\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | unless $symbol->isa('PPI::Token::Symbol') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | && $symbol->content =~ /^\$([A-Za-z_]\w*)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 80 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | _error("Template argument '$name' uses a reserved compiler identifier", $line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 80 | ▶ | if $RESERVED_ARGUMENT{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 76 | ▶ | _error("Duplicate args declaration '$name'", $line) if $seen{$name}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 75 | my ($symbol_index) = grep { $part->[$_] == $symbol } 0 .. $#$part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 75 | my $leading = join '', map { $_->content } @$part[0 .. $symbol_index - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 75 | $generated .= $leading; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 75 | ▶ | if (!@significant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 43 | $generated .= "my \$$name=\$__context->take_required_argument(\$__named_args,'$name');"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 43 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 32 | my $equals = shift @significant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 32 | ▶ | _error("invalid declaration for template argument '$name'", $line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$equals->isa("PPI::Token::Operator") and $equals->content eq "="
MC/DC0%0/2
$equals->isa("PPI::Token::Operator") and $equals->content eq "="
$equals->isa("PPI::Token::Operator")
$equals->content eq "="
Truth table33%1/3
A and B
A= $equals->isa("PPI::Token::Operator")B= $equals->content eq "="
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | unless $equals->isa('PPI::Token::Operator') && $equals->content eq '='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 32 | ▶ | _error("template argument '$name' requires a default expression", $line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | unless @significant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 32 | my ($equals_index) = grep { $part->[$_] == $equals } 0 .. $#$part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 32 | my @default_elements = @$part[$equals_index + 1 .. $#$part]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 32 | my $default = join '', map { $_->content } @default_elements; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 32 | my @default_significant = grep { $_->significant } @default_elements; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 32 | ▶ | my $factory = _is_anonymous_sub(@default_significant) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ? $default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | : "sub {$default}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 32 | $generated .= "my \$$name=\$__context->take_optional_argument(\$__named_args,'$name',$factory);"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 51 | $generated .= '$__context->assert_no_arguments($__named_args);'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 51 | return $generated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 32 | ▶ | sub _is_anonymous_sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_anonymous_sub: called CC=7 SCAR=20.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 32 | my (@elements) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 32 | ▶ | return 0 unless @elements == 2 || @elements == 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@elements == 2 or @elements == 3
MC/DC50%1/2
@elements == 2 or @elements == 3
@elements == 2
@elements == 3
Truth table66%2/3
A or B
A= @elements == 2B= @elements == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | ▶ | return 0 unless $elements[0]->isa('PPI::Token::Word') && $elements[0]->content eq 'sub'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$elements[0]->isa("PPI::Token::Word") and $elements[0]->content eq "sub"
MC/DC50%1/2
$elements[0]->isa("PPI::Token::Word") and $elements[0]->content eq "sub"
$elements[0]->isa("PPI::Token::Word")
$elements[0]->content eq "sub"
Truth table66%2/3
A and B
A= $elements[0]->isa("PPI::Token::Word")B= $elements[0]->content eq "sub"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | ▶ | return 0 unless $elements[-1]->isa('PPI::Structure::Block'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 6 | ▶ | return 1 if @elements == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | return $elements[1]->isa('PPI::Structure::List'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 61 | ▶ | sub _is_wholly_consumed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_wholly_consumed: called CC=16 SCAR=31.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 61 | my ($document, $list, $expression) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 61 | ▶ | my $statement = $document->schild(0) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 61 | ▶ | return 0 unless $statement->isa('PPI::Statement::Variable'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 61 | ▶ | return 0 if $document->schild(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 61 | ▶ | my $keyword = $statement->schild(0) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 61 | ▶ | return 0 unless $keyword->isa('PPI::Token::Word') && $keyword->content eq 'my'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$keyword->isa("PPI::Token::Word") and $keyword->content eq "my"
MC/DC0%0/2
$keyword->isa("PPI::Token::Word") and $keyword->content eq "my"
$keyword->isa("PPI::Token::Word")
$keyword->content eq "my"
Truth table33%1/3
A and B
A= $keyword->isa("PPI::Token::Word")B= $keyword->content eq "my"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 61 | ▶ | return 0 unless $statement->schild(1) == $list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 61 | ▶ | my $terminator = $statement->schild(2) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 61 | ▶ | return 0 unless $terminator->isa('PPI::Token::Structure') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$terminator->isa("PPI::Token::Structure") and $terminator->content eq ";"
MC/DC0%0/2
$terminator->isa("PPI::Token::Structure") and $terminator->content eq ";"
$terminator->isa("PPI::Token::Structure")
$terminator->content eq ";"
Truth table33%1/3
A and B
A= $terminator->isa("PPI::Token::Structure")B= $terminator->content eq ";"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | && $terminator->content eq ';'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 61 | ▶ | return 0 if $statement->schild(3); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 61 | ▶ | return 0 unless $list->schild(0) == $expression; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 61 | ▶ | return 0 if $list->schild(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | return 0 if grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 59 | ▶ | $_->isa('PPI::Token::Structure') && $_->content eq ';' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_->isa('PPI::Token::Structure') && $_->content eq ';'
MC/DC50%1/2
$_->isa('PPI::Token::Structure') && $_->content eq ';'
$_->isa('PPI::Token::Structure')
$_->content eq ';'
Truth table66%2/3
A && B
A= $_->isa('PPI::Token::Structure')B= $_->content eq ';'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } $expression->children; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 58 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 141 | ▶ | sub _parse_declaration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_declaration: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 141 | my ($declaration) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 141 | my $source = "my ($declaration);"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 141 | ▶ | my $document = PPI::Document->new(\$source) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 141 | ▶ | my $statement = $document->schild(0) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 141 | ▶ | my $list = $statement->find_first('PPI::Structure::List') or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 141 | ▶ | my $expression = $list->schild(0) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 140 | return ($document, $list, $expression); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 16 | ▶ | sub _error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 16 | my ($message, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 16 | die "$message at template line $line\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||