| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/XPath/Literal.pm | ||||||||||||||||||||
| 3 | ## Version v0.2.1 | ||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||
| 6 | ## Created 2021/12/05 | ||||||||||||||||||||
| 7 | ## Modified 2022/11/11 | ||||||||||||||||||||
| 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::Literal; | ||||||||||||||||||||
| 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( $TRUE $FALSE $BASE_CLASS $DEBUG $VERSION ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 14 | ▶ | use HTML::Object::XPath::Boolean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 14 | our $TRUE = HTML::Object::XPath::Boolean->True; | |||||||||||||||||||
| 24 | 14 | our $FALSE = HTML::Object::XPath::Boolean->False; | |||||||||||||||||||
| 25 | 14 | our $BASE_CLASS = 'HTML::Object::XPath'; | |||||||||||||||||||
| 26 | 14 | our $DEBUG = 0; | |||||||||||||||||||
| 27 | use overload ( | ||||||||||||||||||||
| 28 | 14 | '""' => \&value, | |||||||||||||||||||
| 29 | 'cmp' => \&cmp, | ||||||||||||||||||||
| 30 | 'bool' => \&value, | ||||||||||||||||||||
| 31 | fallback => 1, | ||||||||||||||||||||
| 32 | 14 | ▶ | ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 14 | our $VERSION = 'v0.2.1'; | |||||||||||||||||||
| 34 | }; | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 14 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | 14 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | sub new | ||||||||||||||||||||
| 40 | { | ||||||||||||||||||||
| 41 | 3988 | ▶ | my $this = shift( @_ ); | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 42 | 3988 | my $str = shift( @_ ); | |||||||||||||||||||
| 43 | 3988 | ▶ | return( bless( \$str => ( 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
| |||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | sub as_string | ||||||||||||||||||||
| 47 | { | ||||||||||||||||||||
| 48 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 49 | 0 | my $string = $$self; | |||||||||||||||||||
| 50 | 0 | $string =~ s/'/'/g; | |||||||||||||||||||
| 51 | 0 | return( "'$string'" ); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | sub as_xml | ||||||||||||||||||||
| 55 | { | ||||||||||||||||||||
| 56 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
as_xml: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 57 | 0 | my $string = $$self; | |||||||||||||||||||
| 58 | 0 | return( "<Literal>$string</Literal>\n" ); | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub cmp | ||||||||||||||||||||
| 62 | { | ||||||||||||||||||||
| 63 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
cmp: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 64 | 0 | my( $cmp, $swap ) = @_; | |||||||||||||||||||
| 65 | 0 | ▶ | return( $swap ? $cmp cmp $$self : $$self cmp $cmp ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | sub evaluate | ||||||||||||||||||||
| 69 | { | ||||||||||||||||||||
| 70 | 140 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
evaluate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 71 | 140 | return( $self ); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 1 | ▶ | sub getChildNodes { die( "cannot get child nodes of a literal" ); } | ||||||||||||||||||
|
Subroutine
getChildNodes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 1 | ▶ | sub getAttributes { die( "cannot get attributes of a literal" ); } | ||||||||||||||||||
|
Subroutine
getAttributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 1 | ▶ | sub getParentNode { die( "cannot get parent node of a literal" ); } | ||||||||||||||||||
|
Subroutine
getParentNode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | sub new_number { return( shift->_class_for( 'Number' )->new( @_ ) ); } | ||||||||||||||||||
|
Subroutine
new_number: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 57 | ▶ | sub string_value { return( $_[0]->value ); } | ||||||||||||||||||
|
Subroutine
string_value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | sub to_boolean | ||||||||||||||||||||
| 85 | { | ||||||||||||||||||||
| 86 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
to_boolean: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 87 | 0 | ▶ | return( ( length( $$self ) > 0 ) ? $TRUE : $FALSE ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | ▶ | sub to_literal { return( $_[0] ); } | ||||||||||||||||||
|
Subroutine
to_literal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | ▶ | sub to_number { return( $_[0]->new_number( $_[0]->value ) ); } | ||||||||||||||||||
|
Subroutine
to_number: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | sub value | ||||||||||||||||||||
| 95 | { | ||||||||||||||||||||
| 96 | 4084 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 97 | 4084 | return( $$self ); | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | sub value_as_number | ||||||||||||||||||||
| 101 | { | ||||||||||||||||||||
| 102 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||
|
Subroutine
value_as_number: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 103 | 0 | ▶ | warn( "numifying '" . $$self . "' to '" . +$$self . "'\n" ) if( $self->_is_warnings_enabled( 'HTML::Object' ) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 0 | return( +$$self ); | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub _class_for | ||||||||||||||||||||
| 108 | { | ||||||||||||||||||||
| 109 | 0 | ▶ | my( $self, $mod ) = @_; | ||||||||||||||||||
|
Subroutine
_class_for: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 110 | 0 | eval( "require ${BASE_CLASS}\::${mod};" ); | |||||||||||||||||||
| 111 | 0 | ▶ | die( $@ ) if( $@ ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG; | ||||||||||||||||||||
| 113 | 0 | ▶ | eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) ); | ||||||||||||||||||
|
Condition0%0/2
$HTML::Object::XPath::Literal::DEBUG // 0
MC/DC0%0/1
$HTML::Object::XPath::Literal::DEBUG // 0
$HTML::Object::XPath::Literal::DEBUG
Truth table0%0/2
A
A= $HTML::Object::XPath::Literal::DEBUG
| |||||||||||||||||||||
| 114 | 0 | return( "${BASE_CLASS}::${mod}" ); | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 14 | 1; | |||||||||||||||||||
| 118 | # NOTE: POD | ||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||