| 1 | ##---------------------------------------------------------------------------- | ||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/Comment.pm | ||||||||||
| 3 | ## Version v0.2.0 | ||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||
| 6 | ## Created 2021/04/19 | ||||||||||
| 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::Comment; | ||||||||||
| 15 | BEGIN | ||||||||||
| 16 | { | ||||||||||
| 17 | 33 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 33 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 33 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 33 | ▶ | use parent qw( HTML::Object::Element ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 33 | ▶ | use vars qw( $VERSION ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 33 | our $VERSION = 'v0.2.0'; | |||||||||
| 23 | }; | ||||||||||
| 24 | |||||||||||
| 25 | 33 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 33 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | sub init | ||||||||||
| 29 | { | ||||||||||
| 30 | 7 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 31 | 7 | $self->{open_seq} = '<!--'; | |||||||||
| 32 | 7 | $self->{close_seq} = '-->'; | |||||||||
| 33 | 7 | $self->{tag} = '_comment'; | |||||||||
| 34 | 7 | $self->{value} = ''; | |||||||||
| 35 | 7 | $self->{is_empty} = 1; | |||||||||
| 36 | 7 | $self->{_init_strict_use_sub} = 1; | |||||||||
| 37 | 7 | $self->{_exception_class} = 'HTML::Object::Exception'; | |||||||||
| 38 | 7 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 7 | return( $self ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub as_string | ||||||||||
| 43 | { | ||||||||||
| 44 | 1 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
as_string: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 45 | # We need to remove the reset flag, otherwise if there are any subsequent change that need to be propagated to this comment parent, HTML::Object::Element::reset will not propagate it | ||||||||||
| 46 | 1 | $self->_remove_reset; | |||||||||
| 47 | return( | ||||||||||
| 48 | 1 | ▶ | $self->value->length | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | ? $self->new_scalar( join( '', '<!--', $self->value->scalar, '-->' ) ) | ||||||||||
| 50 | : $self->original | ||||||||||
| 51 | ); | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | sub as_xml | ||||||||||
| 55 | { | ||||||||||
| 56 | 0 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
as_xml: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 57 | 0 | ▶ | my $txt = $self->value->length | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | ? $self->new_scalar( join( '', '<!--', $self->value->scalar, '-->' ) ) | ||||||||||
| 59 | : $self->original; | ||||||||||
| 60 | # HTML::Element says there cannot be double --'s in XML comments | ||||||||||
| 61 | 0 | $txt->replace( qr/--/, '--' ); | |||||||||
| 62 | 0 | return( $txt ); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub close_seq { return( shift->_set_get_scalar_as_object( 'close_seq', @_ ) ); } | ||||||||
|
Subroutine
close_seq: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | sub open_seq { return( shift->_set_get_scalar_as_object( 'open_seq', @_ ) ); } | ||||||||
|
Subroutine
open_seq: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 68 | |||||||||||
| 69 | sub set_checksum | ||||||||||
| 70 | { | ||||||||||
| 71 | 7 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
set_checksum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 72 | 7 | return( $self->_get_md5_hash( $self->value->scalar ) ); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 17 | ▶ | sub value : lvalue { return( shift->_set_get_scalar_as_object( 'value', @_ ) ); } | ||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 76 | |||||||||||
| 77 | 33 | 1; | |||||||||
| 78 | # NOTE: POD | ||||||||||
| 79 | __END__ | ||||||||||
| 80 | |||||||||||
| 81 | =encoding utf-8 | ||||||||||
| 82 | |||||||||||
| 83 | =head1 NAME | ||||||||||
| 84 | |||||||||||
| 85 | HTML::Object::Comment - HTML Object Comment Element Class | ||||||||||
| 86 | |||||||||||
| 87 | =head1 SYNOPSIS | ||||||||||
| 88 | |||||||||||
| 89 | use HTML::Object::Comment; | ||||||||||
| 90 | my $this = HTML::Object::Comment->new || | ||||||||||
| 91 | die( HTML::Object::Comment->error, "\n" ); | ||||||||||
| 92 | |||||||||||
| 93 | =head1 VERSION | ||||||||||
| 94 | |||||||||||
| 95 | v0.2.0 | ||||||||||
| 96 | |||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||
| 98 | |||||||||||
| 99 | This module represents an HTML comment | ||||||||||
| 100 | |||||||||||
| 101 | =head1 INHERITANCE | ||||||||||
| 102 | |||||||||||
| 103 | +-----------------------+ +-----------------------+ | ||||||||||
| 104 | | HTML::Object::Element | --> | HTML::Object::Comment | | ||||||||||
| 105 | +-----------------------+ +-----------------------+ | ||||||||||
| 106 | |||||||||||
| 107 | =head1 PROPERTIES | ||||||||||
| 108 | |||||||||||
| 109 | =head2 nodeValue | ||||||||||
| 110 | |||||||||||
| 111 | This returns or sets the value of the current node. | ||||||||||
| 112 | |||||||||||
| 113 | For document, element or collection, this returns C<undef> and for attribute, text or comment, this returns the objct value. | ||||||||||
| 114 | |||||||||||
| 115 | See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue> | ||||||||||
| 116 | |||||||||||
| 117 | =head1 METHODS | ||||||||||
| 118 | |||||||||||
| 119 | =head2 as_string | ||||||||||
| 120 | |||||||||||
| 121 | Returns the HTML comment as a string. | ||||||||||
| 122 | |||||||||||
| 123 | =head2 as_xml | ||||||||||
| 124 | |||||||||||
| 125 | Returns the comment as an XML string., which is almost the same format as with L</as_string> | ||||||||||
| 126 | |||||||||||
| 127 | =head2 close_seq | ||||||||||
| 128 | |||||||||||
| 129 | Set or get the string used as a close sequence. | ||||||||||
| 130 | |||||||||||
| 131 | =head2 isEqualNode | ||||||||||
| 132 | |||||||||||
| 133 | Returns a boolean value which indicates whether or not two elements are of the same type and all their defining data points match. | ||||||||||
| 134 | |||||||||||
| 135 | Two elements are equal when they have the same type, defining characteristics (this would be their ID, number of children, and so forth), its attributes match, and so on. The specific set of data points that must match varies depending on the types of the elements. | ||||||||||
| 136 | |||||||||||
| 137 | See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode> | ||||||||||
| 138 | |||||||||||
| 139 | =head2 nodeValue | ||||||||||
| 140 | |||||||||||
| 141 | This returns or sets the value of the current element. | ||||||||||
| 142 | |||||||||||
| 143 | See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue> | ||||||||||
| 144 | |||||||||||
| 145 | =head2 open_seq | ||||||||||
| 146 | |||||||||||
| 147 | Set or get the string used as an open sequence. | ||||||||||
| 148 | |||||||||||
| 149 | =head2 set_checksum | ||||||||||
| 150 | |||||||||||
| 151 | Read-only. | ||||||||||
| 152 | |||||||||||
| 153 | Get the element md5 checksum for the current value. | ||||||||||
| 154 | |||||||||||
| 155 | =head2 value | ||||||||||
| 156 | |||||||||||
| 157 | Set or get the comment inner value, i.e. the text within, as a L<scalar object|Module::Generic::Scalar> | ||||||||||
| 158 | |||||||||||
| 159 | =head1 AUTHOR | ||||||||||
| 160 | |||||||||||
| 161 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||
| 162 | |||||||||||
| 163 | =head1 SEE ALSO | ||||||||||
| 164 | |||||||||||
| 165 | L<https://html.spec.whatwg.org/multipage/syntax.html#the-doctype> | ||||||||||
| 166 | |||||||||||
| 167 | L<https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode> | ||||||||||
| 168 | |||||||||||
| 169 | L<HTML::Object>, L<HTML::Object::Attribute>, L<HTML::Object::Boolean>, L<HTML::Object::Closing>, L<HTML::Object::Collection>, L<HTML::Object::Comment>, L<HTML::Object::Declaration>, L<HTML::Object::Document>, L<HTML::Object::Element>, L<HTML::Object::Exception>, L<HTML::Object::Literal>, L<HTML::Object::Number>, L<HTML::Object::Root>, L<HTML::Object::Space>, L<HTML::Object::Text>, L<HTML::Object::XQuery> | ||||||||||
| 170 | |||||||||||
| 171 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 172 | |||||||||||
| 173 | Copyright (c) 2021 DEGUEST Pte. Ltd. | ||||||||||
| 174 | |||||||||||
| 175 | All rights reserved | ||||||||||
| 176 | |||||||||||
| 177 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||