| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/Element/Select.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::Select; | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use parent qw( HTML::Object::DOM::Element ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use HTML::Object::DOM::Element::Shared qw( :select ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | $self->{tag} = 'select' if( !CORE::length( "$self->{tag}" ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $self->{options} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | $self->{_select_reset} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | my $callback = sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | my $def = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Our children were modified from outside our package. | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # We need to check if it affects our rows and reset the cache accordingly | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | ▶ | unless( $def->{caller}->[0] eq ref( $self ) || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$def->{"caller"}[0] eq ref $self or $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Select"
MC/DC50%1/2
$def->{"caller"}[0] eq ref $self or $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Select"
$def->{"caller"}[0] eq ref $self
$def->{"caller"}[0] eq "HTML::Object::DOM::Element::Select"
Truth table66%2/3
A or B
A= $def->{"caller"}[0] eq ref $selfB= $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Select"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | $def->{caller}->[0] eq 'HTML::Object::DOM::Element::Select' ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | return(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | $self->children->callback( add => $callback ); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | $self->children->callback( remove => $callback ); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sub add | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=17 SCAR=47.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | message => sprintf( "At least 1 argument is required, but only %d was provided.", scalar( @_ ) ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | class => 'HTML::Object::SyntaxError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }) ) if( scalar( @_ ) < 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my( $elem, $pos ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
MC/DC0%0/2
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
$self->_is_a($elem, "HTML::Object::DOM::Element::Option")
$self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
Truth table33%1/3
A or B
A= $self->_is_a($elem, "HTML::Object::DOM::Element::Option")B= $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | message => "Element provided is neither a HTML::Object::DOM::Element::Option object nor a HTML::Object::DOM::Element::OptGroup object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | }) ) if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element::Option' ) && !$self->_is_a( $elem => 'HTML::Object::DOM::Element::OptGroup' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my $options = $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | my $size = $options->size; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if( defined( $pos ) && CORE::length( $pos ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pos and CORE::length $pos
MC/DC0%0/2
defined $pos and CORE::length $pos
defined $pos
CORE::length $pos
Truth table33%1/3
A and B
A= defined $posB= CORE::length $pos
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element::Option' ) && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$self->_is_a($elem, 'HTML::Object::DOM::Element::Option') || $self->_is_a($elem, 'HTML::Object::DOM::Element::OptGroup') || $self->_is_integer($pos)
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
MC/DC0%0/3
$self->_is_a($elem, 'HTML::Object::DOM::Element::Option') || $self->_is_a($elem, 'HTML::Object::DOM::Element::OptGroup') || $self->_is_integer($pos)
$self->_is_a($elem, "HTML::Object::DOM::Element::Option")
$self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
$self->_is_integer($pos)
Truth table0%0/4
A or B || C
A= $self->_is_a($elem, "HTML::Object::DOM::Element::Option")B= $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")C= $self->_is_integer($pos)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | !$self->_is_a( $elem => 'HTML::Object::DOM::Element::OptGroup' ) && | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | !$self->_is_integer( $pos ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | message => "The offset position before which to insert the element, if provided, must be an object or an integer, but I got '" . overload::StrVal( $pos ) . "'.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ▶ | elsif( $self->_is_a( $elem => 'HTML::Object::DOM::Element::Option' ) || | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
MC/DC0%0/2
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
$self->_is_a($elem, "HTML::Object::DOM::Element::Option")
$self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
Truth table0%0/3
A or B
A= $self->_is_a($elem, "HTML::Object::DOM::Element::Option")B= $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | $self->_is_a( $elem => 'HTML::Object::DOM::Element::OptGroup' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Check if it is an ancestor, as per the specifications | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $lineage = $self->lineage; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $lineagePos = $lineage->pos( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( defined( $lineagePos ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | message => "Element to be added to this select element is an ancestor.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $tmpPos = $options->pos( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if( defined( $tmpPos ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $pos = $tmpPos; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | undef( $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if( $pos < 0 ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $pos = $pos + $size; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | elsif( $pos > $size ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | undef( $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | $elem->detach; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | $elem->parent( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my $children = $self->children; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | if( defined( $pos ) && CORE::length( $pos ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pos and CORE::length $pos
MC/DC0%0/2
defined $pos and CORE::length $pos
defined $pos
CORE::length $pos
Truth table33%1/3
A and B
A= defined $posB= CORE::length $pos
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $kid = $options->index( $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $real_pos = $children->pos( $kid ); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $children->splice( $real_pos, 0, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $children->push( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Note: property autofocus | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub autofocus : lvalue { return( shift->_set_get_property( 'autofocus', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
autofocus: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub blur { return; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blur: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Note: method checkValidity is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Note: property disabled is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub focus { return; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
focus: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # Note: property form read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | ▶ | sub item { return( shift->options->index( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
item: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Note: property labels read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Note: property length | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub length : lvalue { return( shift->_set_get_property( 'length', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
length: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # Note: property multiple | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub multiple : lvalue { return( shift->_set_get_property( 'multiple', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
multiple: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # Note: property name is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Note: method namedItem is inherited from HTML::Object::DOM::Collection | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | sub namedItem { return( shift->options->namedItem( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
namedItem: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub onchange : lvalue { return( shift->on( 'change', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
onchange: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub oninput : lvalue { return( shift->on( 'input', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oninput: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # Note: property options read-only | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # sub options { return( shift->_set_get_object( 'options', 'HTML::Object::DOM::Element::OptionsCollection', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | sub options | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 37 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 37 | ▶ | return( $self->{_select_options} ) if( $self->{_select_options} && !$self->_is_select_reset ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"_select_options"} and not $self->_is_select_reset
MC/DC100%2/2
$self->{"_select_options"} and not $self->_is_select_reset
$self->{"_select_options"}
not $self->_is_select_reset
Truth table100%3/3
A and not(B)
A= $self->{"_select_options"}B= not $self->_is_select_reset
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 22 | ▶ | my $list = $self->children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Element::Option' ) }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # The content of the collection is refreshed, but the collection object itself does not change, so the user can poll it | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 22 | ▶ | unless( $self->{_select_options} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | $self->_load_class( 'HTML::Object::DOM::Element::OptionsCollection' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | ▶ | $self->{_select_options} = HTML::Object::DOM::Element::OptionsCollection->new || | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'HTML::Object::DOM::Element::OptionsCollection'->new || (return $self->pass_error('HTML::Object::DOM::Element::OptionsCollection'->error))
MC/DC0%0/1
'HTML::Object::DOM::Element::OptionsCollection'->new || (return $self->pass_error('HTML::Object::DOM::Element::OptionsCollection'->error))
'HTML::Object::DOM::Element::OptionsCollection'->new
Truth table50%1/2
A
A= 'HTML::Object::DOM::Element::OptionsCollection'->new
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | return( $self->pass_error( HTML::Object::DOM::Element::OptionsCollection->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 22 | $self->{_select_options}->set( $list ); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 22 | $self->_remove_select_reset; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 22 | return( $self->{_select_options} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub remove | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=6 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | my $pos = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $pos and CORE::length "$pos" and $self->_is_integer($pos)
defined $pos and CORE::length "$pos"
MC/DC0%0/3
defined $pos and CORE::length "$pos" and $self->_is_integer($pos)
defined $pos
CORE::length "$pos"
$self->_is_integer($pos)
Truth table25%1/4
A and B and C
A= defined $posB= CORE::length "$pos"C= $self->_is_integer($pos)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | message => "Index value provided ($pos) is not an integer", | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | }) ) if( !defined( $pos ) || !CORE::length( "$pos" ) || !$self->_is_integer( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | my $options = $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | message => "Index value provided ($pos) is greater than the zero-based total number of options.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | }) ) if( $pos > $options->size ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | my $elem = $options->index( $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | my $real_pos = $self->children->pos( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | message => "Could not find the real index position of element found at offset '$pos'.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | }) ) if( !defined( $real_pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | $self->children->splice( $real_pos, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | $elem->parent( undef ); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | return( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Note: method reportValidity is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # Note: property required is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | sub reset | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 72 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 72 | ▶ | if( scalar( @_ ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 22 | $self->_reset_select; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | # Force the rebuilding of the collection of selected options | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 22 | CORE::delete( $self->{_selected_options} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 22 | CORE::delete( $self->{selectedindex} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | 22 | return( $self->SUPER::reset( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 50 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Note: property selectedIndex | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # This is called by the HTML::Object::DOM::Element::Option when selected | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # sub selectedIndex : lvalue { return( shift->_set_get_number( 'selectedindex', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | sub selectedIndex : lvalue { return( shift->_lvalue({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | set => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my( $self, $val ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | message => "Index value provided is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | }) ) if( !$self->_is_integer( $val ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $options = $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | message => "Index value provided is greater than the zero-based total number (" . $options->size . ") of options available.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | }) ) if( $val > $options->size ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $self->{selectedindex} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $elem = $options->index( $val ); | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | message => "Somehow, the element found at position $val is not an HTML::Object::DOM::Element::Option object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | }) ) if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element::Option' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $elem->defaultSelected = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | get => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | ▶ | return( $self->{selectedindex} ) if( $self->{selectedindex} && !$self->_is_select_reset ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"selectedindex"} and not $self->_is_select_reset
MC/DC0%0/2
$self->{"selectedindex"} and not $self->_is_select_reset
$self->{"selectedindex"}
not $self->_is_select_reset
Truth table33%1/3
A and not(B)
A= $self->{"selectedindex"}B= not $self->_is_select_reset
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # Get all options | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | my $options = $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | # Get all selected ones; could be empty | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | my $selected = $self->selectedOptions; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | ▶ | return if( $selected->is_empty ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # Get the first selected one | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | my $elem = $selected->index(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Find its index position among all options | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | my $pos = $options->pos( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | # and return it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | return( $self->{selectedindex} = $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | ▶ | }, @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectedIndex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # Note: property selectedOptions read-only | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | sub selectedOptions | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 4 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectedOptions: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | return( $self->{_selected_options} ) if( $self->{_selected_options} && !$self->_is_select_reset ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_selected_options"} and not $self->_is_select_reset
MC/DC50%1/2
$self->{"_selected_options"} and not $self->_is_select_reset
$self->{"_selected_options"}
not $self->_is_select_reset
Truth table66%2/3
A and not(B)
A= $self->{"_selected_options"}B= not $self->_is_select_reset
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | ▶ | my $list = $self->options->filter(sub{ $_->defaultSelected }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | $self->children->for(sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 14 | ▶ | my( $i, $elem ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | # The content of the collection is refreshed, but the collection object itself does not change, so the user can poll it | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | unless( $self->{_selected_options} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | ▶ | $self->_load_class( 'HTML::Object::DOM::Collection' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | $self->{_selected_options} = HTML::Object::DOM::Collection->new || | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'HTML::Object::DOM::Collection'->new || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
MC/DC0%0/1
'HTML::Object::DOM::Collection'->new || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
'HTML::Object::DOM::Collection'->new
Truth table50%1/2
A
A= 'HTML::Object::DOM::Collection'->new
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | return( $self->pass_error( HTML::Object::DOM::Collection->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | $self->{_selected_options}->set( $list ); | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | $self->_remove_select_reset; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | return( $self->{_selected_options} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Note: method setCustomValidity is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # Note: property size | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub size : lvalue { return( shift->_set_get_property( 'size', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # Note: property type read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # Note: property validationMessage read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # Note: property validity read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # Note: property value is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # Note: property willValidate read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 38 | ▶ | sub _is_select_reset { return( CORE::length( shift->{_select_reset} ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_select_reset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 24 | ▶ | sub _remove_select_reset { return( CORE::delete( shift->{_select_reset} ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_select_reset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | sub _reset_select | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 22 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_select: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 22 | $self->{_select_reset}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Force it to recompute | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 22 | $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 22 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||