« blib/lib/HTML/Object/DOM/Element/Image.pm
↑ Summary
blib/lib/HTML/Object/DOM/DocumentFragment.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 | { | ||||||||||||
| 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' ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 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 | { | ||||||||||||
| 30 | 5 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
init: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||
| 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
| |||||||||||||
| 37 | 5 | ▶ | return( $self->error( "No callback has been set for this event listener." ) ) if( !$self->{code} ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | { | ||||||||||||
| 53 | 2 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
remove: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||
| 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'}))
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
| |||||||||||||
| 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'}))
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
| |||||||||||||
| 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'}))
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
| |||||||||||||
| 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
MC/DC0%0/1
$opts->{"capture"} //= 0
$opts->{"capture"}
Truth table50%1/2
A
A= $opts->{"capture"}
| |||||||||||||
| 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__ | ||||||||||||