| 1 | package Plift::Handler::Include; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | my ($self, $engine) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | $engine->add_handler({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | name => 'include', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | tag => 'x-include', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | attribute => 'data-plift-include', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | handler => \&include | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 28 | ▶ | sub include { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
include: called CC=14 SCAR=26.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 28 | my ($element, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 28 | my $node = $element->get(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 28 | my $is_tag = $node->localname eq 'x-include'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 28 | ▶ | my $template_name = $is_tag ? $node->getAttribute('template') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | : $node->getAttribute('data-plift-include'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 28 | ▶ | my $if = $node->getAttribute('if') || $node->getAttribute('data-if'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$node->getAttribute('if') || $node->getAttribute('data-if')
MC/DC50%1/2
$node->getAttribute('if') || $node->getAttribute('data-if')
$node->getAttribute('if')
$node->getAttribute('data-if')
Truth table66%2/3
A || B
A= $node->getAttribute('if')B= $node->getAttribute('data-if')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 28 | ▶ | my $unless = $node->getAttribute('unless') || $node->getAttribute('data-unless'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$node->getAttribute('unless') || $node->getAttribute('data-unless')
MC/DC50%1/2
$node->getAttribute('unless') || $node->getAttribute('data-unless')
$node->getAttribute('unless')
$node->getAttribute('data-unless')
Truth table66%2/3
A || B
A= $node->getAttribute('unless')B= $node->getAttribute('data-unless')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # no template name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 28 | ▶ | unless ($template_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $error = "include error: missing template name\nsyntax:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $error .= $is_tag ? '<x-include template="<template_name>"' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | : sprintf('<%s data-plift-include="<template_name>">', $element->tagname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | die $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # contitional remove | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 27 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
defined $if and not $ctx->get($if) or defined $unless and $ctx->get($unless)
defined $if and not $ctx->get($if)
defined $unless and $ctx->get($unless)
MC/DC100%4/4
defined $if and not $ctx->get($if) or defined $unless and $ctx->get($unless)
defined $if
not $ctx->get($if)
defined $unless
$ctx->get($unless)
Truth table71%5/7
A and not(B) or C and D
A= defined $ifB= not $ctx->get($if)C= defined $unlessD= $ctx->get($unless)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | (defined $if && !$ctx->get($if)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | || (defined $unless && $ctx->get($unless)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | $element->remove if $is_tag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # remove our attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 25 | ▶ | unless ($is_tag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | $node->removeAttribute($_) for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | qw/ data-plift-include data-if data-unless if unless/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 25 | my $dom = $ctx->process_template( $template_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # replace or append | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 25 | ▶ | if ($is_tag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 18 | $element->replace_with($dom); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | $element->append($dom); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||