| 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
| |||||||||||||||||||||||||||||
| 29 | 25 | ▶ | $node->removeAttribute('data-render') unless $is_tag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$mod->{"replace"} or $is_tag
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | 24 | ▶ | $selector .= '+' if $mod->{append}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 24 | ▶ | $selector = '+'.$selector if $mod->{prepend}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 24 | ▶ | $selector = '^'.$selector if $mod->{replace} || $is_tag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mod->{"replace"} or $is_tag
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||