blib/lib/HTML/Object/EventListener.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 83 CC 2 SCAR 9.2
CC
2
Cov
0%
init
6.0
BEGIN
2.0
capture
2.0
CRAP 2.5
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 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( Module::Generic );
21 use vars qw( $VERSION );
22 our $VERSION = 'v0.2.0';
23 };
24  
25 use strict;
26 use warnings;
27  
28 sub init
29 {
30 my $self = shift( @_ );
31 $self->{element} = undef;
32 $self->{type} = undef;
33 $self->{code} = undef;
34 $self->{options} = {};
35 $self->{_init_strict_use_sub} = 1;
36 $self->SUPER::init( @_ ) || return( $self->pass_error );
37 return( $self->error( "No callback has been set for this event listener." ) ) if( !$self->{code} );
38 return( $self );
39 }
40  
41 sub capture { return( shift->options->{capture} ); }
42  
43 sub code { return( shift->_set_get_code( 'code', @_ ) ); }
44  
45 sub element { return( shift->_set_get_object_without_init( 'element', 'HTML::Object::Element', @_ ) ); }
46  
47 sub handleEvent { return( shift->code( @_ ) ); }
48  
49 sub options { return( shift->_set_get_hash_as_mix_object( 'options', @_ ) ); }
50  
51 sub remove
52 {
53 my $self = shift( @_ );
54 my $elem = $self->element ||
55 return( $self->error({
56 message => "No element object found in our event listener!",
57 class => 'HTML::Object::SyntaxError',
58 }) );
59 my $type = $self->type ||
60 return( $self->error({
61 message => "No event type found in our event listener!",
62 class => 'HTML::Object::SyntaxError',
63 }) );
64 my $code = $self->code ||
65 return( $self->error({
66 message => "No event callabck found in our event listener!",
67 class => 'HTML::Object::SyntaxError',
68 }) );
69 my $opts = $self->options;
70 $opts->{capture} //= 0;
71 $elem->removeEventListener( $type, $code, { capture => $opts->{capture} });
72 return( $self );
73 }
74  
75 sub type { return( shift->_set_get_scalar_as_object( 'type', @_ ) ); }
76  
77 1;
78 # NOTE: POD
79 __END__