Object/EventListener.pm

filter: Statementstmt 97.7% 43 / 44 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 93.3% 14 / 15 Podpod 100% 8 / 8 totaltotal 85.5% 71 / 83 CC 7 SCAR 8.7
CC
7
Cov
88%
remove
5.4
init
3.0
handleEvent
2.0
CRAP 2.4
« Object/ElementDataMap.pm ↑ Summary Object/DOM/Element/TableCol.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/EventListener.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/11
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::EventListener;
15 BEGIN
16 36 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 36 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 36 warnings::register_categories( 'HTML::Object' );
20 36 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 36 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 our $VERSION = 'v0.2.0';
23 };
24  
25 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub init
29 5 ▶{
Subroutine init: called CC=3 SCAR=11.1
Pod documented
30 5 my $self = shift( @_ );
31 5 $self->{element} = undef;
32 5 $self->{type} = undef;
33 5 $self->{code} = undef;
34 5 $self->{options} = {};
35 5 $self->{_init_strict_use_sub} = 1;
36 5 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 5 0 5
37 5 ▶ return( $self->error( "No callback has been set for this event listener." ) ) if( !$self->{code} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"code"} 0 5 5
38 5 return( $self );
39 }
40  
41 6 ▶sub capture { return( shift->options->{capture} ); }
Subroutine capture: called CC=1 SCAR=0.0
Pod documented
42  
43 14 ▶sub code { return( shift->_set_get_code( 'code', @_ ) ); }
Subroutine code: called CC=1 SCAR=0.0
Pod documented
44  
45 7 ▶sub element { return( shift->_set_get_object_without_init( 'element', 'HTML::Object::Element', @_ ) ); }
Subroutine element: called CC=1 SCAR=0.0
Pod documented
46  
47 0 ▶sub handleEvent { return( shift->code( @_ ) ); }
Subroutine handleEvent: not called CC=1 SCAR=6.9
Pod documented
48  
49 13 ▶sub options { return( shift->_set_get_hash_as_mix_object( 'options', @_ ) ); }
Subroutine options: called CC=1 SCAR=0.0
Pod documented
50  
51 sub remove
52 2 ▶{
Subroutine remove: called CC=5 SCAR=16.8
Pod documented
53 2 my $self = shift( @_ );
54 2 ▶ my $elem = $self->element ||
Condition50%1/2
$self->element || (return $self->error({'message', 'No element object found in our event listener!', 'class', 'HTML::Object::SyntaxError'}))
l!l
20
MC/DC0%0/1
$self->element || (return $self->error({'message', 'No element object found in our event listener!', 'class', 'HTML::Object::SyntaxError'}))
$self->element
Truth table50%1/2
A
A= $self->element
Aresult
11
00
55 return( $self->error({
56 message => "No element object found in our event listener!",
57 class => 'HTML::Object::SyntaxError',
58 }) );
59 2 ▶ my $type = $self->type ||
Condition50%1/2
$self->type || (return $self->error({'message', 'No event type found in our event listener!', 'class', 'HTML::Object::SyntaxError'}))
l!l
20
MC/DC0%0/1
$self->type || (return $self->error({'message', 'No event type found in our event listener!', 'class', 'HTML::Object::SyntaxError'}))
$self->type
Truth table50%1/2
A
A= $self->type
Aresult
11
00
60 return( $self->error({
61 message => "No event type found in our event listener!",
62 class => 'HTML::Object::SyntaxError',
63 }) );
64 2 ▶ my $code = $self->code ||
Condition50%1/2
$self->code || (return $self->error({'message', 'No event callabck found in our event listener!', 'class', 'HTML::Object::SyntaxError'}))
l!l
20
MC/DC0%0/1
$self->code || (return $self->error({'message', 'No event callabck found in our event listener!', 'class', 'HTML::Object::SyntaxError'}))
$self->code
Truth table50%1/2
A
A= $self->code
Aresult
11
00
65 return( $self->error({
66 message => "No event callabck found in our event listener!",
67 class => 'HTML::Object::SyntaxError',
68 }) );
69 2 my $opts = $self->options;
70 2 ▶ $opts->{capture} //= 0;
Condition50%1/2
$opts->{"capture"} //= 0
l!l
20
MC/DC0%0/1
$opts->{"capture"} //= 0
$opts->{"capture"}
Truth table50%1/2
A
A= $opts->{"capture"}
Aresult
11
00
71 2 $elem->removeEventListener( $type, $code, { capture => $opts->{capture} });
72 2 return( $self );
73 }
74  
75 7 ▶sub type { return( shift->_set_get_scalar_as_object( 'type', @_ ) ); }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
76  
77 36 1;
78 # NOTE: POD
79 __END__
« Object/ElementDataMap.pm ↑ Summary Object/DOM/Element/TableCol.pm »