| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/Collection.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.3.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2021/12/24 | ||||||||||||||||||||||||||||
| 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::Collection; | ||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||
| 16 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 5 | warnings::register_categories( 'HTML::Object' ); | |||||||||||||||||||||||||||
| 20 | 5 | ▶ | use parent qw( Module::Generic::Array ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use vars qw( $AUTOLOAD $VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use Module::Generic::Null; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | use Wanted; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use overload ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | 'eq' => sub{ Scalar::Util::refaddr( $_[0] ) eq Scalar::Util::refaddr( $_[1] ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | '==' => sub{ Scalar::Util::refaddr( $_[0] ) eq Scalar::Util::refaddr( $_[1] ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 502 | ▶ | bool => sub{ $_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 5 | fallback => 1, | |||||||||||||||||||||||||||
| 30 | 5 | ); | |||||||||||||||||||||||||||
| 31 | 5 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 32 | 5 | our $VERSION = 'v0.3.0'; | |||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub item { return( shift->index( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
item: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub namedItem | ||||||||||||||||||||||||||||
| 41 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
namedItem: called CC=11 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 2 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 43 | 2 | my $name = shift( @_ ); | |||||||||||||||||||||||||||
| 44 | 2 | for( @$self ) | |||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 4 | ▶ | return( $_ ) if( $self->_can( $_ => 'id' ) && $_->id eq $name ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_can($_, "id") and $_->id eq $name
MC/DC50%1/2
$self->_can($_, "id") and $_->id eq $name
$self->_can($_, "id")
$_->id eq $name
Truth table66%2/3
A and B
A= $self->_can($_, "id")B= $_->id eq $name
| |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | return( $_ ) if( $self->_can( $_ => 'name' ) && $_->name eq $name ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_can($_, "name") and $_->name eq $name
MC/DC0%0/2
$self->_can($_, "name") and $_->name eq $name
$self->_can($_, "name")
$_->name eq $name
Truth table66%2/3
A and B
A= $self->_can($_, "name")B= $_->name eq $name
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if( want( 'OBJECT' ) ) | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 0 | return( Module::Generic::Null->new( @_ ) ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | elsif( want( 'ARRAY' ) ) | ||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | 0 | return( [] ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | elsif( want( 'HASH' ) ) | ||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 0 | return( {} ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | elsif( want( 'CODE' ) ) | ||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return( sub{ return; } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | elsif( want( 'REFSCALAR' ) ) | ||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||
| 67 | 0 | return( \undef ); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | else | ||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub _can | ||||||||||||||||||||||||||||
| 76 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_can: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||
| 77 | 6 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 78 | 5 | ▶ | no overloading; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | # Nothing provided | ||||||||||||||||||||||||||||
| 80 | 6 | ▶ | return if( !scalar( @_ ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 6 | ▶ | return if( !defined( $_[0] ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 6 | ▶ | return if( !Scalar::Util::blessed( $_[0] ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 6 | return( $_[0]->can( $_[1] ) ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # NOTE: AUTOLOAD | ||||||||||||||||||||||||||||
| 87 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 88 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 89 | 1 | my( $meth ) = our $AUTOLOAD =~ /([^:]+)$/; | |||||||||||||||||||||||||||
| 90 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 91 | 1 | ▶ | die( "No class function \"$meth\" exists in this package \"", __PACKAGE__, "\".\n" ) if( !defined( $self ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 1 | return( $self->namedItem( $meth ) ); | |||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # To avoid being caught by AUTOLOAD | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub DESTROY {}; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 5 | 1; | |||||||||||||||||||||||||||
| 99 | # NOTE: POD | ||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||