| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/XPathEvaluator.pm | ||||||||||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||
| 6 | ## Created 2022/01/01 | ||||||||||||||||||||
| 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::DOM::XPathEvaluator; | ||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||
| 16 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | warnings::register_categories( 'HTML::Object' ); | |||||||||||||||||||
| 20 | 1 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 1 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 1 | ▶ | use HTML::Object::XPath; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 1 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||
| 24 | }; | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | sub init | ||||||||||||||||||||
| 30 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 31 | 0 | my $self = shift( @_ ); | |||||||||||||||||||
| 32 | 0 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||
| 33 | 0 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 0 | $self->{_xp} = HTML::Object::XPath->new; | |||||||||||||||||||
| 35 | 0 | return( $self ); | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | sub createExpression { return( shift->{_xp}->parse( @_ ) ); } | ||||||||||||||||||
|
Subroutine
createExpression: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ▶ | sub createNSResolver { return; } | ||||||||||||||||||
|
Subroutine
createNSResolver: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | sub evaluate | ||||||||||||||||||||
| 43 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
evaluate: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 44 | 0 | my $self = shift( @_ ); | |||||||||||||||||||
| 45 | 0 | my $expr = shift( @_ ); | |||||||||||||||||||
| 46 | 0 | ▶ | if( $self->_is_a( $expr => 'HTML::Object::XPath::Expr' ) ) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 47 | { | ||||||||||||||||||||
| 48 | 0 | return( $expr->evaluate( @_ ) ); | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | ▶ | elsif( !ref( $expr ) || overload::Method( $expr, '""' ) ) | |||||||||||||||||||
|
Condition0%0/3
not ref $expr or overload::Method($expr, "\"\"")
MC/DC0%0/2
not ref $expr or overload::Method($expr, "\"\"")
not ref $expr
overload::Method($expr, "\"\"")
Truth table0%0/3
not(A) or B
A= not ref $exprB= overload::Method($expr, "\"\"")
| |||||||||||||||||||||
| 51 | { | ||||||||||||||||||||
| 52 | 0 | ▶ | my $xpath = $self->{_xp}->parse( $expr ) || return( $self->pass_error( $self->{_xp}->error ) ); | ||||||||||||||||||
|
Condition0%0/2
$self->{'_xp'}->parse($expr) || (return $self->pass_error($self->{'_xp'}->error))
MC/DC0%0/1
$self->{'_xp'}->parse($expr) || (return $self->pass_error($self->{'_xp'}->error))
$self->{'_xp'}->parse($expr)
Truth table0%0/2
A
A= $self->{'_xp'}->parse($expr)
| |||||||||||||||||||||
| 53 | 0 | return( $xpath->evaluate( @_ ) ); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | else | ||||||||||||||||||||
| 56 | { | ||||||||||||||||||||
| 57 | 0 | return( $self->error({ | |||||||||||||||||||
| 58 | message => 'Value provided (' . overload::StrVal( $expr ) . ' is not a HTML::Object::XPath::Expr object. You can create one using createExpression()', | ||||||||||||||||||||
| 59 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||
| 60 | }) ); | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 0 | return( $self ); | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 1 | 1; | |||||||||||||||||||
| 66 | # NOTE: POD | ||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||