| 1 | ##---------------------------------------------------------------------------- | ||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/ElementDataMap.pm | ||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||
| 6 | ## Created 2021/12/12 | ||||||||||||
| 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::ElementDataMap; | ||||||||||||
| 15 | BEGIN | ||||||||||||
| 16 | 2 | ▶ | { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 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' ); | |||||||||||
| 20 | 2 | ▶ | use parent qw( Module::Generic ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 2 | ▶ | use vars qw( $VERSION ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 2 | our $VERSION = 'v0.2.0'; | |||||||||||
| 23 | }; | ||||||||||||
| 24 | |||||||||||||
| 25 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | |||||||||||||
| 28 | sub init | ||||||||||||
| 29 | 1 | ▶ | { | ||||||||||
|
Subroutine
init: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||
| 30 | 1 | my $self = shift( @_ ); | |||||||||||
| 31 | 1 | ▶ | my $elem = shift( @_ ) || return( $self->error( "No HTML::Object::Element was provided." ) ); | ||||||||||
|
Condition50%1/2
shift @_ || (return $self->error('No HTML::Object::Element was provided.'))
MC/DC0%0/1
shift @_ || (return $self->error('No HTML::Object::Element was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||
| 32 | 1 | ▶ | return( $self->error( "Element object provided is not a HTML::Object::Element" ) ) if( !$self->_is_a( $elem => 'HTML::Object::Element' ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 1 | $self->{element} = $elem; | |||||||||||
| 34 | 1 | $self->{_init_strict_use_sub} = 1; | |||||||||||
| 35 | 1 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | 1 | return( $self ); | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | AUTOLOAD | ||||||||||||
| 40 | 2 | ▶ | { | ||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=14.0
| |||||||||||||
| 41 | 2 | my( $name ) = our $AUTOLOAD =~ /([^:]+)$/; | |||||||||||
| 42 | 2 | my $self = shift( @_ ); | |||||||||||
| 43 | 2 | ▶ | my $elem = $self->{element} || die( "No element object set!\n" ); | ||||||||||
|
Condition50%1/2
$self->{'element'} || die("No element object set!\n")
MC/DC0%0/1
$self->{'element'} || die("No element object set!\n")
$self->{'element'}
Truth table50%1/2
A
A= $self->{'element'}
| |||||||||||||
| 44 | 2 | ( my $copy = $name ) =~ s/^([A-Z])/\L$1\E/; | |||||||||||
| 45 | 2 | my $att = 'data-' . join( '-', map( lc( $_ ), split( /(?=[A-Z])/, $copy ) ) ); | |||||||||||
| 46 | 2 | ▶ | if( @_ ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | { | ||||||||||||
| 48 | 1 | my $val = shift( @_ ); | |||||||||||
| 49 | 1 | ▶ | if( !$elem->attributes->has( $att ) ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | { | ||||||||||||
| 51 | 1 | $elem->setAttribute( $att => $val ); | |||||||||||
| 52 | } | ||||||||||||
| 53 | else | ||||||||||||
| 54 | { | ||||||||||||
| 55 | 0 | $elem->attributes->set( $att => $val ); | |||||||||||
| 56 | } | ||||||||||||
| 57 | 1 | $elem->reset(1); | |||||||||||
| 58 | 1 | return( $self ); | |||||||||||
| 59 | } | ||||||||||||
| 60 | else | ||||||||||||
| 61 | { | ||||||||||||
| 62 | 1 | return( $elem->attributes->get( $att ) ); | |||||||||||
| 63 | } | ||||||||||||
| 64 | }; | ||||||||||||
| 65 | |||||||||||||
| 66 | |||||||||||||
| 67 | 2 | 1; | |||||||||||
| 68 | # NOTE: POD | ||||||||||||
| 69 | __END__ | ||||||||||||