| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/Document.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::Document; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 37 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 37 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 37 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 37 | ▶ | use parent qw( HTML::Object::Element ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 37 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 37 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 37 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 37 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 37 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 83 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 83 | $self->{is_empty} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 83 | $self->{tag} = '_document'; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 83 | $self->{declaration} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 83 | $self->{referrer} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 83 | $self->{uri} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 83 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 83 | $self->{_exception_class} = 'HTML::Object::Exception'; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 83 | $self->{_last_modified} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 83 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 83 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | sub append | ||||||||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return( $self->error( "Nothing to append was provided." ) ) if( !defined( $this ) || !CORE::length( $this ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $this and length $this
MC/DC0%0/2
defined $this and length $this
defined $this
length $this
Truth table0%0/3
A and B
A= defined $thisB= length $this
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if( !ref( $this ) || overload::Method( $this, '""' ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $this or overload::Method($this, "\"\"")
MC/DC0%0/2
not ref $this or overload::Method($this, "\"\"")
not ref $this
overload::Method($this, "\"\"")
Truth table0%0/3
not(A) or B
A= not ref $thisB= overload::Method($this, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $p = HTML::Object->new; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $doc = $p->parse( "$this" ) || return( $self->pass_error( $p->error ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$p->parse("$this") || (return $self->pass_error($p->error))
MC/DC0%0/1
$p->parse("$this") || (return $self->pass_error($p->error))
$p->parse("$this")
Truth table0%0/2
A
A= $p->parse("$this")
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return( $self->error( "No element could be found from parsing html text provided." ) ) if( !$doc->children->length ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $this = $doc->children->first; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if( !$self->_is_a( $this, 'HTML::Object::Element' ) || $self->_is_a( $this, 'HTML::Object::Collection' ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $self->_is_a($this, "HTML::Object::Element") or $self->_is_a($this, "HTML::Object::Collection")
MC/DC0%0/2
not $self->_is_a($this, "HTML::Object::Element") or $self->_is_a($this, "HTML::Object::Collection")
not $self->_is_a($this, "HTML::Object::Element")
$self->_is_a($this, "HTML::Object::Collection")
Truth table0%0/3
not(A) or B
A= not $self->_is_a($this, "HTML::Object::Element")B= $self->_is_a($this, "HTML::Object::Collection")
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return( $self->error( "Element object provided is not an HTML::Object::Element object." ) ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if( $this->tag eq 'html' && $self->children->length && $self->children->first->tag eq 'html' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$this->tag eq "html" and $self->children->length and $self->children->first->tag eq "html"
$this->tag eq "html" and $self->children->length
MC/DC0%0/3
$this->tag eq "html" and $self->children->length and $self->children->first->tag eq "html"
$this->tag eq "html"
$self->children->length
$self->children->first->tag eq "html"
Truth table0%0/4
A and B and C
A= $this->tag eq "html"B= $self->children->lengthC= $self->children->first->tag eq "html"
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | require HTML::Object::Exception; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||
| 64 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||
| 65 | code => 403, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | message => "You are atttempting to add an html tag, but there is already one.", | ||||||||||||||||||||||||||||||||||||||||||
| 67 | }) ); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $this->parent( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $this->children->push( $this ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return( $this ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | sub as_string | ||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | # if( $self->isa( 'HTML::Object::Collection' ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # return( '' ) if( !$self->children->length ); | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # my $first = $self->children->first; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # return( '' ) if( !$self->_is_a( $first, 'HTML::Object::Element' ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # return( $self->error( "as_string() called on a Collection object, but its first children element is also a collection. Stopping before starting an infinite recursion." ) ) if( $self->_is_a( $first, 'HTML::Object::Collection' ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # return( $first->as_string ); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $a = $self->new_array; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $a->push( $self->declaration->as_string ) if( $self->declaration ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | $self->children->foreach(sub | ||||||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $e = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $v = $e->as_string; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $a->push( defined( $v ) ? $v->scalar : $v ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return( $a->join( '' ) ); | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | sub as_xml | ||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_xml: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $a = $self->new_array; | |||||||||||||||||||||||||||||||||||||||||
| 100 | $self->children->foreach(sub | ||||||||||||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $e = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $v = $e->as_xml; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $a->push( defined( $v ) ? $v->scalar : $v ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return( $a->join( '' ) ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 31 | ▶ | sub declaration { return( shift->_set_get_object_without_init( 'declaration', 'HTML::Object::Declaration', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
declaration: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | sub uri { return( shift->_set_get_uri( 'uri', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | ▶ | sub _last_modified { return( shift->_set_get_datetime( '_last_modified', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_last_modified: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 37 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 116 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||||||||||||||||