| 1 | ##---------------------------------------------------------------------------- | ||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM.pm | ||
| 3 | ## Version v0.5.1 | ||
| 4 | ## Copyright(c) 2024 DEGUEST Pte. Ltd. | ||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||
| 6 | ## Created 2021/12/13 | ||
| 7 | ## Modified 2026/07/04 | ||
| 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; | ||
| 15 | BEGIN | ||
| 16 | { | ||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | warnings::register_categories( 'HTML::Object' ); | ||
| 20 | use parent qw( HTML::Object ); | ||
| 21 | use vars qw( @EXPORT_OK %EXPORT_TAGS $SCREEN $WINDOW $TAG_TO_CLASS $GLOBAL_DOM $VERSION ); | ||
| 22 | use HTML::Object::DOM::Closing; | ||
| 23 | use HTML::Object::DOM::Comment; | ||
| 24 | use HTML::Object::DOM::Declaration; | ||
| 25 | use HTML::Object::DOM::Document; | ||
| 26 | use HTML::Object::DOM::Element; | ||
| 27 | use HTML::Object::DOM::Space; | ||
| 28 | use HTML::Object::DOM::Text; | ||
| 29 | use HTML::Object::DOM::Screen; | ||
| 30 | use HTML::Object::DOM::Window; | ||
| 31 | use Scalar::Util (); | ||
| 32 | use constant { | ||
| 33 | # For HTML::Object::DOM::Node | ||
| 34 | DOCUMENT_POSITION_IDENTICAL => 0, | ||
| 35 | DOCUMENT_POSITION_DISCONNECTED => 1, | ||
| 36 | DOCUMENT_POSITION_PRECEDING => 2, | ||
| 37 | DOCUMENT_POSITION_FOLLOWING => 4, | ||
| 38 | DOCUMENT_POSITION_CONTAINS => 8, | ||
| 39 | DOCUMENT_POSITION_CONTAINED_BY => 16, | ||
| 40 | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC => 32, | ||
| 41 | |||
| 42 | ELEMENT_NODE => 1, | ||
| 43 | ATTRIBUTE_NODE => 2, | ||
| 44 | TEXT_NODE => 3, | ||
| 45 | CDATA_SECTION_NODE => 4, | ||
| 46 | # Deprecated | ||
| 47 | ENTITY_REFERENCE_NODE => 5, | ||
| 48 | # Deprecated | ||
| 49 | ENTITY_NODE => 6, | ||
| 50 | PROCESSING_INSTRUCTION_NODE => 7, | ||
| 51 | COMMENT_NODE => 8, | ||
| 52 | DOCUMENT_NODE => 9, | ||
| 53 | DOCUMENT_TYPE_NODE => 10, | ||
| 54 | DOCUMENT_FRAGMENT_NODE => 11, | ||
| 55 | NOTATION_NODE => 12, | ||
| 56 | # non-standard addition, because we distinguish space from text | ||
| 57 | SPACE_NODE => 13, | ||
| 58 | |||
| 59 | # For HTML::Object::DOM::Element::Media | ||
| 60 | # There is no data yet. Also, readyState is HAVE_NOTHING. | ||
| 61 | NETWORK_EMPTY => 0, | ||
| 62 | # HTMLMediaElement is active and has selected a resource, but is not using the network. | ||
| 63 | NETWORK_IDLE => 1, | ||
| 64 | # The browser is downloading HTMLMediaElement data. | ||
| 65 | NETWORK_LOADING => 2, | ||
| 66 | # No HTMLMediaElement src found. | ||
| 67 | NETWORK_NO_SOURCE => 3, | ||
| 68 | |||
| 69 | # For HTML::Object::DOM::Element::Track | ||
| 70 | # Indicates that the text track's cues have not been obtained. | ||
| 71 | NONE => 0, | ||
| 72 | # Indicates that the text track is loading and there have been no fatal errors encountered so far. Further cues might still be added to the track by the parser. | ||
| 73 | LOADING => 1, | ||
| 74 | # Indicates that the text track has been loaded with no fatal errors. | ||
| 75 | LOADED => 2, | ||
| 76 | # Indicates that the text track was enabled, but when the user agent attempted to obtain it, this failed in some way. Some or all of the cues are likely missing and will not be obtained. | ||
| 77 | ERROR => 3, | ||
| 78 | |||
| 79 | # For HTML::Object::Event | ||
| 80 | # NONE => 0, | ||
| 81 | CAPTURING_PHASE => 1, | ||
| 82 | AT_TARGET => 2, | ||
| 83 | BUBBLING_PHASE => 3, | ||
| 84 | |||
| 85 | CANCEL_PROPAGATION => 1, | ||
| 86 | CANCEL_IMMEDIATE_PROPAGATION => 2, | ||
| 87 | |||
| 88 | # HTML::Object::DOM::NodeFilter | ||
| 89 | # Shows all nodes. | ||
| 90 | SHOW_ALL => 4294967295, | ||
| 91 | # Shows Element nodes. | ||
| 92 | SHOW_ELEMENT => 1, | ||
| 93 | # Shows attribute Attr nodes. | ||
| 94 | SHOW_ATTRIBUTE => 2, | ||
| 95 | # Shows Text nodes. | ||
| 96 | SHOW_TEXT => 4, | ||
| 97 | # Shows CDATASection nodes. | ||
| 98 | SHOW_CDATA_SECTION => 8, | ||
| 99 | # Legacy, no more used. | ||
| 100 | SHOW_ENTITY_REFERENCE => 16, | ||
| 101 | # Legacy, no more used. | ||
| 102 | SHOW_ENTITY => 32, | ||
| 103 | # Shows ProcessingInstruction nodes. | ||
| 104 | SHOW_PROCESSING_INSTRUCTION => 64, | ||
| 105 | # Shows Comment nodes. | ||
| 106 | SHOW_COMMENT => 128, | ||
| 107 | # Shows Document nodes. | ||
| 108 | SHOW_DOCUMENT => 256, | ||
| 109 | # Shows DocumentType nodes. | ||
| 110 | SHOW_DOCUMENT_TYPE => 512, | ||
| 111 | # Shows DocumentFragment nodes. | ||
| 112 | SHOW_DOCUMENT_FRAGMENT => 1024, | ||
| 113 | # Legacy, no more used. | ||
| 114 | SHOW_NOTATION => 2048, | ||
| 115 | # Show spaces | ||
| 116 | SHOW_SPACE => 4096, | ||
| 117 | |||
| 118 | FILTER_ACCEPT => 1, | ||
| 119 | FILTER_REJECT => 2, | ||
| 120 | FILTER_SKIP => 3, | ||
| 121 | |||
| 122 | # HTML::Object::DOM::XPathResult | ||
| 123 | # A result set containing whatever type naturally results from evaluation of the expression. Note that if the result is a node-set then UNORDERED_NODE_ITERATOR_TYPE is always the resulting type. | ||
| 124 | ANY_TYPE => 0, | ||
| 125 | # A result containing a single number. This is useful for example, in an XPath expression using the count() function. | ||
| 126 | NUMBER_TYPE => 1, | ||
| 127 | # A result containing a single string. | ||
| 128 | STRING_TYPE => 2, | ||
| 129 | # A result containing a single boolean value. This is useful for example, in an XPath expression using the not() function. | ||
| 130 | BOOLEAN_TYPE => 3, | ||
| 131 | # A result node-set containing all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document. | ||
| 132 | UNORDERED_NODE_ITERATOR_TYPE => 4, | ||
| 133 | # A result node-set containing all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document. | ||
| 134 | ORDERED_NODE_ITERATOR_TYPE => 5, | ||
| 135 | # A result node-set containing snapshots of all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document. | ||
| 136 | UNORDERED_NODE_SNAPSHOT_TYPE => 6, | ||
| 137 | # A result node-set containing snapshots of all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document. | ||
| 138 | ORDERED_NODE_SNAPSHOT_TYPE => 7, | ||
| 139 | # A result node-set containing any single node that matches the expression. The node is not necessarily the first node in the document that matches the expression. | ||
| 140 | ANY_UNORDERED_NODE_TYPE => 8, | ||
| 141 | # A result node-set containing the first node in the document that matches the expression. | ||
| 142 | FIRST_ORDERED_NODE_TYPE => 9, | ||
| 143 | }; | ||
| 144 | our @EXPORT_OK = qw( | ||
| 145 | screen window | ||
| 146 | |||
| 147 | DOCUMENT_POSITION_IDENTICAL | ||
| 148 | DOCUMENT_POSITION_DISCONNECTED | ||
| 149 | DOCUMENT_POSITION_PRECEDING | ||
| 150 | DOCUMENT_POSITION_FOLLOWING | ||
| 151 | DOCUMENT_POSITION_CONTAINS | ||
| 152 | DOCUMENT_POSITION_CONTAINED_BY | ||
| 153 | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | ||
| 154 | |||
| 155 | ELEMENT_NODE | ||
| 156 | ATTRIBUTE_NODE | ||
| 157 | TEXT_NODE | ||
| 158 | CDATA_SECTION_NODE | ||
| 159 | ENTITY_REFERENCE_NODE | ||
| 160 | ENTITY_NODE | ||
| 161 | PROCESSING_INSTRUCTION_NODE | ||
| 162 | COMMENT_NODE | ||
| 163 | DOCUMENT_NODE | ||
| 164 | DOCUMENT_TYPE_NODE | ||
| 165 | DOCUMENT_FRAGMENT_NODE | ||
| 166 | NOTATION_NODE | ||
| 167 | SPACE_NODE | ||
| 168 | |||
| 169 | NETWORK_EMPTY NETWORK_IDLE NETWORK_LOADING NETWORK_NO_SOURCE | ||
| 170 | NONE LOADING LOADED ERROR | ||
| 171 | CAPTURING_PHASE AT_TARGET BUBBLING_PHASE CANCEL_PROPAGATION CANCEL_IMMEDIATE_PROPAGATION | ||
| 172 | |||
| 173 | SHOW_ALL SHOW_ELEMENT SHOW_ATTRIBUTE SHOW_TEXT SHOW_CDATA_SECTION | ||
| 174 | SHOW_ENTITY_REFERENCE SHOW_ENTITY SHOW_PROCESSING_INSTRUCTION SHOW_COMMENT | ||
| 175 | SHOW_DOCUMENT SHOW_DOCUMENT_TYPE SHOW_DOCUMENT_FRAGMENT SHOW_NOTATION SHOW_SPACE | ||
| 176 | FILTER_ACCEPT FILTER_REJECT FILTER_SKIP | ||
| 177 | |||
| 178 | ANY_TYPE NUMBER_TYPE STRING_TYPE BOOLEAN_TYPE | ||
| 179 | UNORDERED_NODE_ITERATOR_TYPE ORDERED_NODE_ITERATOR_TYPE | ||
| 180 | UNORDERED_NODE_SNAPSHOT_TYPE ORDERED_NODE_SNAPSHOT_TYPE | ||
| 181 | ANY_UNORDERED_NODE_TYPE FIRST_ORDERED_NODE_TYPE | ||
| 182 | ); | ||
| 183 | our %EXPORT_TAGS = ( | ||
| 184 | event => [qw( | ||
| 185 | NONE LOADING LOADED ERROR | ||
| 186 | CAPTURING_PHASE AT_TARGET BUBBLING_PHASE CANCEL_PROPAGATION CANCEL_IMMEDIATE_PROPAGATION | ||
| 187 | )], | ||
| 188 | filter => [qw( | ||
| 189 | SHOW_ALL SHOW_ELEMENT SHOW_ATTRIBUTE SHOW_TEXT SHOW_CDATA_SECTION | ||
| 190 | SHOW_ENTITY_REFERENCE SHOW_ENTITY SHOW_PROCESSING_INSTRUCTION SHOW_COMMENT | ||
| 191 | SHOW_DOCUMENT SHOW_DOCUMENT_TYPE SHOW_DOCUMENT_FRAGMENT SHOW_NOTATION SHOW_SPACE | ||
| 192 | FILTER_ACCEPT FILTER_REJECT FILTER_SKIP | ||
| 193 | )], | ||
| 194 | # HTML::Object::DOM::Element::Media | ||
| 195 | media => [qw( NETWORK_EMPTY NETWORK_IDLE NETWORK_LOADING NETWORK_NO_SOURCE )], | ||
| 196 | # HTML::Object::DOM::Node | ||
| 197 | node => [qw( | ||
| 198 | DOCUMENT_POSITION_IDENTICAL | ||
| 199 | DOCUMENT_POSITION_DISCONNECTED | ||
| 200 | DOCUMENT_POSITION_PRECEDING | ||
| 201 | DOCUMENT_POSITION_FOLLOWING | ||
| 202 | DOCUMENT_POSITION_CONTAINS | ||
| 203 | DOCUMENT_POSITION_CONTAINED_BY | ||
| 204 | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | ||
| 205 | |||
| 206 | ELEMENT_NODE | ||
| 207 | ATTRIBUTE_NODE | ||
| 208 | TEXT_NODE | ||
| 209 | CDATA_SECTION_NODE | ||
| 210 | ENTITY_REFERENCE_NODE | ||
| 211 | ENTITY_NODE | ||
| 212 | PROCESSING_INSTRUCTION_NODE | ||
| 213 | COMMENT_NODE | ||
| 214 | DOCUMENT_NODE | ||
| 215 | DOCUMENT_TYPE_NODE | ||
| 216 | DOCUMENT_FRAGMENT_NODE | ||
| 217 | NOTATION_NODE | ||
| 218 | SPACE_NODE | ||
| 219 | )], | ||
| 220 | track => [qw( NONE LOADING LOADED ERROR )], | ||
| 221 | xpath => [qw( | ||
| 222 | ANY_TYPE NUMBER_TYPE STRING_TYPE BOOLEAN_TYPE | ||
| 223 | UNORDERED_NODE_ITERATOR_TYPE ORDERED_NODE_ITERATOR_TYPE | ||
| 224 | UNORDERED_NODE_SNAPSHOT_TYPE ORDERED_NODE_SNAPSHOT_TYPE | ||
| 225 | ANY_UNORDERED_NODE_TYPE FIRST_ORDERED_NODE_TYPE | ||
| 226 | )], | ||
| 227 | ); | ||
| 228 | $EXPORT_TAGS{all} = [@EXPORT_OK]; | ||
| 229 | our $SCREEN = HTML::Object::DOM::Screen->new; | ||
| 230 | our $WINDOW; | ||
| 231 | # An hash reference map to lowercase HTML tag name to perl class, for those who have special classes, otherwise the fallback is HTML::Object::Element. | ||
| 232 | our $TAG_TO_CLASS = {}; | ||
| 233 | our $GLOBAL_DOM; | ||
| 234 | our $VERSION = 'v0.5.1'; | ||
| 235 | }; | ||
| 236 | |||
| 237 | use strict; | ||
| 238 | use warnings; | ||
| 239 | |||
| 240 | { | ||
| 241 | # "If name is applet, bgsound, blink, isindex, keygen, multicol, nextid, or spacer, then return HTMLUnknownElement." | ||
| 242 | # "If name is acronym, basefont, big, center, nobr, noembed, noframes, plaintext, rb, rtc, strike, or tt, then return HTMLElement." | ||
| 243 | # "If name is listing or xmp, then return HTMLPreElement." | ||
| 244 | # <https://html.spec.whatwg.org/multipage/dom.html#htmlunknownelement> | ||
| 245 | $TAG_TO_CLASS = | ||
| 246 | { | ||
| 247 | a => 'HTML::Object::DOM::Element::Anchor', | ||
| 248 | acronym => 'HTML::Object::DOM::Element', | ||
| 249 | # Deprecated | ||
| 250 | applet => 'HTML::Object::DOM::Element::Unknown', | ||
| 251 | area => 'HTML::Object::DOM::Element::Area', | ||
| 252 | audio => 'HTML::Object::DOM::Element::Audio', | ||
| 253 | base => 'HTML::Object::DOM::Element::Base', | ||
| 254 | basefont => 'HTML::Object::DOM::Element', | ||
| 255 | # Deprecated | ||
| 256 | bgsound => 'HTML::Object::DOM::Element::Unknown', | ||
| 257 | big => 'HTML::Object::DOM::Element', | ||
| 258 | # Deprecated | ||
| 259 | blink => 'HTML::Object::DOM::Element::Unknown', | ||
| 260 | blockquote => 'HTML::Object::DOM::Element::Quote', | ||
| 261 | body => 'HTML::Object::DOM::Element::Body', | ||
| 262 | br => 'HTML::Object::DOM::Element::BR', | ||
| 263 | button => 'HTML::Object::DOM::Element::Button', | ||
| 264 | canvas => 'HTML::Object::DOM::Element::Canvas', | ||
| 265 | caption => 'HTML::Object::DOM::Element::TableCaption', | ||
| 266 | center => 'HTML::Object::DOM::Element', | ||
| 267 | col => 'HTML::Object::DOM::Element::TableCol', | ||
| 268 | colgroup => 'HTML::Object::DOM::Element::TableCol', | ||
| 269 | data => 'HTML::Object::DOM::Element::Data', | ||
| 270 | datalist => 'HTML::Object::DOM::Element::DataList', | ||
| 271 | details => 'HTML::Object::DOM::Element::Details', | ||
| 272 | dialog => 'HTML::Object::DOM::Element::Dialog', | ||
| 273 | div => 'HTML::Object::DOM::Element::Div', | ||
| 274 | dl => 'HTML::Object::DOM::Element::DList', | ||
| 275 | # "Firefox implements the HTMLSpanElement interface for this element." | ||
| 276 | # <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dt> | ||
| 277 | dt => 'HTML::Object::DOM::Element::Span', | ||
| 278 | dd => 'HTML::Object::DOM::Element', | ||
| 279 | embed => 'HTML::Object::DOM::Element::Embed', | ||
| 280 | fieldset => 'HTML::Object::DOM::Element::FieldSet', | ||
| 281 | font => 'HTML::Object::DOM::Element::Unknown', | ||
| 282 | form => 'HTML::Object::DOM::Element::Form', | ||
| 283 | frame => 'HTML::Object::DOM::Element::Unknown', | ||
| 284 | frameset => 'HTML::Object::DOM::Element::Unknown', | ||
| 285 | head => 'HTML::Object::DOM::Element::Head', | ||
| 286 | h1 => 'HTML::Object::DOM::Element::Heading', | ||
| 287 | h2 => 'HTML::Object::DOM::Element::Heading', | ||
| 288 | h3 => 'HTML::Object::DOM::Element::Heading', | ||
| 289 | h4 => 'HTML::Object::DOM::Element::Heading', | ||
| 290 | h5 => 'HTML::Object::DOM::Element::Heading', | ||
| 291 | h6 => 'HTML::Object::DOM::Element::Heading', | ||
| 292 | hr => 'HTML::Object::DOM::Element::HR', | ||
| 293 | html => 'HTML::Object::DOM::Element::HTML', | ||
| 294 | iframe => 'HTML::Object::DOM::Element::IFrame', | ||
| 295 | image => 'HTML::Object::DOM::Element::Image', | ||
| 296 | input => 'HTML::Object::DOM::Element::Input', | ||
| 297 | # Deprecated | ||
| 298 | isindex => 'HTML::Object::DOM::Element::Unknown', | ||
| 299 | # Deprecated | ||
| 300 | keygen => 'HTML::Object::DOM::Element::Unknown', | ||
| 301 | label => 'HTML::Object::DOM::Element::Label', | ||
| 302 | legend => 'HTML::Object::DOM::Element::Legend', | ||
| 303 | li => 'HTML::Object::DOM::Element::LI', | ||
| 304 | 'link' => 'HTML::Object::DOM::Element::Link', | ||
| 305 | listing => 'HTML::Object::DOM::Element::Pre', | ||
| 306 | 'map' => 'HTML::Object::DOM::Element::Map', | ||
| 307 | marquee => 'HTML::Object::DOM::Element::Marquee', | ||
| 308 | media => 'HTML::Object::DOM::Element::Media', | ||
| 309 | menu => 'HTML::Object::DOM::Element::Unknown', | ||
| 310 | meta => 'HTML::Object::DOM::Element::Meta', | ||
| 311 | meter => 'HTML::Object::DOM::Element::Meter', | ||
| 312 | mod => 'HTML::Object::DOM::Element::Mod', | ||
| 313 | # Deprecated | ||
| 314 | multicol => 'HTML::Object::DOM::Element::Unknown', | ||
| 315 | # Deprecated | ||
| 316 | nextid => 'HTML::Object::DOM::Element::Unknown', | ||
| 317 | nobr => 'HTML::Object::DOM::Element', | ||
| 318 | noembed => 'HTML::Object::DOM::Element', | ||
| 319 | noframes => 'HTML::Object::DOM::Element', | ||
| 320 | object => 'HTML::Object::DOM::Element::Object', | ||
| 321 | ol => 'HTML::Object::DOM::Element::OList', | ||
| 322 | optgroup => 'HTML::Object::DOM::Element::OptGroup', | ||
| 323 | option => 'HTML::Object::DOM::Element::Option', | ||
| 324 | output => 'HTML::Object::DOM::Element::Output', | ||
| 325 | p => 'HTML::Object::DOM::Element::Paragraph', | ||
| 326 | param => 'HTML::Object::DOM::Element::Param', | ||
| 327 | picture => 'HTML::Object::DOM::Element::Picture', | ||
| 328 | plaintext => 'HTML::Object::DOM::Element', | ||
| 329 | pre => 'HTML::Object::DOM::Element::Pre', | ||
| 330 | progress => 'HTML::Object::DOM::Element::Progress', | ||
| 331 | quote => 'HTML::Object::DOM::Element::Quote', | ||
| 332 | 'q' => 'HTML::Object::DOM::Element::Quote', | ||
| 333 | rb => 'HTML::Object::DOM::Element', | ||
| 334 | rtc => 'HTML::Object::DOM::Element', | ||
| 335 | script => 'HTML::Object::DOM::Element::Script', | ||
| 336 | 'select' => 'HTML::Object::DOM::Element::Select', | ||
| 337 | slot => 'HTML::Object::DOM::Element::Slot', | ||
| 338 | source => 'HTML::Object::DOM::Element::Source', | ||
| 339 | # Deprecated | ||
| 340 | spacert => 'HTML::Object::DOM::Element::Unknown', | ||
| 341 | span => 'HTML::Object::DOM::Element::Span', | ||
| 342 | strike => 'HTML::Object::DOM::Element', | ||
| 343 | style => 'HTML::Object::DOM::Element::Style', | ||
| 344 | table => 'HTML::Object::DOM::Element::Table', | ||
| 345 | td => 'HTML::Object::DOM::Element::TableCell', | ||
| 346 | th => 'HTML::Object::DOM::Element::TableCell', | ||
| 347 | 'tr' => 'HTML::Object::DOM::Element::TableRow', | ||
| 348 | tbody => 'HTML::Object::DOM::Element::TableSection', | ||
| 349 | tfoot => 'HTML::Object::DOM::Element::TableSection', | ||
| 350 | thead => 'HTML::Object::DOM::Element::TableSection', | ||
| 351 | template => 'HTML::Object::DOM::Element::Template', | ||
| 352 | textarea => 'HTML::Object::DOM::Element::TextArea', | ||
| 353 | 'time' => 'HTML::Object::DOM::Element::Time', | ||
| 354 | title => 'HTML::Object::DOM::Element::Title', | ||
| 355 | track => 'HTML::Object::DOM::Element::Track', | ||
| 356 | tt => 'HTML::Object::DOM::Element', | ||
| 357 | video => 'HTML::Object::DOM::Element::Video', | ||
| 358 | xmp => 'HTML::Object::DOM::Element::Pre', | ||
| 359 | }; | ||
| 360 | } | ||
| 361 | |||
| 362 | # *import = \&Exporter::import; | ||
| 363 | |||
| 364 | sub init | ||
| 365 | { | ||
| 366 | my $self = shift( @_ ); | ||
| 367 | $self->{onload} = undef; | ||
| 368 | $self->{onreadystatechange} = undef; | ||
| 369 | $self->{_init_strict_use_sub} = 1; | ||
| 370 | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||
| 371 | my $win = $self->new_window( debug => $self->debug ); | ||
| 372 | $self->window( $win ); | ||
| 373 | return( $self ); | ||
| 374 | } | ||
| 375 | |||
| 376 | sub current_parent { return( shift->_set_get_object_without_init( 'current_parent', 'HTML::Object::DOM::Node', @_ ) ); } | ||
| 377 | |||
| 378 | sub document { return( shift->_set_get_object( 'document', 'HTML::Object::DOM::Document', @_ ) ); } | ||
| 379 | |||
| 380 | sub get_definition | ||
| 381 | { | ||
| 382 | my $self = shift( @_ ); | ||
| 383 | my $tag = shift( @_ ); | ||
| 384 | return( $self->error( "No tag was provided to get its definition." ) ) if( !length( $tag ) ); | ||
| 385 | # Just to be sure | ||
| 386 | $tag = lc( $tag ); | ||
| 387 | my $def = $self->SUPER::get_definition( $tag, @_ ) || return( $self->pass_error ); | ||
| 388 | $def->{class} = $TAG_TO_CLASS->{ $tag } if( CORE::exists( $TAG_TO_CLASS->{ $tag } ) ); | ||
| 389 | return( $def ); | ||
| 390 | } | ||
| 391 | |||
| 392 | sub get_dom { return( $GLOBAL_DOM ); } | ||
| 393 | |||
| 394 | sub new_closing | ||
| 395 | { | ||
| 396 | my $self = shift( @_ ); | ||
| 397 | my $e = HTML::Object::DOM::Closing->new( @_ ) || | ||
| 398 | return( $self->pass_error( HTML::Object::DOM::Closing->error ) ); | ||
| 399 | return( $e ); | ||
| 400 | } | ||
| 401 | |||
| 402 | sub new_comment | ||
| 403 | { | ||
| 404 | my $self = shift( @_ ); | ||
| 405 | my $e = HTML::Object::DOM::Comment->new( @_ ) || | ||
| 406 | return( $self->pass_error( HTML::Object::DOM::Comment->error ) ); | ||
| 407 | $e->debug( $self->debug ); | ||
| 408 | return( $e ); | ||
| 409 | } | ||
| 410 | |||
| 411 | sub new_declaration | ||
| 412 | { | ||
| 413 | my $self = shift( @_ ); | ||
| 414 | my $e = HTML::Object::DOM::Declaration->new( @_ ) || | ||
| 415 | return( $self->pass_error( HTML::Object::DOM::Declaration->error ) ); | ||
| 416 | $e->debug( $self->debug ); | ||
| 417 | return( $e ); | ||
| 418 | } | ||
| 419 | |||
| 420 | sub new_document | ||
| 421 | { | ||
| 422 | my $self = shift( @_ ); | ||
| 423 | my $e = HTML::Object::DOM::Document->new( @_ ) || | ||
| 424 | return( $self->pass_error( HTML::Object::DOM::Document->error ) ); | ||
| 425 | my $win = $self->window; | ||
| 426 | $e->defaultView( $win ); | ||
| 427 | $e->debug( $self->debug ); | ||
| 428 | return( $e ); | ||
| 429 | } | ||
| 430 | |||
| 431 | sub new_element | ||
| 432 | { | ||
| 433 | my $self = shift( @_ ); | ||
| 434 | my $e = HTML::Object::DOM::Element->new( @_ ) || | ||
| 435 | return( $self->pass_error( HTML::Object::DOM::Element->error ) ); | ||
| 436 | $e->debug( $self->debug ); | ||
| 437 | return( $e ); | ||
| 438 | } | ||
| 439 | |||
| 440 | sub new_space | ||
| 441 | { | ||
| 442 | my $self = shift( @_ ); | ||
| 443 | my $e = HTML::Object::DOM::Space->new( @_ ) || | ||
| 444 | return( $self->pass_error( HTML::Object::DOM::Space->error ) ); | ||
| 445 | return( $e ); | ||
| 446 | } | ||
| 447 | |||
| 448 | sub new_text | ||
| 449 | { | ||
| 450 | my $self = shift( @_ ); | ||
| 451 | my $e = HTML::Object::DOM::Text->new( @_ ) || | ||
| 452 | return( $self->pass_error( HTML::Object::DOM::Text->error ) ); | ||
| 453 | $e->debug( $self->debug ); | ||
| 454 | return( $e ); | ||
| 455 | } | ||
| 456 | |||
| 457 | sub new_window | ||
| 458 | { | ||
| 459 | my $self = shift( @_ ); | ||
| 460 | my $e = HTML::Object::DOM::Window->new( @_ ) || | ||
| 461 | return( $self->pass_error( HTML::Object::DOM::Window->error ) ); | ||
| 462 | $e->screen( $SCREEN ); | ||
| 463 | $e->debug( $self->debug ); | ||
| 464 | $WINDOW = $e unless( ref( $WINDOW ) ); | ||
| 465 | return( $e ); | ||
| 466 | } | ||
| 467 | |||
| 468 | sub onload : lvalue { return( shift->_set_get_code( 'onload', @_ ) ); } | ||
| 469 | |||
| 470 | sub onreadystatechange : lvalue { return( shift->_set_get_code( 'onreadystatechange', @_ ) ); } | ||
| 471 | |||
| 472 | sub parseFromString { return( shift->parse_data( @_ ) ); } | ||
| 473 | |||
| 474 | sub screen { return( $SCREEN ); } | ||
| 475 | |||
| 476 | sub set_dom | ||
| 477 | { | ||
| 478 | my( $this, $html ) = @_; | ||
| 479 | if( defined( $html ) ) | ||
| 480 | { | ||
| 481 | if( Scalar::Util::blessed( $html ) && $html->isa( 'HTML::Object::DOM::Document' ) ) | ||
| 482 | { | ||
| 483 | $GLOBAL_DOM = $html; | ||
| 484 | } | ||
| 485 | elsif( CORE::length( $html ) ) | ||
| 486 | { | ||
| 487 | $GLOBAL_DOM = $this->new->parse( $html ); | ||
| 488 | } | ||
| 489 | } | ||
| 490 | return( $this ); | ||
| 491 | } | ||
| 492 | |||
| 493 | sub window | ||
| 494 | { | ||
| 495 | if( !scalar( @_ ) ) | ||
| 496 | { | ||
| 497 | return( $WINDOW ); | ||
| 498 | } | ||
| 499 | my $self = shift( @_ ); | ||
| 500 | if( Scalar::Util::blessed( $self ) ) | ||
| 501 | { | ||
| 502 | if( $self->isa( 'HTML::Object::DOM' ) ) | ||
| 503 | { | ||
| 504 | return( $self->_set_get_object( 'window', 'HTML::Object::DOM::Window', @_ ) ); | ||
| 505 | } | ||
| 506 | else | ||
| 507 | { | ||
| 508 | die( "You cannot call window as a class function and passing it an object other than a HTML::Object::DOM::Window object.\n" ) unless( $self->isa( 'HTML::Object::DOM::Window' ) ); | ||
| 509 | $WINDOW = $self; | ||
| 510 | } | ||
| 511 | } | ||
| 512 | else | ||
| 513 | { | ||
| 514 | die( "Unknown value (", overload::StrVal( $self ), ") provided to window() called as a HTML::Object::DOM class function\n" ); | ||
| 515 | } | ||
| 516 | } | ||
| 517 | |||
| 518 | 1; | ||
| 519 | # NOTE: POD | ||
| 520 | __END__ |