| 1 | package Plift::Handler::Wrap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | my ($self, $engine) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | $engine->add_handler({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | name => 'wrap', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | tag => 'x-wrap', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | attribute => 'data-plift-wrap', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | handler => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | $self->wrap(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | ▶ | sub wrap { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wrap: called CC=21 SCAR=32.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | my ($self, $element, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my $node = $element->get(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | my $is_tag = $node->localname eq 'x-wrap'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | my $template_name = $is_tag ? $node->getAttribute('template') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | : $node->getAttribute('data-plift-wrap'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | $template_name ||= 'layout'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$template_name ||= "layout"
MC/DC0%0/1
$template_name ||= "layout"
$template_name
Truth table50%1/2
A
A= $template_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | my %params = ( at => '#content' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | foreach (qw/ at if unless replace content /) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 30 | ▶ | my $value = $node->getAttribute("data-$_") || $node->getAttribute($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$node->getAttribute("data-$_") || $node->getAttribute($_)
MC/DC100%2/2
$node->getAttribute("data-$_") || $node->getAttribute($_)
$node->getAttribute("data-$_")
$node->getAttribute($_)
Truth table100%3/3
A || B
A= $node->getAttribute("data-$_")B= $node->getAttribute($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 30 | ▶ | unless ($is_tag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 10 | $node->removeAttribute("data-$_"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | $node->removeAttribute($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 30 | ▶ | $params{$_} = $value if $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # contitional abort | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
defined $params{"if"} and not $ctx->get($params{"if"}) or defined $params{"unless"} and $ctx->get($params{"unless"})
defined $params{"if"} and not $ctx->get($params{"if"})
defined $params{"unless"} and $ctx->get($params{"unless"})
MC/DC25%1/4
defined $params{"if"} and not $ctx->get($params{"if"}) or defined $params{"unless"} and $ctx->get($params{"unless"})
defined $params{"if"}
not $ctx->get($params{"if"})
defined $params{"unless"}
$ctx->get($params{"unless"})
Truth table28%2/7
A and not(B) or C and D
A= defined $params{"if"}B= not $ctx->get($params{"if"})C= defined $params{"unless"}D= $ctx->get($params{"unless"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | (defined $params{if} && !$ctx->get($params{if})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | || (defined $params{unless} && $ctx->get($params{unless})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | $element->replace_with($element->children) if $is_tag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # load template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | my $dom = $ctx->process_template($template_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # $dom elements comes unbound of document, insert after element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | $dom->insert_after($element); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # find wrapper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | my $wrapper = $dom->find($params{at}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | ▶ | $wrapper = $dom->filter($params{at}) if $wrapper->size == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | ▶ | confess "wrap error: can't find wrapper element (with id '".$params{at}."') on:\n".$dom->as_html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | unless $wrapper->size > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # wrap element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | my $is_xtag = $element->tagname =~ /^x-/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | ▶ | if ($params{replace}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | $wrapper->replace_with($is_xtag || $params{content} ? $element->contents : $element); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_xtag or $params{"content"}
MC/DC0%0/2
$is_xtag or $params{"content"}
$is_xtag
$params{"content"}
Truth table66%2/3
A or B
A= $is_xtagB= $params{"content"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | $wrapper->append($is_xtag || $params{content} ? $element->contents->{nodes} : $element->{nodes}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_xtag or $params{"content"}
MC/DC0%0/2
$is_xtag or $params{"content"}
$is_xtag
$params{"content"}
Truth table66%2/3
A or B
A= $is_xtagB= $params{"content"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | $element->remove if $is_xtag || $params{content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_xtag or $params{"content"}
MC/DC0%0/2
$is_xtag or $params{"content"}
$is_xtag
$params{"content"}
Truth table66%2/3
A or B
A= $is_xtagB= $params{"content"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||