| 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 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $self->{tag} = 'label' if( !CORE::length( "$self->{tag}" ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Note: property read-only | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | sub control | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
control: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $id and length "$id"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $elem and ref $elem
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $tag = $_->tag; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if( $tag ne 'input' || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
$tag ne "input" or $tag eq "input" and lc($_->attr("type") // "") ne "hidden"
$tag eq "input" and lc($_->attr("type") // "") ne "hidden"
$_->attr("type") // ""
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")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $elem = $self->control; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||