| 1 | ##---------------------------------------------------------------------------- | ||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/Declaration.pm | ||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||
| 6 | ## Created 2021/12/13 | ||||||||||||
| 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::Declaration; | ||||||||||||
| 15 | BEGIN | ||||||||||||
| 16 | { | ||||||||||||
| 17 | 32 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 32 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 32 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 32 | ▶ | use parent qw( HTML::Object::Declaration HTML::Object::DOM::Node ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 32 | ▶ | use vars qw( $VERSION ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 32 | our $VERSION = 'v0.2.0'; | |||||||||||
| 23 | }; | ||||||||||||
| 24 | |||||||||||||
| 25 | 32 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 32 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | |||||||||||||
| 28 | sub init | ||||||||||||
| 29 | { | ||||||||||||
| 30 | 27 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 31 | 27 | $self->{name} = 'html'; | |||||||||||
| 32 | 27 | $self->{_init_strict_use_sub} = 1; | |||||||||||
| 33 | 27 | ▶ | $self->HTML::Object::Declaration::init( @_ ) || return( $self->pass_error ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 27 | return( $self ); | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | sub after | ||||||||||||
| 38 | { | ||||||||||||
| 39 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
after: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 40 | 0 | ▶ | my $parent = $self->parent || | ||||||||||
|
Condition0%0/2
$self->parent || (return $self->error('No parent document is set for this DTD'))
MC/DC0%0/1
$self->parent || (return $self->error('No parent document is set for this DTD'))
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||
| 41 | return( $self->error( "No parent document is set for this DTD" ) ); | ||||||||||||
| 42 | 0 | ▶ | return if( !$parent ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 0 | my $nodes = $self->_list_to_nodes( @_ ); | |||||||||||
| 44 | 0 | ▶ | return if( $nodes->is_empty ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 0 | my $refNode = $self; | |||||||||||
| 46 | 0 | foreach my $node ( @$nodes ) | |||||||||||
| 47 | { | ||||||||||||
| 48 | 0 | $parent->insertAfter( $node, $refNode ); | |||||||||||
| 49 | 0 | $refNode = $node; | |||||||||||
| 50 | } | ||||||||||||
| 51 | 0 | return( $self ); | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | sub before | ||||||||||||
| 55 | { | ||||||||||||
| 56 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
before: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 57 | 0 | ▶ | my $parent = $self->parent || | ||||||||||
|
Condition0%0/2
$self->parent || (return $self->error('No parent document is set for this DTD'))
MC/DC0%0/1
$self->parent || (return $self->error('No parent document is set for this DTD'))
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||
| 58 | return( $self->error( "No parent document is set for this DTD" ) ); | ||||||||||||
| 59 | 0 | ▶ | return if( !$parent ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 0 | my $nodes = $self->_list_to_nodes( @_ ); | |||||||||||
| 61 | 0 | ▶ | return if( $nodes->is_empty ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 0 | my $refNode = $self; | |||||||||||
| 63 | 0 | foreach my $node ( @$nodes ) | |||||||||||
| 64 | { | ||||||||||||
| 65 | 0 | $parent->insertBefore( $node, $refNode ); | |||||||||||
| 66 | 0 | $refNode = $node; | |||||||||||
| 67 | } | ||||||||||||
| 68 | 0 | return( $self ); | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | # Note: property internalSubset read-only | ||||||||||||
| 72 | 0 | ▶ | sub internalSubset { return( shift->new_scalar ); } | ||||||||||
|
Subroutine
internalSubset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 73 | |||||||||||||
| 74 | # Note: property name read-only | ||||||||||||
| 75 | 1 | ▶ | sub name : lvalue { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); } | ||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 76 | |||||||||||||
| 77 | # Note: property notations read-only | ||||||||||||
| 78 | 0 | ▶ | sub notations { return; } | ||||||||||
|
Subroutine
notations: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 79 | |||||||||||||
| 80 | # Note: property publicId read-only | ||||||||||||
| 81 | sub publicId | ||||||||||||
| 82 | { | ||||||||||||
| 83 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
publicId: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||
| 84 | 1 | ▶ | if( my $rv = $self->original->match( qr/PUBLIC[[:blank:]\h]+\"([^\"]+)\"/ ) ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | { | ||||||||||||
| 86 | 0 | return( $rv->capture->first ); | |||||||||||
| 87 | } | ||||||||||||
| 88 | 1 | return( '' ); | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | sub remove | ||||||||||||
| 92 | { | ||||||||||||
| 93 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
remove: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 94 | 0 | ▶ | my $parent = $self->parent || return; | ||||||||||
|
Condition0%0/2
$self->parent || (return)
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||
| 95 | 0 | $parent->removeChild( $self ); | |||||||||||
| 96 | 0 | return( $self ); | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | sub replaceWith | ||||||||||||
| 100 | { | ||||||||||||
| 101 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
replaceWith: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 102 | 0 | ▶ | my $parent = $self->parent || return; | ||||||||||
|
Condition0%0/2
$self->parent || (return)
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||
| 103 | 0 | ▶ | my $list = $self->_list_to_nodes( @_ ) || return( $self->pass_error ); | ||||||||||
|
Condition0%0/2
$self->_list_to_nodes(@_) || (return $self->pass_error)
MC/DC0%0/1
$self->_list_to_nodes(@_) || (return $self->pass_error)
$self->_list_to_nodes(@_)
Truth table0%0/2
A
A= $self->_list_to_nodes(@_)
| |||||||||||||
| 104 | 0 | my $pos = $parent->nodes->pos( $self ); | |||||||||||
| 105 | 0 | ▶ | return( $self->error( "Unable to find our DTD object in our parent's nodes" ) ) if( !defined( $pos ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 0 | my $dtd; | |||||||||||
| 107 | $list->foreach(sub | ||||||||||||
| 108 | { | ||||||||||||
| 109 | 0 | ▶ | $_->parent( $parent ); | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 110 | 0 | ▶ | if( $self->_is_a( $_ => 'HTML::Object::DOM::Declaration' ) ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | { | ||||||||||||
| 112 | 0 | $dtd = $_; | |||||||||||
| 113 | } | ||||||||||||
| 114 | 0 | }); | |||||||||||
| 115 | 0 | $parent->nodes->splice( $pos, 1, $list->list ); | |||||||||||
| 116 | # Either an DTD object, if we found one, or undef | ||||||||||||
| 117 | 0 | $parent->declaration( $dtd ); | |||||||||||
| 118 | 0 | $parent->reset(1); | |||||||||||
| 119 | 0 | return( $self ); | |||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | 16 | ▶ | sub string_value { return; } | ||||||||||
|
Subroutine
string_value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 123 | |||||||||||||
| 124 | # Note: property systemId read-only | ||||||||||||
| 125 | sub systemId | ||||||||||||
| 126 | { | ||||||||||||
| 127 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
systemId: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||
| 128 | 1 | ▶ | if( my $rv = $self->original->match( qr/[[:blank:]\h]+\"(http[^\"]+)\"/ ) ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 129 | { | ||||||||||||
| 130 | 0 | return( $rv->capture->first ); | |||||||||||
| 131 | } | ||||||||||||
| 132 | 1 | return( '' ); | |||||||||||
| 133 | } | ||||||||||||
| 134 | |||||||||||||
| 135 | 32 | 1; | |||||||||||
| 136 | # NOTE: POD | ||||||||||||
| 137 | __END__ | ||||||||||||
| 138 | |||||||||||||
| 139 | =encoding utf-8 | ||||||||||||
| 140 | |||||||||||||
| 141 | =head1 NAME | ||||||||||||
| 142 | |||||||||||||
| 143 | HTML::Object::DOM::Declaration - HTML Object DOM DTD | ||||||||||||
| 144 | |||||||||||||
| 145 | =head1 SYNOPSIS | ||||||||||||
| 146 | |||||||||||||
| 147 | use HTML::Object::DOM::Declaration; | ||||||||||||
| 148 | my $decl = HTML::Object::DOM::Declaration->new || | ||||||||||||
| 149 | die( HTML::Object::DOM::Declaration->error, "\n" ); | ||||||||||||
| 150 | |||||||||||||
| 151 | =head1 VERSION | ||||||||||||
| 152 | |||||||||||||
| 153 | v0.2.0 | ||||||||||||
| 154 | |||||||||||||
| 155 | =head1 DESCRIPTION | ||||||||||||
| 156 | |||||||||||||
| 157 | This module implements an HTTML declaration for the DOM. It inherits from L<HTML::Object::Declaration> and L<HTTML::Object::DOM::Node> | ||||||||||||
| 158 | |||||||||||||
| 159 | =head1 INHERITANCE | ||||||||||||
| 160 | |||||||||||||
| 161 | +---------------------------+ +---------------------------+ +-------------------------+ +--------------------------------+ | ||||||||||||
| 162 | | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Declaration | | ||||||||||||
| 163 | +---------------------------+ +---------------------------+ +-------------------------+ +--------------------------------+ | ||||||||||||
| 164 | | ^ | ||||||||||||
| 165 | | | | ||||||||||||
| 166 | v | | ||||||||||||
| 167 | +---------------------------+ | | ||||||||||||
| 168 | | HTML::Object::Declaration | ------------------------------------------------------------------------+ | ||||||||||||
| 169 | +---------------------------+ | ||||||||||||
| 170 | |||||||||||||
| 171 | =head1 PROPERTIES | ||||||||||||
| 172 | |||||||||||||
| 173 | Inherits properties from its parents L<HTML::Object::Declaration> and L<HTML::Object::DOM::Node> | ||||||||||||
| 174 | |||||||||||||
| 175 | =head2 internalSubset | ||||||||||||
| 176 | |||||||||||||
| 177 | Read-only. | ||||||||||||
| 178 | |||||||||||||
| 179 | A string of the internal subset, or C<undef> if there is none. Eg "<!ELEMENT foo (bar)>". | ||||||||||||
| 180 | |||||||||||||
| 181 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/internalSubset> | ||||||||||||
| 182 | |||||||||||||
| 183 | =head2 name | ||||||||||||
| 184 | |||||||||||||
| 185 | Read-only. | ||||||||||||
| 186 | |||||||||||||
| 187 | A string, eg "html" for <!DOCTYPE HTML>. | ||||||||||||
| 188 | |||||||||||||
| 189 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/name> | ||||||||||||
| 190 | |||||||||||||
| 191 | =head2 notations | ||||||||||||
| 192 | |||||||||||||
| 193 | Always returns C<undef> under perl. | ||||||||||||
| 194 | |||||||||||||
| 195 | Normally, under JavaScript, this returns s C<NamedNodeMap> with notations declared in the DTD. | ||||||||||||
| 196 | |||||||||||||
| 197 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/notations> | ||||||||||||
| 198 | |||||||||||||
| 199 | =head2 publicId | ||||||||||||
| 200 | |||||||||||||
| 201 | Read-only. | ||||||||||||
| 202 | |||||||||||||
| 203 | A string, eg "-//W3C//DTD HTML 4.01//EN", empty string for HTML5. | ||||||||||||
| 204 | |||||||||||||
| 205 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/publicId> | ||||||||||||
| 206 | |||||||||||||
| 207 | =head2 systemId | ||||||||||||
| 208 | |||||||||||||
| 209 | Read-only. | ||||||||||||
| 210 | |||||||||||||
| 211 | A string, eg "http://www.w3.org/TR/html4/strict.dtd", empty string for HTML5. | ||||||||||||
| 212 | |||||||||||||
| 213 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/systemId> | ||||||||||||
| 214 | |||||||||||||
| 215 | =head1 METHODS | ||||||||||||
| 216 | |||||||||||||
| 217 | Inherits methods from its parents L<HTML::Object::Declaration> and L<HTML::Object::DOM::Node> | ||||||||||||
| 218 | |||||||||||||
| 219 | =head2 after | ||||||||||||
| 220 | |||||||||||||
| 221 | Inserts a set of L<Node|HTML::Object::DOM::Node> or string objects in the children list of the | ||||||||||||
| 222 | C<DocumentType>'s parent, just after the C<DocumentType> object. | ||||||||||||
| 223 | |||||||||||||
| 224 | Example: | ||||||||||||
| 225 | |||||||||||||
| 226 | my $docType = $doc->implementation->createDocumentType("html", "", ""); | ||||||||||||
| 227 | my $myDoc = $doc->implementation->createDocument("", "", $docType); | ||||||||||||
| 228 | |||||||||||||
| 229 | $docType->after($doc->createElement('html')); | ||||||||||||
| 230 | |||||||||||||
| 231 | $myDoc->childNodes; | ||||||||||||
| 232 | # NodeList [<!DOCTYPE html>, <html>] | ||||||||||||
| 233 | |||||||||||||
| 234 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/after> | ||||||||||||
| 235 | |||||||||||||
| 236 | =head2 before | ||||||||||||
| 237 | |||||||||||||
| 238 | Inserts a set of Node or string objects in the children list of the | ||||||||||||
| 239 | C<DocumentType>'s parent, just before the C<DocumentType> object. | ||||||||||||
| 240 | |||||||||||||
| 241 | Example: | ||||||||||||
| 242 | |||||||||||||
| 243 | my $docType = $doc->implementation->createDocumentType("html", "", ""); | ||||||||||||
| 244 | my $myDoc = $doc->implementation->createDocument("", "", $docType); | ||||||||||||
| 245 | |||||||||||||
| 246 | $docType->before( $doc->createComment('<!--[if !IE]> conditional comment <![endif]-->') ); | ||||||||||||
| 247 | |||||||||||||
| 248 | $myDoc->childNodes; | ||||||||||||
| 249 | # NodeList [<!--[if !IE]> conditional comment <![endif]-->, <!DOCTYPE html>] | ||||||||||||
| 250 | |||||||||||||
| 251 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/before> | ||||||||||||
| 252 | |||||||||||||
| 253 | =head2 remove | ||||||||||||
| 254 | |||||||||||||
| 255 | Removes the object from its parent children list. | ||||||||||||
| 256 | |||||||||||||
| 257 | Example: | ||||||||||||
| 258 | |||||||||||||
| 259 | $doc->doctype; # "<!DOCTYPE html>' | ||||||||||||
| 260 | $doc->doctype->remove(); | ||||||||||||
| 261 | $doc->doctype; # null | ||||||||||||
| 262 | |||||||||||||
| 263 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/remove> | ||||||||||||
| 264 | |||||||||||||
| 265 | =head2 replaceWith | ||||||||||||
| 266 | |||||||||||||
| 267 | Replaces the document type with a set of given nodes. | ||||||||||||
| 268 | |||||||||||||
| 269 | Example: | ||||||||||||
| 270 | |||||||||||||
| 271 | my $svg_dt = $doc->implementation->createDocumentType( | ||||||||||||
| 272 | 'svg:svg', | ||||||||||||
| 273 | '-//W3C//DTD SVG 1.1//EN', | ||||||||||||
| 274 | 'http://www->w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' | ||||||||||||
| 275 | ); | ||||||||||||
| 276 | |||||||||||||
| 277 | $doc->doctype->replaceWith($svg_dt); | ||||||||||||
| 278 | |||||||||||||
| 279 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/replaceWith> | ||||||||||||
| 280 | |||||||||||||
| 281 | =head2 string_value | ||||||||||||
| 282 | |||||||||||||
| 283 | Always returns C<undef> | ||||||||||||
| 284 | |||||||||||||
| 285 | =head1 AUTHOR | ||||||||||||
| 286 | |||||||||||||
| 287 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||
| 288 | |||||||||||||
| 289 | =head1 SEE ALSO | ||||||||||||
| 290 | |||||||||||||
| 291 | L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/DocumentType> | ||||||||||||
| 292 | |||||||||||||
| 293 | =head1 COPYRIGHT & LICENSE | ||||||||||||
| 294 | |||||||||||||
| 295 | Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||
| 296 | |||||||||||||
| 297 | All rights reserved | ||||||||||||
| 298 | |||||||||||||
| 299 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||
| 300 | |||||||||||||
| 301 | =cut | ||||||||||||