| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 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
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 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $tag = $_->tag; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | HTML::Object::DOM::Element::Label - HTML Object DOM Label Class | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | use HTML::Object::DOM::Element::Label; | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | my $label = HTML::Object::DOM::Element::Label->new || | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | die( HTML::Object::DOM::Element::Label->error, "\n" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | v0.2.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | This interface gives access to properties specific to <label> elements. It inherits methods and properties from the base L<HTML::Object::Element> interface. | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =head1 INHERITANCE | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+ | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Label | | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+ | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | =head1 PROPERTIES | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | Inherits properties from its parent L<HTML::Object::DOM::Element> | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | =head2 control | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | Is a L<HTML::Object::Element> representing the control with which the label is associated. It returns C<undef> if the C<for> attribute has no id set, or no associated element could be found in the DOM. | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control> | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | =head2 form | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | Is a L<HTML::Object::DOM::Element::Form> object representing the form with which the labeled control is associated, or C<undef> if there is no associated control, or if that control is not associated with a form. In other words, this is just a shortcut for: | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | $e->control->form | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/form> | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =head2 htmlFor | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | Is a string containing the ID of the labeled control. This reflects the for attribute. | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | <label for="inputId">Enter your name</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | my $label = $doc->getElementsByTagName( 'label' )->first; | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | say( "ID is: ", $label->htmlFor ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/htmlFor> | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | Inherits methods from its parent L<HTML::Object::DOM::Element> | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement>, L<Mozilla documentation on label element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label>, L<W3C specificatins|https://html.spec.whatwg.org/multipage/forms.html#htmllabelelement> | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||