Object/DOM/List.pm

filter: Statementstmt 32.9% 27 / 82 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 44 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 52.9% 9 / 17 Podpod 100% 5 / 5 totaltotal 19.6% 41 / 209 CC 35 SCAR 60.0
CC
35
Cov
17%
addEventListener
756.0
AUTOLOAD
30.0
__ANON__
12.0
CRAP 404.6
« Object/XQuery.pm ↑ Summary Object/DOM/Element/Input.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/List.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/28
7 ## Modified 2025/10/16
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::List;
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::EventTarget );
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::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 our $VERSION = 'v0.3.0';
25 };
26  
27 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 sub init
31 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
32 0 my $self = shift( @_ );
33 0 $self->{children} = [];
34 0 $self->{_init_strict_use_sub} = 1;
35 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
36 0 return( $self );
37 }
38  
39 # This method is called from the package inheriting from us
40 # $def is a dictionary hash reference providing specifics in a crisp way about the types of events and related properties concerned
41 # Example:
42 # {
43 # addtrack => {
44 # add => { property => 'children', type => 'add', event => 'addtrack' },
45 # },
46 # change => {
47 # add => { property => 'selected', type => 'add', event => 'change' },
48 # remove => { property => 'selected', type => 'remove', event => 'change' },
49 # },
50 # removetrack => {
51 # remove => { property => 'children', type => 'remove', event => 'removetrack' },
52 # },
53 # }
54 sub addEventListener
55 0 ▶{
Subroutine addEventListener: not called CC=27 SCAR=66.3
Pod documented
56 0 my $self = shift( @_ );
57 0 ▶ return( $self->error( "I was expecting 3 arguments, but got only ", scalar( @_ ), "." ) ) if( scalar( @_ ) < 3 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 3 0 0 0
58 0 my $def = shift( @_ );
59 0 my $type = shift( @_ );
60 0 my $code = shift( @_ );
61 0 ▶ return( $self->error( "Dictionary provided is not an hash reference." ) ) if( !defined( $def ) || ref( $def ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $def or ref $def ne "HASH" 0 0 0
Condition0%0/3
not defined $def or ref $def ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $def or ref $def ne "HASH"
not defined $def ref $def ne "HASH"
Truth table0%0/3
not(A) or B
A= not defined $defB= ref $def ne "HASH"
ABresult
1X1
011
000
62 0 ▶ return( $self->error( "Event type provided contains illegal characters." ) ) if( !defined( $type ) || $type !~ /^\w+#/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type =~ /^\w+#/ 0 0 0
Condition0%0/3
defined $type and $type =~ /^\w+#/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type and $type =~ /^\w+#/
defined $type $type =~ /^\w+#/
Truth table0%0/3
A and B
A= defined $typeB= $type =~ /^\w+#/
ABresult
0X0
100
111
63 0 ▶ return( $self->error( "Callback is not a code reference." ) ) if( !defined( $code ) || !length( "$code" ) || ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $code && CORE::length "$code" or ref $code ne "CODE" 0 0 0
Condition0%0/6
not defined $code && CORE::length "$code" or ref $code ne "CODE"
l!l&&r!l&&!r
000
defined $code && CORE::length "$code"
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $code && CORE::length "$code" or ref $code ne "CODE"
defined $code CORE::length "$code" ref $code ne "CODE"
Truth table0%0/4
not(A && B) or C
A= defined $codeB= CORE::length "$code"C= ref $code ne "CODE"
ABCresult
0XX1
10X1
1111
1100
64 # Before we enable the event listener we must make sure we are listening on events on relevant array or scalar
65 0 ▶ if( CORE::exists( $def->{ $type } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{$type}) 0 0 0
66 {
67 0 my $ref = $def->{ $type };
68 # add or remove
69 0 OP: foreach my $op ( keys( %$ref ) )
70 {
71 0 my $this = $ref->{ $op };
72 0 for( qw( property type ) )
73 {
74 0 ▶ if( !CORE::exists( $this->{ $_ } ) || !defined( $this->{ $_ } ) || !CORE::length( $this->{ $_ } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $this->{$_} && defined $this->{$_} && CORE::length $this->{$_}) { } 0 0 0
elsif ($_ ne 'add' and $_ ne 'remove') { } 0 0 0
Condition0%0/6
exists $this->{$_} && defined $this->{$_} && CORE::length $this->{$_}
!ll&&!rl&&r
000
exists $this->{$_} and defined $this->{$_}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $this->{$_} && defined $this->{$_} && CORE::length $this->{$_}
exists $this->{$_} defined $this->{$_} CORE::length $this->{$_}
Truth table0%0/4
A and B && C
A= exists $this->{$_}B= defined $this->{$_}C= CORE::length $this->{$_}
ABCresult
0XX0
10X0
1100
1111
75 {
76 0 ▶ warn( "Dictionary property \"$_\" is missing or empty.\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
77 0 next OP;
78 }
79 ▶ elsif( $_ ne 'add' && $_ ne 'remove' )
Condition0%0/3
$_ ne "add" and $_ ne "remove"
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne "add" and $_ ne "remove"
$_ ne "add" $_ ne "remove"
Truth table0%0/3
A and B
A= $_ ne "add"B= $_ ne "remove"
ABresult
0X0
100
111
80 {
81 0 warnings::warn( "Unknown data listener type \"$_\"\n" );
82 0 next OP;
83 }
84 }
85  
86 0 my $subref = $self->can( $this->{property} );
87 0 ▶ if( !defined( $subref ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $subref) 0 0 0
88 {
89 0 ▶ warn( "This object class \"" . ( ref( $self ) || $self ) . "\" does not support method \"" . $this->{property} . "\".\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
90 0 next;
91 }
92 0 my $data = $subref->( $self );
93 0 ▶ if( !$self->_is_object( $data ) || !$data->can( 'callback' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_object($data) and $data->can("callback")) 0 0 0
Condition0%0/3
$self->_is_object($data) and $data->can("callback")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($data) and $data->can("callback")
$self->_is_object($data) $data->can("callback")
Truth table0%0/3
A and B
A= $self->_is_object($data)B= $data->can("callback")
ABresult
0X0
100
111
94 {
95 0 ▶ warn( "Object from class \"" . ( ref( $data ) || $data ) . "\" does not have a \"callback\" method.\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("HTML::Object") 0 0 0
Condition0%0/3
ref $data || $data
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $data || $data
ref $data $data
Truth table0%0/3
A || B
A= ref $dataB= $data
ABresult
1X1
011
000
96 0 next;
97 }
98 0 my $cb = $data->callback( $this->{type} );
99 # Callback already exists
100 0 ▶ next if( defined( $cb ) && ref( $cb ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $cb and ref $cb 0 0 0
Condition0%0/3
defined $cb and ref $cb
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cb and ref $cb
defined $cb ref $cb
Truth table0%0/3
A and B
A= defined $cbB= ref $cb
ABresult
0X0
100
111
101 $data->callback( $this->{type} => sub
102 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
103 0 my $hash = shift( @_ );
104 0 my $event = $self->_make_event( $type );
105 0 ▶ if( CORE::exists( $this->{callback} ) && ref( $this->{callback} ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{"callback"} and ref $this->{"callback"} eq "CODE") 0 0 0
Condition0%0/3
exists $this->{"callback"} and ref $this->{"callback"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $this->{"callback"} and ref $this->{"callback"} eq "CODE"
exists $this->{"callback"} ref $this->{"callback"} eq "CODE"
Truth table0%0/3
A and B
A= exists $this->{"callback"}B= ref $this->{"callback"} eq "CODE"
ABresult
0X0
100
111
106 {
107 0 $this->{callback}->( $self, { event => $event, added => $hash->{added}, removed => $hash->{removed}, type => $hash->{type} });
108 }
109 0 $self->dispatchEvent( $event );
110 0 });
111 }
112 }
113 0 return( $self->SUPER::addEventListener( $type => $code ) );
114 }
115  
116 0 ▶sub forEach { return( shift->children->foreach( @_ ) ); }
Subroutine forEach: not called CC=1 SCAR=6.9
Pod documented
117  
118 0 ▶sub length { return( shift->children->length ); }
Subroutine length: not called CC=1 SCAR=6.9
Pod documented
119  
120 0 ▶sub push { return( shift->children->push( @_ ) ); }
Subroutine push: not called CC=1 SCAR=6.9
Pod documented
121  
122 sub _make_event
123 0 ▶{
Subroutine _make_event: not called CC=2 SCAR=17.9
124 0 my $self = shift( @_ );
125 0 my $type = shift( @_ );
126 0 ▶ my $event = HTML::Object::Event->new( $type,
Condition0%0/2
'HTML::Object::Event'->new($type, 'bubbles', 0, 'cancellable', 0, 'target', $self) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
'HTML::Object::Event'->new($type, 'bubbles', 0, 'cancellable', 0, 'target', $self) || (return $self->pass_error)
'HTML::Object::Event'->new($type, 'bubbles', 0, 'cancellable', 0, 'target', $self)
Truth table0%0/2
A
A= 'HTML::Object::Event'->new($type, 'bubbles', 0, 'cancellable', 0, 'target', $self)
Aresult
11
00
127 bubbles => 0,
128 cancellable => 0,
129 target => $self,
130 ) || return( $self->pass_error );
131 0 return( $event );
132 }
133  
134 sub AUTOLOAD
135 0 ▶{
Subroutine AUTOLOAD: not called CC=5 SCAR=34.0
136 0 my( $name ) = our $AUTOLOAD =~ /([^:]+)$/;
137 0 my $self = shift( @_ );
138 0 my $children = $self->children;
139 0 ▶ die( "No method \"\$name\" in class \"", ( ref( $self ) || $self ), "\".\n" ) if( !$children );
Branch: 1 branch
BranchTrueFalseTotal
unless $children 0 0 0
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
140 0 my $code = $children->can( $name );
141 0 ▶ die( "No method \"\$name\" in class \"", ( ref( $children ) || $children ), "\".\n" ) if( !$code );
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
Condition0%0/3
ref $children || $children
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $children || $children
ref $children $children
Truth table0%0/3
A || B
A= ref $childrenB= $children
ABresult
1X1
011
000
142 0 eval( "sub $name { return( shift->children->$name( \@_ ) ); }\n\n" );
143 0 return( $code->( $children, @_ ) );
144 }
145  
146 1 1;
147 # NOTE: POD
148 __END__
« Object/XQuery.pm ↑ Summary Object/DOM/Element/Input.pm »