lib/HTML/Object/DOM/Element/Label.pm

filter: Statementstmt 52.8% 28 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 64.2% 9 / 14 Podpod 100% 3 / 3 totaltotal 38.8% 40 / 103 CC 12 SCAR 26.6
CC
12
Cov
35%
control
30.0
__ANON__
30.0
init
12.0
CRAP 14.3
« lib/HTML/Object/DOM/Collection.pm ↑ Summary blib/lib/HTML/Object/Document.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Label.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/23
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::Element::Label;
15 BEGIN
16 {
17 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use parent qw( HTML::Object::DOM::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶ use HTML::Object::DOM::Element::Shared qw( :label );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 our $VERSION = 'v0.2.0';
24 };
25  
26 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub init
30 {
31 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
32 0 $self->{_init_strict_use_sub} = 1;
33 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
34 0 ▶ $self->{tag} = 'label' if( !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length qq[$self->{"tag"}] 0 0 0
35 0 return( $self );
36 }
37  
38 # Note: property read-only
39 sub control
40 {
41 0 ▶ my $self = shift( @_ );
Subroutine control: not called CC=5 SCAR=34.0
Pod documented
42 0 my $id = $self->htmlFor;
43 # return if( !defined( $id ) || !CORE::length( "$id" ) );
44 0 ▶ if( defined( $id ) && CORE::length( "$id" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and length "$id") { } 0 0 0
Condition0%0/3
defined $id and length "$id"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $id and length "$id"
defined $id length "$id"
Truth table0%0/3
A and B
A= defined $idB= length "$id"
ABresult
0X0
100
111
45 {
46 0 my $root = $self->root;
47 0 my $elem = $root->look_down( id => $id )->first;
48 0 ▶ return if( !defined( $elem ) || !ref( $elem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem and ref $elem 0 0 0
Condition0%0/3
defined $elem and ref $elem
!ll&&!rl&&r
000
MC/DC0%0/2
defined $elem and ref $elem
defined $elem ref $elem
Truth table0%0/3
A and B
A= defined $elemB= ref $elem
ABresult
0X0
100
111
49 0 return( $elem );
50 }
51 # "If the for attribute is not specified, but the label element has a labelable element descendant, then the first such descendant in tree order is the label element's labeled control."
52 # <https://html.spec.whatwg.org/multipage/forms.html#htmllabelelement>
53 else
54 {
55 0 my $elems = $self->look_down( _tag => qr/(?:button|input|meter|output|progress|select|textarea)/ );
56 0 my $elem;
57 $elems->foreach(sub
58 {
59 0 ▶ my $tag = $_->tag;
Subroutine __ANON__: not called CC=5 SCAR=34.0
60 0 ▶ if( $tag ne 'input' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($tag ne "input" or $tag eq "input" and lc($_->attr("type") // "") ne "hidden") 0 0 0
Condition0%0/8
$tag ne "input" or $tag eq "input" and lc($_->attr("type") // "") ne "hidden"
l!l&&r!l&&!r
000
$tag eq "input" and lc($_->attr("type") // "") ne "hidden"
!ll&&!rl&&r
000
$_->attr("type") // ""
l!l
00
MC/DC0%0/3
$tag ne "input" or $tag eq "input" and lc($_->attr("type") // "") ne "hidden"
$tag ne "input" $tag eq "input" $_->attr("type")
Truth table0%0/4
A or B and C
A= $tag ne "input"B= $tag eq "input"C= $_->attr("type")
ABCresult
1XX1
0111
00X0
0100
61 ( $tag eq 'input' && lc( $_->attr( 'type' ) // '' ) ne 'hidden' ) )
62 {
63 0 $elem = $_;
64 0 return(0);
65 }
66 0 });
67 0 return( $elem );
68 }
69 }
70  
71 # Note: property form is NOT inherited, because this is the 'form' value of the associated control, if any.
72 {
73 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 sub form
75 {
76 0 ▶ my $self = shift( @_ );
Subroutine form: not called CC=2 SCAR=17.9
77 0 my $elem = $self->control;
78 0 ▶ return if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "HTML::Object::DOM::Element") 0 0 0
79 0 return( $elem->form );
80 }
81 }
82  
83 # Note: property
84 # labelable elements:
85 # "button, input (if the type attribute is not in the Hidden state) meter, output, progress, select, textarea, form-associated custom elements"
86 # <https://html.spec.whatwg.org/multipage/forms.html#category-label>
87 0 ▶sub htmlFor : lvalue { return( shift->_set_get_property( 'for', @_ ) ); }
Subroutine htmlFor: not called CC=1 SCAR=1.2
Pod documented
88  
89 1 1;
90 # NOTE: POD
91 __END__
« lib/HTML/Object/DOM/Collection.pm ↑ Summary blib/lib/HTML/Object/Document.pm »