| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/XPath/LocationPath.pm | ||||||||||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||
| 6 | ## Created 2021/12/05 | ||||||||||||||||||||
| 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::XPath::LocationPath; | ||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||
| 16 | { | ||||||||||||||||||||
| 17 | 14 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 14 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 14 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 14 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 14 | ▶ | use vars qw( $BASE_CLASS $DEBUG $VERSION ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 14 | our $BASE_CLASS = 'HTML::Object::XPath'; | |||||||||||||||||||
| 23 | 14 | our $DEBUG = 0; | |||||||||||||||||||
| 24 | 14 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||
| 25 | }; | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 14 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 14 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | sub new | ||||||||||||||||||||
| 31 | { | ||||||||||||||||||||
| 32 | 86 | ▶ | my $this = shift( @_ ); | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||
| 33 | 86 | ▶ | return( bless( [] => ( ref( $this ) || $this ) ) ); | ||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | sub as_string | ||||||||||||||||||||
| 37 | { | ||||||||||||||||||||
| 38 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
as_string: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 39 | 0 | my $string = ''; | |||||||||||||||||||
| 40 | 0 | ▶ | for( my $i = 0; $i < @$self; $i++ ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | { | ||||||||||||||||||||
| 42 | 0 | ▶ | $string .= ( $self->[ $i ]->as_string // '' ); | ||||||||||||||||||
|
Condition0%0/2
$self->[$i]->as_string // ""
MC/DC0%0/1
$self->[$i]->as_string // ""
$self->[$i]->as_string
Truth table0%0/2
A
A= $self->[$i]->as_string
| |||||||||||||||||||||
| 43 | 0 | ▶ | $string .= '/' if( $self->[ $i + 1 ] ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | 0 | return( $string ); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | sub as_xml | ||||||||||||||||||||
| 49 | { | ||||||||||||||||||||
| 50 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
as_xml: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 51 | 0 | my $string = "<LocationPath>\n"; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | for (my $i = 0; $i < @$self; $i++ ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | { | ||||||||||||||||||||
| 55 | 0 | $string .= $self->[ $i ]->as_xml; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | 0 | $string .= "</LocationPath>\n"; | |||||||||||||||||||
| 58 | 0 | return( $string ); | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub evaluate | ||||||||||||||||||||
| 62 | { | ||||||||||||||||||||
| 63 | 238 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
evaluate: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 64 | # context _MUST_ be a single node | ||||||||||||||||||||
| 65 | 238 | my $context = shift( @_ ); | |||||||||||||||||||
| 66 | 238 | ▶ | die( "No context" ) unless( $context ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # I _think_ this is how it should work :) | ||||||||||||||||||||
| 69 | 238 | my $nodeset = $self->new_nodeset(); | |||||||||||||||||||
| 70 | 238 | $nodeset->push( $context ); | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 238 | foreach my $step ( @$self ) | |||||||||||||||||||
| 73 | { | ||||||||||||||||||||
| 74 | # For each step | ||||||||||||||||||||
| 75 | # evaluate the step with the nodeset | ||||||||||||||||||||
| 76 | 427 | my $pos = 1; | |||||||||||||||||||
| 77 | # die( "Looping !\n" ) if( ref( $step ) eq ref( $self ) ); | ||||||||||||||||||||
| 78 | 427 | ▶ | die( "Looping !\n" ) if( $step eq $self ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 427 | $nodeset = $step->evaluate( $nodeset ); | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | 235 | return( $nodeset ); | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 238 | ▶ | sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); } | ||||||||||||||||||
|
Subroutine
new_nodeset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | sub new_root { return( shift->_class_for( 'Root' )->new( @_ ) ); } | ||||||||||||||||||
|
Subroutine
new_root: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | # sub push { return( CORE::push( @{$_[0]}, @_ ) ); } | ||||||||||||||||||||
| 89 | sub push | ||||||||||||||||||||
| 90 | { | ||||||||||||||||||||
| 91 | 163 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
push: called CC=4 SCAR=20.1
Pod
documented
| |||||||||||||||||||||
| 92 | 163 | ▶ | if( $self->debug ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | { | ||||||||||||||||||||
| 94 | 0 | for( @_ ) | |||||||||||||||||||
| 95 | { | ||||||||||||||||||||
| 96 | 0 | ▶ | if( ref( $_ ) eq ref( $self ) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | { | ||||||||||||||||||||
| 98 | 0 | die( "A LocationPath object was added to its own stack!\n" ); | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | 163 | return( CORE::push( @$self, @_ ) ); | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | sub set_root | ||||||||||||||||||||
| 106 | { | ||||||||||||||||||||
| 107 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
set_root: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 108 | 0 | return( unshift( @$self, $self->new_root ) ); | |||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | sub _class_for | ||||||||||||||||||||
| 112 | { | ||||||||||||||||||||
| 113 | 238 | ▶ | my( $self, $mod ) = @_; | ||||||||||||||||||
|
Subroutine
_class_for: called CC=3 SCAR=11.3
| |||||||||||||||||||||
| 114 | 238 | eval( "require ${BASE_CLASS}\::${mod};" ); | |||||||||||||||||||
| 115 | 238 | ▶ | die( $@ ) if( $@ ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG; | ||||||||||||||||||||
| 117 | 238 | ▶ | eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) ); | ||||||||||||||||||
|
Condition50%1/2
$HTML::Object::XPath::LocationPath::DEBUG // 0
MC/DC0%0/1
$HTML::Object::XPath::LocationPath::DEBUG // 0
$HTML::Object::XPath::LocationPath::DEBUG
Truth table50%1/2
A
A= $HTML::Object::XPath::LocationPath::DEBUG
| |||||||||||||||||||||
| 118 | 238 | return( "${BASE_CLASS}::${mod}" ); | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 14 | 1; | |||||||||||||||||||
| 122 | # NOTE: POD | ||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||