Plift/Handler/Render.pm

filter: Statementstmt 100% 29 / 29 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 86.8% 53 / 61 CC 12 SCAR 22.9
CC
12
Cov
92%
create_directives
12.1
BEGIN
1.0
BEGIN
1.0
CRAP 9.9
« Plift/Context.pm ↑ Summary Plift.pm »
1 package Plift::Handler::Render;
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 10 $engine->add_handler({
11 name => 'render',
12 tag => 'x-render',
13 attribute => ['data-render'],
14 handler => \&create_directives
15 });
16 }
17  
18  
19 25 ▶sub create_directives {
Subroutine create_directives: called CC=12 SCAR=25.0
Pod undocumented
20 25 my ($element, $ctx) = @_;
21 25 my $node = $element->get(0);
22  
23 # walk directive stack, get node id
24 25 $ctx->rewind_directive_stack($element);
25  
26 # parse directive
27 25 my $is_tag = $node->localname eq 'x-render';
28 25 ▶ my $render_instruction = $node->getAttribute($is_tag ? 'data' : 'data-render');
Branch: 1 branch
BranchTrueFalseTotal
$is_tag ? : 10 15 25
29 25 ▶ $node->removeAttribute('data-render') unless $is_tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_tag 15 10 25
30  
31 # prepare selector
32 25 my $element_selector = $ctx->selector_for($node);
33  
34 # data-render="[datapoint]" (step into directive)
35 25 ▶ if ($render_instruction =~ /^\s*\[\s*([\w._-]+)\s*\]\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($render_instruction =~ /^\s*\[\s*([\w._-]+)\s*\]\s*$/) { } 6 19 25
36  
37 # modifiers
38 6 my $mod = $ctx->_parse_matchspec_modifiers($render_instruction);
39 $element_selector = '^'.$element_selector
40 6 ▶ if $mod->{replace} || $is_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $mod->{"replace"} or $is_tag 3 3 6
Condition66%2/3
$mod->{"replace"} or $is_tag
l!l&&r!l&&!r
033
MC/DC50%1/2
$mod->{"replace"} or $is_tag
$mod->{"replace"} $is_tag
Truth table66%2/3
A or B
A= $mod->{"replace"}B= $is_tag
ABresult
1X1
011
000
41  
42 # push directive stack
43 6 $ctx->push_at($element_selector, $1);
44 }
45  
46 # data-render="datapoint"
47 else {
48  
49 19 foreach my $instruction (split /\s+/, $render_instruction) {
50  
51 24 my $mod = $ctx->_parse_matchspec_modifiers($instruction);
52 24 my ($data_point, $attribute) = split '@', $instruction;
53 24 my $selector = $element_selector;
54 24 ▶ $selector .= "\@$attribute" if defined $attribute;
Branch: 1 branch
BranchTrueFalseTotal
if defined $attribute 7 17 24
55 24 ▶ $selector .= '+' if $mod->{append};
Branch: 1 branch
BranchTrueFalseTotal
if $mod->{"append"} 0 24 24
56 24 ▶ $selector = '+'.$selector if $mod->{prepend};
Branch: 1 branch
BranchTrueFalseTotal
if $mod->{"prepend"} 0 24 24
57 24 ▶ $selector = '^'.$selector if $mod->{replace} || $is_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $mod->{"replace"} or $is_tag 7 17 24
Condition66%2/3
$mod->{"replace"} or $is_tag
l!l&&r!l&&!r
0717
MC/DC50%1/2
$mod->{"replace"} or $is_tag
$mod->{"replace"} $is_tag
Truth table66%2/3
A or B
A= $mod->{"replace"}B= $is_tag
ABresult
1X1
011
000
58  
59 24 $ctx->at($selector, $data_point);
60 }
61 }
62 }
63  
64  
65  
66  
67  
68  
69  
70  
71 9 1;
72  
73 __END__
« Plift/Context.pm ↑ Summary Plift.pm »