« blib/lib/HTML/Object/DOM/Element/TableCaption.pm
↑ Summary
blib/lib/HTML/Object/DOM/Element/Time.pm »
| 1 | ##---------------------------------------------------------------------------- | ||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/Element/Template.pm | ||
| 3 | ## Version v0.2.0 | ||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||
| 6 | ## Created 2022/01/09 | ||
| 7 | ## Modified 2022/09/18 | ||
| 8 | ## All rights reserved | ||
| 9 | ## | ||
| 10 | ## | ||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||
| 12 | ## under the same terms as Perl itself. | ||
| 13 | ##---------------------------------------------------------------------------- | ||
| 14 | package HTML::Object::DOM::Element::Template; | ||
| 15 | BEGIN | ||
| 16 | { | ||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | warnings::register_categories( 'HTML::Object' ); | ||
| 20 | use parent qw( HTML::Object::DOM::Element ); | ||
| 21 | use vars qw( $VERSION ); | ||
| 22 | our $VERSION = 'v0.2.0'; | ||
| 23 | }; | ||
| 24 | |||
| 25 | use strict; | ||
| 26 | use warnings; | ||
| 27 | |||
| 28 | sub init | ||
| 29 | { | ||
| 30 | my $self = shift( @_ ); | ||
| 31 | $self->{_init_strict_use_sub} = 1; | ||
| 32 | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||
| 33 | $self->{tag} = 'template' if( !CORE::length( "$self->{tag}" ) ); | ||
| 34 | return( $self ); | ||
| 35 | } | ||
| 36 | |||
| 37 | # Note: property content read-only | ||
| 38 | sub content : lvalue { return( shift->_lvalue({ | ||
| 39 | set => sub | ||
| 40 | { | ||
| 41 | my $self = shift( @_ ); | ||
| 42 | my $ref = shift( @_ ); | ||
| 43 | my $nodes = $self->_list_to_nodes( @$ref ) || | ||
| 44 | return( $self->pass_error ); | ||
| 45 | for( @$nodes ) | ||
| 46 | { | ||
| 47 | $_->detach; | ||
| 48 | $_->parent( $self ); | ||
| 49 | } | ||
| 50 | my $children = $self->children; | ||
| 51 | $children->set( $nodes ); | ||
| 52 | return( $self ); | ||
| 53 | }, | ||
| 54 | get => sub | ||
| 55 | { | ||
| 56 | my $self = shift( @_ ); | ||
| 57 | $self->_load_class( 'HTML::Object::DOM::DocumentFragment' ) || | ||
| 58 | return( $self->pass_error ); | ||
| 59 | my $children = $self->children; | ||
| 60 | my $frag = HTML::Object::DOM::DocumentFragment->new; | ||
| 61 | $frag->children->set( $children ); | ||
| 62 | return( $frag ); | ||
| 63 | } | ||
| 64 | }, @_ ) ); } | ||
| 65 | |||
| 66 | 1; | ||
| 67 | # NOTE: POD | ||
| 68 | __END__ | ||
| 69 | |||
| 70 | =encoding utf-8 | ||
| 71 | |||
| 72 | =head1 NAME | ||
| 73 | |||
| 74 | HTML::Object::DOM::Element::Template - HTML Object DOM Template Class | ||
| 75 | |||
| 76 | =head1 SYNOPSIS | ||
| 77 | |||
| 78 | use HTML::Object::DOM::Element::Template; | ||
| 79 | my $template = HTML::Object::DOM::Element::Template->new || | ||
| 80 | die( HTML::Object::DOM::Element::Template->error, "\n" ); | ||
| 81 | |||
| 82 | =head1 VERSION | ||
| 83 | |||
| 84 | v0.2.0 | ||
| 85 | |||
| 86 | =head1 DESCRIPTION | ||
| 87 | |||
| 88 | This interface enables access to the contents of an HTML C<template> element. | ||
| 89 | |||
| 90 | =head1 INHERITANCE | ||
| 91 | |||
| 92 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +--------------------------------------+ | ||
| 93 | | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Template | | ||
| 94 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +--------------------------------------+ | ||
| 95 | |||
| 96 | =head1 PROPERTIES | ||
| 97 | |||
| 98 | Inherits properties from its parent L<HTML::Object::DOM::Element> | ||
| 99 | |||
| 100 | =head2 content | ||
| 101 | |||
| 102 | Read-only. | ||
| 103 | |||
| 104 | A read-only L<DocumentFragment|HTML::Object::DOM::DocumentFragment> which contains the DOM subtree representing the <template> element's template contents. | ||
| 105 | |||
| 106 | Example: | ||
| 107 | |||
| 108 | my $templateElement = $doc->querySelector('#foo'); | ||
| 109 | my $documentFragment = $templateElement->content->cloneNode(1); # pass true to cloneNode | ||
| 110 | |||
| 111 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content> | ||
| 112 | |||
| 113 | =head1 METHODS | ||
| 114 | |||
| 115 | Inherits methods from its parent L<HTML::Object::DOM::Element> | ||
| 116 | |||
| 117 | =head1 AUTHOR | ||
| 118 | |||
| 119 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||
| 120 | |||
| 121 | =head1 SEE ALSO | ||
| 122 | |||
| 123 | L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement>, L<Mozilla documentation on template element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template> | ||
| 124 | |||
| 125 | =head1 COPYRIGHT & LICENSE | ||
| 126 | |||
| 127 | Copyright(c) 2022 DEGUEST Pte. Ltd. | ||
| 128 | |||
| 129 | All rights reserved | ||
| 130 | |||
| 131 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 132 | |||
| 133 | =cut |