Object/DOM/Element/Title.pm

filter: Statementstmt 91.3% 63 / 69 Branchbran 72.2% 13 / 18 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 85.4% 100 / 117 CC 16 SCAR 15.2
CC
16
Cov
85%
__ANON__
9.3
__ANON__
6.0
init
3.1
CRAP 4.6
« Object/DOM/Boolean.pm ↑ Summary Object/DOM/Element/FencedFrame.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Title.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/01/09
7 ## Modified 2025/10/16
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::Element::Title;
15 BEGIN
16 18 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 warnings::register_categories( 'HTML::Object' );
20 18 ▶ use parent qw( HTML::Object::DOM::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 18 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 18 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 18 our $VERSION = 'v0.3.0';
24 };
25  
26 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub init
30 28 ▶{
Subroutine init: called CC=3 SCAR=11.2
Pod documented
31 28 my $self = shift( @_ );
32 28 $self->{_init_strict_use_sub} = 1;
33 28 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 28 0 28
34 28 ▶ $self->{tag} = 'title' if( !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length qq[$self->{"tag"}] 0 28 28
35 # We set this boolean to true to indicate we have not yet looked into the text inside the <title></title>
36 28 $self->{_initial_text} = 1;
37 28 return( $self );
38 }
39  
40 # Note: property text
41 5 ▶sub text : lvalue { return( shift->_set_get_callback({
Subroutine text: called CC=1 SCAR=0.1
Pod documented
42 get => sub
43 4 ▶ {
Subroutine __ANON__: called CC=6 SCAR=18.0
44 4 my $self = shift( @_ );
45 4 ▶ if( !$self->{_title_text} || $self->_is_reset )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"_title_text"} or $self->_is_reset) 2 2 4
Condition66%2/3
not $self->{"_title_text"} or $self->_is_reset
l!l&&r!l&&!r
202
MC/DC50%1/2
not $self->{"_title_text"} or $self->_is_reset
not $self->{"_title_text"} $self->_is_reset
Truth table66%2/3
not(A) or B
A= not $self->{"_title_text"}B= $self->_is_reset
ABresult
1X1
011
000
46 {
47 # We set this boolean to true to indicate we have not yet looked into the text inside the <title></title>
48 # The HTML::Parser sets the title value to anything within <title></title> no matter if there are any tag embedded, so we need to parse it further, but only once, hence this boolean value
49 2 ▶ if( $self->{_initial_text} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_initial_text"}) 2 0 2
50 {
51 2 my $children = $self->children;
52 2 my $val;
53 2 $val = $self->as_text;
54 2 ▶ if( $self->looks_like_it_has_html( "$val" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->looks_like_it_has_html("$val")) { } 1 1 2
55 {
56 1 my $p = $self->new_parser;
57 1 my $doc = $p->parse_data( $val );
58 1 my $kids = $doc->children;
59 1 $_->parent( $self ) for( @$kids );
60 1 $children->set( $kids );
61 }
62 else
63 {
64 # Title text does not look like it contains HTML.
65 }
66 2 CORE::delete( $self->{_initial_text} );
67 }
68  
69 2 my $result = $self->new_array;
70 # We purposively skip anything that is neither a space nor a text.
71 # This is what web browser do, notwithstanding any tag that may exist in the <title> tag
72 $self->children->foreach(sub
73 4 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
74 4 ▶ if( $self->_is_a( $_ => 'HTML::Object::DOM::Text' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($_, "HTML::Object::DOM::Text") or $self->_is_a($_, "HTML::Object::DOM::Space")) 3 1 4
Condition66%2/3
$self->_is_a($_, "HTML::Object::DOM::Text") or $self->_is_a($_, "HTML::Object::DOM::Space")
l!l&&r!l&&!r
301
MC/DC50%1/2
$self->_is_a($_, "HTML::Object::DOM::Text") or $self->_is_a($_, "HTML::Object::DOM::Space")
$self->_is_a($_, "HTML::Object::DOM::Text") $self->_is_a($_, "HTML::Object::DOM::Space")
Truth table66%2/3
A or B
A= $self->_is_a($_, "HTML::Object::DOM::Text")B= $self->_is_a($_, "HTML::Object::DOM::Space")
ABresult
1X1
011
000
75 $self->_is_a( $_ => 'HTML::Object::DOM::Space' ) )
76 {
77 3 my $v = $_->value;
78 3 $result->push( "$v" );
79 }
80 2 });
81 2 $self->{_title_text} = $result->join( '' )->scalar;
82 2 $self->_remove_reset;
83 }
84 4 my $text = $self->{_title_text};
85 4 return( $text );
86 },
87 set => sub
88 1 ▶ {
Subroutine __ANON__: called CC=7 SCAR=22.3
89 1 my $self = shift( @_ );
90 1 my $arg = shift( @_ );
91 1 my $nodes = $self->_get_from_list_of_elements_or_html( $arg );
92 # for( my $i = 0; $i < scalar( @$nodes ); $i++ )
93 # {
94 # }
95  
96 1 ▶ if( !defined( $nodes ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nodes) 0 1 1
97 {
98 0 return( $self->pass_error );
99 }
100 1 my $ok = 1;
101 1 for( @$nodes )
102 {
103 2 ▶ if( !$self->_is_a( $_ => 'HTML::Object::DOM::Text' ) &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($_, "HTML::Object::DOM::Text") or $self->_is_a($_, "HTML::Object::DOM::Space")) 1 1 2
Condition66%2/3
$self->_is_a($_, "HTML::Object::DOM::Text") or $self->_is_a($_, "HTML::Object::DOM::Space")
l!l&&r!l&&!r
101
MC/DC50%1/2
$self->_is_a($_, "HTML::Object::DOM::Text") or $self->_is_a($_, "HTML::Object::DOM::Space")
$self->_is_a($_, "HTML::Object::DOM::Text") $self->_is_a($_, "HTML::Object::DOM::Space")
Truth table66%2/3
A or B
A= $self->_is_a($_, "HTML::Object::DOM::Text")B= $self->_is_a($_, "HTML::Object::DOM::Space")
ABresult
1X1
011
000
104 !$self->_is_a( $_ => 'HTML::Object::DOM::Space' ) )
105 {
106 1 $ok = 0, last;
107 }
108 }
109 1 ▶ if( !$ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 0 1
110 {
111 1 return( $self->error( 'Values provided for title text contains data other tan text or space. You can provide text, space including HTML::Object::DOM::Text and HTML::Object::DOM::Space objects' ) );
112 }
113 0 $_->parent( $self ) for( @$nodes );
114 0 my $children = $self->children;
115 0 $children->set( $nodes );
116 0 $self->reset(1);
117 0 return(1);
118 }
119 5 }, @_ ) ); }
120  
121 18 1;
122 # NOTE: POD
123 __END__
« Object/DOM/Boolean.pm ↑ Summary Object/DOM/Element/FencedFrame.pm »