blib/lib/HTML/Object/Comment.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 71 CC 3 SCAR 11.0
CC
3
Cov
0%
as_string
6.0
as_xml
6.0
BEGIN
2.0
CRAP 3.0
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 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( HTML::Object::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->{open_seq} = '<!--';
32 $self->{close_seq} = '-->';
33 $self->{tag} = '_comment';
34 $self->{value} = '';
35 $self->{is_empty} = 1;
36 $self->{_init_strict_use_sub} = 1;
37 $self->{_exception_class} = 'HTML::Object::Exception';
38 $self->SUPER::init( @_ ) || return( $self->pass_error );
39 return( $self );
40 }
41  
42 sub as_string
43 {
44 my $self = shift( @_ );
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 $self->_remove_reset;
47 return(
48 $self->value->length
49 ? $self->new_scalar( join( '', '<!--', $self->value->scalar, '-->' ) )
50 : $self->original
51 );
52 }
53  
54 sub as_xml
55 {
56 my $self = shift( @_ );
57 my $txt = $self->value->length
58 ? $self->new_scalar( join( '', '<!--', $self->value->scalar, '-->' ) )
59 : $self->original;
60 # HTML::Element says there cannot be double --'s in XML comments
61 $txt->replace( qr/--/, '-&#45;' );
62 return( $txt );
63 }
64  
65 sub close_seq { return( shift->_set_get_scalar_as_object( 'close_seq', @_ ) ); }
66  
67 sub open_seq { return( shift->_set_get_scalar_as_object( 'open_seq', @_ ) ); }
68  
69 sub set_checksum
70 {
71 my $self = shift( @_ );
72 return( $self->_get_md5_hash( $self->value->scalar ) );
73 }
74  
75 sub value : lvalue { return( shift->_set_get_scalar_as_object( 'value', @_ ) ); }
76  
77 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.