| 1 | ##---------------------------------------------------------------------------- | ||
| 2 | ## HTML Object - ~/lib/HTML/Object/Root.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::Root; | ||
| 15 | BEGIN | ||
| 16 | { | ||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | warnings::register_categories( 'HTML::Object' ); | ||
| 20 | use parent qw( HTML::Object::Document ); | ||
| 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->{root} = ''; | ||
| 32 | $self->{_init_strict_use_sub} = 1; | ||
| 33 | $self->{_exception_class} = 'HTML::Object::Exception'; | ||
| 34 | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||
| 35 | return( $self ); | ||
| 36 | } | ||
| 37 | |||
| 38 | # added to provide element-like methods to root, for use by cmp | ||
| 39 | sub lineage | ||
| 40 | { | ||
| 41 | my $self = shift( @_ ); | ||
| 42 | return( $self->new_array( [ $self ] ) ); | ||
| 43 | } | ||
| 44 | |||
| 45 | sub root { return( shift->_set_get_object( 'root', 'HTML::Object::Element', @_ ) ); } | ||
| 46 | |||
| 47 | 1; | ||
| 48 | # NOTE: POD | ||
| 49 | __END__ | ||
| 50 | |||
| 51 | =encoding utf-8 | ||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | HTML::Object::Root - HTML Object | ||
| 56 | |||
| 57 | =head1 SYNOPSIS | ||
| 58 | |||
| 59 | use HTML::Object::Root; | ||
| 60 | my $root = HTML::Object::Root->new || | ||
| 61 | die( HTML::Object::Root->error, "\n" ); | ||
| 62 | |||
| 63 | =head1 VERSION | ||
| 64 | |||
| 65 | v0.2.0 | ||
| 66 | |||
| 67 | =head1 DESCRIPTION | ||
| 68 | |||
| 69 | This module represent a C<Root> element. It inherits fron L<HTML::Object::Document> | ||
| 70 | |||
| 71 | =head1 INHERITANCE | ||
| 72 | |||
| 73 | +-----------------------+ +------------------------+ +--------------------+ | ||
| 74 | | HTML::Object::Element | --> | HTML::Object::Document | --> | HTML::Object::Root | | ||
| 75 | +-----------------------+ +------------------------+ +--------------------+ | ||
| 76 | |||
| 77 | =head1 PROPERTIES | ||
| 78 | |||
| 79 | =head2 nodeValue | ||
| 80 | |||
| 81 | This returns or sets the value of the current node. | ||
| 82 | |||
| 83 | For document, element or collection, this returns C<undef> and for attribute, text or comment, this returns the objct value. | ||
| 84 | |||
| 85 | See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue> | ||
| 86 | |||
| 87 | =head1 METHODS | ||
| 88 | |||
| 89 | =head2 cmp | ||
| 90 | |||
| 91 | Provided with an element and this returns true if this element is a L<Root element|HTML::Object::Root>, or false otherwise. | ||
| 92 | |||
| 93 | =head2 getAttributes | ||
| 94 | |||
| 95 | Returns a new empty L<array object|Module::Generic::Array> | ||
| 96 | |||
| 97 | =head2 getChildNodes | ||
| 98 | |||
| 99 | Returns the value returned by L</root> | ||
| 100 | |||
| 101 | =head2 getName | ||
| 102 | |||
| 103 | Returns C<undef> if scalar context and an empty list in list context. | ||
| 104 | |||
| 105 | =head2 getNextSibling | ||
| 106 | |||
| 107 | Returns C<undef> if scalar context and an empty list in list context. | ||
| 108 | |||
| 109 | =head2 getParentNode | ||
| 110 | |||
| 111 | Returns C<undef> if scalar context and an empty list in list context. | ||
| 112 | |||
| 113 | =head2 getPreviousSibling | ||
| 114 | |||
| 115 | Returns C<undef> if scalar context and an empty list in list context. | ||
| 116 | |||
| 117 | =head2 getRootNode | ||
| 118 | |||
| 119 | Returns the current object since there is no higher element than itself. | ||
| 120 | |||
| 121 | =head2 is_inside | ||
| 122 | |||
| 123 | Returns C<0>, i.e. false. | ||
| 124 | |||
| 125 | =head2 isDocumentNode | ||
| 126 | |||
| 127 | Returns C<1>, i.e. true. | ||
| 128 | |||
| 129 | =head2 lineage | ||
| 130 | |||
| 131 | Returns a new L<array object|Module::Generic::Array> with the current object as its sole element. | ||
| 132 | |||
| 133 | =head2 root | ||
| 134 | |||
| 135 | Returns the L<element object|HTML::Object::Element> representing the actual root element. | ||
| 136 | |||
| 137 | =head1 AUTHOR | ||
| 138 | |||
| 139 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||
| 140 | |||
| 141 | =head1 SEE ALSO | ||
| 142 | |||
| 143 | 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> | ||
| 144 | |||
| 145 | =head1 COPYRIGHT & LICENSE | ||
| 146 | |||
| 147 | Copyright (c) 2021 DEGUEST Pte. Ltd. | ||
| 148 | |||
| 149 | All rights reserved | ||
| 150 | |||
| 151 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 152 | |||
| 153 | =cut |