| 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 | use strict; | ||
| 18 | use warnings; | ||
| 19 | warnings::register_categories( 'HTML::Object' ); | ||
| 20 | use parent qw( HTML::Object::Declaration HTML::Object::DOM::Node ); | ||
| 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->{name} = 'html'; | ||
| 32 | $self->{_init_strict_use_sub} = 1; | ||
| 33 | $self->HTML::Object::Declaration::init( @_ ) || return( $self->pass_error ); | ||
| 34 | return( $self ); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub after | ||
| 38 | { | ||
| 39 | my $self = shift( @_ ); | ||
| 40 | my $parent = $self->parent || | ||
| 41 | return( $self->error( "No parent document is set for this DTD" ) ); | ||
| 42 | return if( !$parent ); | ||
| 43 | my $nodes = $self->_list_to_nodes( @_ ); | ||
| 44 | return if( $nodes->is_empty ); | ||
| 45 | my $refNode = $self; | ||
| 46 | foreach my $node ( @$nodes ) | ||
| 47 | { | ||
| 48 | $parent->insertAfter( $node, $refNode ); | ||
| 49 | $refNode = $node; | ||
| 50 | } | ||
| 51 | return( $self ); | ||
| 52 | } | ||
| 53 | |||
| 54 | sub before | ||
| 55 | { | ||
| 56 | my $self = shift( @_ ); | ||
| 57 | my $parent = $self->parent || | ||
| 58 | return( $self->error( "No parent document is set for this DTD" ) ); | ||
| 59 | return if( !$parent ); | ||
| 60 | my $nodes = $self->_list_to_nodes( @_ ); | ||
| 61 | return if( $nodes->is_empty ); | ||
| 62 | my $refNode = $self; | ||
| 63 | foreach my $node ( @$nodes ) | ||
| 64 | { | ||
| 65 | $parent->insertBefore( $node, $refNode ); | ||
| 66 | $refNode = $node; | ||
| 67 | } | ||
| 68 | return( $self ); | ||
| 69 | } | ||
| 70 | |||
| 71 | # Note: property internalSubset read-only | ||
| 72 | sub internalSubset { return( shift->new_scalar ); } | ||
| 73 | |||
| 74 | # Note: property name read-only | ||
| 75 | sub name : lvalue { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); } | ||
| 76 | |||
| 77 | # Note: property notations read-only | ||
| 78 | sub notations { return; } | ||
| 79 | |||
| 80 | # Note: property publicId read-only | ||
| 81 | sub publicId | ||
| 82 | { | ||
| 83 | my $self = shift( @_ ); | ||
| 84 | if( my $rv = $self->original->match( qr/PUBLIC[[:blank:]\h]+\"([^\"]+)\"/ ) ) | ||
| 85 | { | ||
| 86 | return( $rv->capture->first ); | ||
| 87 | } | ||
| 88 | return( '' ); | ||
| 89 | } | ||
| 90 | |||
| 91 | sub remove | ||
| 92 | { | ||
| 93 | my $self = shift( @_ ); | ||
| 94 | my $parent = $self->parent || return; | ||
| 95 | $parent->removeChild( $self ); | ||
| 96 | return( $self ); | ||
| 97 | } | ||
| 98 | |||
| 99 | sub replaceWith | ||
| 100 | { | ||
| 101 | my $self = shift( @_ ); | ||
| 102 | my $parent = $self->parent || return; | ||
| 103 | my $list = $self->_list_to_nodes( @_ ) || return( $self->pass_error ); | ||
| 104 | my $pos = $parent->nodes->pos( $self ); | ||
| 105 | return( $self->error( "Unable to find our DTD object in our parent's nodes" ) ) if( !defined( $pos ) ); | ||
| 106 | my $dtd; | ||
| 107 | $list->foreach(sub | ||
| 108 | { | ||
| 109 | $_->parent( $parent ); | ||
| 110 | if( $self->_is_a( $_ => 'HTML::Object::DOM::Declaration' ) ) | ||
| 111 | { | ||
| 112 | $dtd = $_; | ||
| 113 | } | ||
| 114 | }); | ||
| 115 | $parent->nodes->splice( $pos, 1, $list->list ); | ||
| 116 | # Either an DTD object, if we found one, or undef | ||
| 117 | $parent->declaration( $dtd ); | ||
| 118 | $parent->reset(1); | ||
| 119 | return( $self ); | ||
| 120 | } | ||
| 121 | |||
| 122 | sub string_value { return; } | ||
| 123 | |||
| 124 | # Note: property systemId read-only | ||
| 125 | sub systemId | ||
| 126 | { | ||
| 127 | my $self = shift( @_ ); | ||
| 128 | if( my $rv = $self->original->match( qr/[[:blank:]\h]+\"(http[^\"]+)\"/ ) ) | ||
| 129 | { | ||
| 130 | return( $rv->capture->first ); | ||
| 131 | } | ||
| 132 | return( '' ); | ||
| 133 | } | ||
| 134 | |||
| 135 | 1; | ||
| 136 | # NOTE: POD | ||
| 137 | __END__ |