| 1 | package Plift::Handler::Snippet; | ||||||||||
| 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 | 9 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 9 | ▶ | use Class::Load qw/ load_class /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 10 | ▶ | has 'attributes', is => 'ro', default => sub { [qw/ data-snippet data-plift data-plift-snippet /] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 10 | ▶ | sub register { | ||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 11 | 10 | my ($self, $engine) = @_; | |||||||||
| 12 | |||||||||||
| 13 | $engine->add_handler({ | ||||||||||
| 14 | name => 'snippet', | ||||||||||
| 15 | attribute => $self->attributes, | ||||||||||
| 16 | 3 | ▶ | handler => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 3 | $self->process(@_); | |||||||||
| 18 | } | ||||||||||
| 19 | }) | ||||||||||
| 20 | 10 | } | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | 3 | ▶ | sub process { | ||||||||
|
Subroutine
process: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 24 | 3 | my ($self, $element, $ctx) = @_; | |||||||||
| 25 | 3 | my $node = $element->get(0); | |||||||||
| 26 | |||||||||||
| 27 | 3 | my $snippet_uri; | |||||||||
| 28 | my $attr; | ||||||||||
| 29 | 3 | foreach $attr (@{ $self->attributes }) { | |||||||||
| 30 | |||||||||||
| 31 | 9 | ▶ | if ($node->hasAttribute($attr)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 3 | $snippet_uri = URI->new($node->getAttribute($attr)); | |||||||||
| 34 | 3 | $node->removeAttribute($attr); | |||||||||
| 35 | } | ||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 3 | ▶ | confess "Template error: missing snippet name in the '$attr' attribute.!" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | unless $snippet_uri->path; | ||||||||||
| 40 | |||||||||||
| 41 | # run | ||||||||||
| 42 | 3 | $ctx->run_snippet($snippet_uri->path, $element, { $snippet_uri->query_form }); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | 9 | 1; | |||||||||
| 51 | |||||||||||
| 52 | __END__ | ||||||||||