| 1 | ##---------------------------------------------------------------------------- | ||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/Text.pm | ||||||||||
| 3 | ## Version v0.2.0 | ||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||
| 6 | ## Created 2021/04/22 | ||||||||||
| 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::Text; | ||||||||||
| 15 | BEGIN | ||||||||||
| 16 | { | ||||||||||
| 17 | 34 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 34 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 34 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 34 | ▶ | use parent qw( HTML::Object::Element ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 34 | ▶ | use vars qw( $VERSION ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 34 | our $VERSION = 'v0.2.0'; | |||||||||
| 23 | }; | ||||||||||
| 24 | |||||||||||
| 25 | 34 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 34 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | sub init | ||||||||||
| 29 | { | ||||||||||
| 30 | 151 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 31 | 151 | $self->{tag} = '_text'; | |||||||||
| 32 | 151 | $self->{value} = ''; | |||||||||
| 33 | 151 | $self->{is_empty} = 1; | |||||||||
| 34 | 151 | $self->{_init_strict_use_sub} = 1; | |||||||||
| 35 | 151 | $self->{_exception_class} = 'HTML::Object::Exception'; | |||||||||
| 36 | 151 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 151 | return( $self ); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub as_string | ||||||||||
| 41 | { | ||||||||||
| 42 | 102 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
as_string: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 43 | # We need to remove the reset flag, otherwise if there are any subsequent change that need to be propagated to this text parent, HTML::Object::Element::reset will not propagate it | ||||||||||
| 44 | 102 | $self->_remove_reset; | |||||||||
| 45 | 102 | ▶ | return( $self->value->length ? $self->value : $self->original ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | # There is nothing to encode because we have not touched the text in the first place. | ||||||||||
| 49 | # Especially in the script tag section ! | ||||||||||
| 50 | # If the user wants to, he can and should go ahead, but it is way too dangerous for us to make assumptions | ||||||||||
| 51 | 0 | ▶ | sub as_xml { return( shift->as_string( @_ ) ); } | ||||||||
|
Subroutine
as_xml: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 52 | |||||||||||
| 53 | # added to provide element-like methods to text nodes, for use by cmp | ||||||||||
| 54 | sub lineage | ||||||||||
| 55 | { | ||||||||||
| 56 | 0 | ▶ | my $node = shift( @_ ); | ||||||||
|
Subroutine
lineage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | 0 | my $parent = $node->parent; | |||||||||
| 58 | 0 | return( $parent, $parent->lineage ); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub set_checksum | ||||||||||
| 62 | { | ||||||||||
| 63 | 151 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
set_checksum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 64 | 151 | return( $self->_get_md5_hash( $self->value->scalar ) ); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 580 | ▶ | sub value : lvalue { return( shift->_set_get_scalar_as_object( 'value', @_ ) ); } | ||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 68 | |||||||||||
| 69 | 34 | 1; | |||||||||
| 70 | # NOTE: POD | ||||||||||
| 71 | __END__ | ||||||||||
| 72 | |||||||||||
| 73 | =encoding utf-8 | ||||||||||
| 74 | |||||||||||
| 75 | =head1 NAME | ||||||||||
| 76 | |||||||||||
| 77 | HTML::Object::Text - HTML Object | ||||||||||
| 78 | |||||||||||
| 79 | =head1 SYNOPSIS | ||||||||||
| 80 | |||||||||||
| 81 | use HTML::Object::Text; | ||||||||||
| 82 | my $txt = HTML::Object::Text->new || | ||||||||||
| 83 | die( HTML::Object::Text->error, "\n" ); | ||||||||||
| 84 | |||||||||||
| 85 | =head1 VERSION | ||||||||||
| 86 | |||||||||||
| 87 | v0.2.0 | ||||||||||
| 88 | |||||||||||
| 89 | =head1 DESCRIPTION | ||||||||||
| 90 | |||||||||||
| 91 | This module represents a text. It inherits from L<HTML::Object::Element> | ||||||||||
| 92 | |||||||||||
| 93 | =head1 INHERITANCE | ||||||||||
| 94 | |||||||||||
| 95 | +-----------------------+ +--------------------+ | ||||||||||
| 96 | | HTML::Object::Element | --> | HTML::Object::Text | | ||||||||||
| 97 | +-----------------------+ +--------------------+ | ||||||||||
| 98 | |||||||||||
| 99 | =head1 PROPERTIES | ||||||||||
| 100 | |||||||||||
| 101 | =head2 nodeValue | ||||||||||
| 102 | |||||||||||
| 103 | This returns or sets the value of the current node. | ||||||||||
| 104 | |||||||||||
| 105 | For document, element or collection, this returns C<undef> and for attribute, text or comment, this returns the objct value. | ||||||||||
| 106 | |||||||||||
| 107 | See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue> | ||||||||||
| 108 | |||||||||||
| 109 | =head1 METHODS | ||||||||||
| 110 | |||||||||||
| 111 | =head2 as_string | ||||||||||
| 112 | |||||||||||
| 113 | Returns the original value or the value assigned with L</value> | ||||||||||
| 114 | |||||||||||
| 115 | =head2 as_xml | ||||||||||
| 116 | |||||||||||
| 117 | This is an alias for L</as_string> | ||||||||||
| 118 | |||||||||||
| 119 | =head2 isEqualNode | ||||||||||
| 120 | |||||||||||
| 121 | Returns a boolean value which indicates whether or not two elements are of the same type and all their defining data points match. | ||||||||||
| 122 | |||||||||||
| 123 | 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. | ||||||||||
| 124 | |||||||||||
| 125 | See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode> | ||||||||||
| 126 | |||||||||||
| 127 | =head2 lineage | ||||||||||
| 128 | |||||||||||
| 129 | Returns an L<array object|Module::Generic::Array> of all the text element's ancestors. | ||||||||||
| 130 | |||||||||||
| 131 | =head2 nodeValue | ||||||||||
| 132 | |||||||||||
| 133 | This returns or sets the value of the current element. | ||||||||||
| 134 | |||||||||||
| 135 | See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue> | ||||||||||
| 136 | |||||||||||
| 137 | =head2 set_checksum | ||||||||||
| 138 | |||||||||||
| 139 | Read-only method. | ||||||||||
| 140 | |||||||||||
| 141 | This returns the md5 checksum for the current value. | ||||||||||
| 142 | |||||||||||
| 143 | =head2 value | ||||||||||
| 144 | |||||||||||
| 145 | Returns the current value as a L<scalar object|Module::Generic::Scalar> | ||||||||||
| 146 | |||||||||||
| 147 | =head1 AUTHOR | ||||||||||
| 148 | |||||||||||
| 149 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||
| 150 | |||||||||||
| 151 | =head1 SEE ALSO | ||||||||||
| 152 | |||||||||||
| 153 | L<https://html.spec.whatwg.org/multipage/syntax.html#the-doctype> | ||||||||||
| 154 | |||||||||||
| 155 | L<https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode> | ||||||||||
| 156 | |||||||||||
| 157 | 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> | ||||||||||
| 158 | |||||||||||
| 159 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 160 | |||||||||||
| 161 | Copyright (c) 2021 DEGUEST Pte. Ltd. | ||||||||||
| 162 | |||||||||||
| 163 | All rights reserved | ||||||||||
| 164 | |||||||||||
| 165 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 166 | |||||||||||
| 167 | =cut | ||||||||||