lib/HTML/Object/DOM/Attribute.pm

filter: Statementstmt 38.2% 31 / 81 Branchbran 5.5% 1 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 34.1% 14 / 41 Podpod 100% 34 / 34 totaltotal 44.6% 80 / 179 CC 11 SCAR 13.8
CC
11
Cov
31%
getAttributes
12.0
getNextSibling
12.0
getPreviousSibling
12.0
CRAP 4.0
« lib/HTML/Object/DOM/Element/UList.pm ↑ Summary lib/HTML/Object/DOM/Element/Option.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Attribute.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::Attribute;
15 BEGIN
16 {
17 13 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 13 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 13 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 13 ▶ use parent qw( HTML::Object::Attribute HTML::Object::DOM::Node );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 13 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 13 our $VERSION = 'v0.2.0';
23 };
24  
25 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 31 ▶sub init { return( shift->HTML::Object::Attribute::init( @_ ) ); }
Subroutine init: called CC=1 SCAR=0.0
Pod documented
29  
30 sub getAttributes
31 {
32 0 ▶ my $self = shift( @_ );
Subroutine getAttributes: not called CC=3 SCAR=24.8
Pod documented
33 0 my $elem = $self->element;
34 0 my $a = $self->new_array;
35 0 ▶ return( wantarray() ? $a->list : $a ) if( !$elem );
Branch: 2 branches
BranchTrueFalseTotal
unless $elem 0 0 0
wantarray ? : 0 0 0
36 0 return( $elem->getAttributes );
37 }
38  
39 0 ▶sub getChildNodes { return( wantarray() ? () : [] ); }
Subroutine getChildNodes: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
40  
41 0 ▶sub getElementById { return; }
Subroutine getElementById: not called CC=1 SCAR=6.9
Pod documented
42  
43 0 ▶sub getFirstChild { return; }
Subroutine getFirstChild: not called CC=1 SCAR=6.9
Pod documented
44  
45 0 ▶sub getLastChild { return; }
Subroutine getLastChild: not called CC=1 SCAR=6.9
Pod documented
46  
47 sub getLocalName
48 {
49 0 ▶ my $self = shift( @_ );
Subroutine getLocalName: not called CC=1 SCAR=6.9
Pod documented
50 0 ( my $name = $self->name ) =~ s{^.*:}{};
51 0 return( $name );
52 }
53  
54 26 ▶sub getName { return( shift->name ); }
Subroutine getName: called CC=1 SCAR=0.0
Pod documented
55  
56 sub getNextSibling
57 {
58 0 ▶ my $self = shift( @_ );
Subroutine getNextSibling: not called CC=3 SCAR=24.8
Pod documented
59 0 my $elem = $self->element;
60 0 ▶ return if( !$elem );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 0 0
61 0 my $pos = $elem->attributes_sequence->pos( $self->name );
62 0 ▶ return if( $pos == $elem->attributes_sequence->size );
Branch: 1 branch
BranchTrueFalseTotal
if $pos == $elem->attributes_sequence->size 0 0 0
63 0 my $key = $elem->attributes_sequence->get( $pos - 1 );
64 0 my $val = $elem->attributes->get( $key );
65 0 return( $self->new(
66 element => $elem,
67 name => $key,
68 rank => ( $pos + 1 ),
69 value => $val,
70 ) );
71 }
72  
73 0 ▶sub getParentNode { return( shift->element ); }
Subroutine getParentNode: not called CC=1 SCAR=6.9
Pod documented
74  
75 # awfully inefficient, but hopefully this is called only for weird (read test-case) queries
76 sub getPreviousSibling
77 {
78 0 ▶ my $self = shift( @_ );
Subroutine getPreviousSibling: not called CC=3 SCAR=24.8
Pod documented
79 0 my $elem = $self->element;
80 0 ▶ return if( !$elem );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 0 0
81 0 my $pos = $elem->attributes_sequence->pos( $self->name );
82 0 ▶ return if( !$pos );
Branch: 1 branch
BranchTrueFalseTotal
unless $pos 0 0 0
83 0 my $key = $elem->attributes_sequence->get( $pos - 1 );
84 0 my $val = $elem->attributes->get( $key );
85 0 return( $self->new(
86 element => $elem,
87 name => $key,
88 rank => ( $pos - 1 ),
89 value => $val,
90 ) );
91 }
92  
93 0 ▶sub getRootNode { return( shift->parent->getRootNode ); }
Subroutine getRootNode: not called CC=1 SCAR=6.9
Pod documented
94  
95 0 ▶sub getValue { return( shift->value ); }
Subroutine getValue: not called CC=1 SCAR=6.9
Pod documented
96  
97 0 ▶sub isAttributeNode { 1 }
Subroutine isAttributeNode: not called CC=1 SCAR=6.9
Pod documented
98  
99 0 ▶sub isCommentNode { return(0); }
Subroutine isCommentNode: not called CC=1 SCAR=6.9
Pod documented
100  
101 0 ▶sub isElementNode { return(0); }
Subroutine isElementNode: not called CC=1 SCAR=6.9
Pod documented
102  
103 0 ▶sub isNamespaceNode { return(0); }
Subroutine isNamespaceNode: not called CC=1 SCAR=6.9
Pod documented
104  
105 0 ▶sub isPINode { return(0); }
Subroutine isPINode: not called CC=1 SCAR=6.9
Pod documented
106  
107 0 ▶sub isProcessingInstructionNode { return(0); }
Subroutine isProcessingInstructionNode: not called CC=1 SCAR=6.9
Pod documented
108  
109 0 ▶sub isTextNode { return(0); }
Subroutine isTextNode: not called CC=1 SCAR=6.9
Pod documented
110  
111 sub is_inside
112 {
113 0 ▶ my( $self, $node ) = @_;
Subroutine is_inside: not called CC=2 SCAR=17.9
Pod documented
114 0 my $e = $self->element;
115 0 ▶ return( ( $e == $node ) || $e->is_inside( $node ) );
Condition0%0/3
$e == $node || $e->is_inside($node)
l!l&&r!l&&!r
000
MC/DC0%0/2
$e == $node || $e->is_inside($node)
$e == $node $e->is_inside($node)
Truth table0%0/3
A || B
A= $e == $nodeB= $e->is_inside($node)
ABresult
1X1
011
000
116 }
117  
118 # Updated version from HTML::Object::Element's one because HTML::Object::DOM::Attribute
119 # is considered a child of its associated element
120 # This is used in HTML::Object::DOM::Node->compareDocumentPosition
121 sub lineage
122 {
123 1 ▶ my $self = shift( @_ );
Subroutine lineage: called CC=2 SCAR=7.0
Pod documented
124 1 my $e = $self->element;
125 1 ▶ return( $self->new_array ) if( !$e );
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 1 1
126 1 return( $e->lineage->unshift( $e ) );
127 }
128  
129 0 ▶sub localName { return( shift->getName ); }
Subroutine localName: not called CC=1 SCAR=6.9
Pod documented
130  
131 0 ▶sub namespaceURI { return; }
Subroutine namespaceURI: not called CC=1 SCAR=6.9
Pod documented
132  
133 # "The value of Attr.name, that is the qualified name of the attribute."
134 # <https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName>
135 0 ▶sub nodeName { return( shift->name ); }
Subroutine nodeName: not called CC=1 SCAR=6.9
Pod documented
136  
137 # Note: Property
138 1 ▶sub nodeValue : lvalue { return( shift->_set_get_lvalue( 'value', @_ ) ); }
Subroutine nodeValue: called CC=1 SCAR=0.0
Pod documented
139  
140 3 ▶sub ownerElement { return( shift->element ); }
Subroutine ownerElement: called CC=1 SCAR=0.0
Pod documented
141  
142 2 ▶sub parent { return( shift->element ); }
Subroutine parent: called CC=1 SCAR=0.0
Pod documented
143  
144 0 ▶sub prefix { return; }
Subroutine prefix: not called CC=1 SCAR=6.9
Pod documented
145  
146 45 ▶sub string_value { return( shift->value ); }
Subroutine string_value: called CC=1 SCAR=0.0
Pod documented
147  
148 0 ▶sub to_boolean { return( shift->value->scalar ? HTML::Object::Boolean->True : HTML::Object::Boolean->False ); }
Subroutine to_boolean: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->value->scalar ? : 0 0 0
149  
150 0 ▶sub to_literal { return( HTML::Object::Literal->new( shift->value ) ); }
Subroutine to_literal: not called CC=1 SCAR=6.9
Pod documented
151  
152 0 ▶sub to_number { return( HTML::Object::Number->new( shift->value ) ); }
Subroutine to_number: not called CC=1 SCAR=6.9
Pod documented
153  
154 sub toString
155 {
156 0 ▶ my $self = shift( @_ );
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
157 0 return( sprintf( '%s="%s"', $self->name, $self->value ) );
158 }
159  
160 13 1;
161 # NOTE: POD
162 __END__
« lib/HTML/Object/DOM/Element/UList.pm ↑ Summary lib/HTML/Object/DOM/Element/Option.pm »