| 1 | ##---------------------------------------------------------------------------- | ||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/Number.pm | ||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||
| 6 | ## Created 2021/04/22 | ||||||||||||
| 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::Number; | ||||||||||||
| 15 | BEGIN | ||||||||||||
| 16 | { | ||||||||||||
| 17 | 11 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 11 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 11 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 11 | ▶ | use parent qw( Module::Generic::Number ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 11 | ▶ | use vars qw( $VERSION ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 11 | our $VERSION = 'v0.2.0'; | |||||||||||
| 23 | }; | ||||||||||||
| 24 | |||||||||||||
| 25 | 11 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 11 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | |||||||||||||
| 28 | sub as_xml | ||||||||||||
| 29 | { | ||||||||||||
| 30 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
as_xml: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 31 | 0 | my $n = $self->as_string; | |||||||||||
| 32 | 0 | ▶ | return( "<Number>" . ( defined( $n ) ? $n : 'NaN' ) . "</Number>\n" ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | 0 | ▶ | sub evaluate { return( $_[0] ); } | ||||||||||
|
Subroutine
evaluate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 36 | |||||||||||||
| 37 | # Return an empty hash | ||||||||||||
| 38 | 0 | ▶ | sub getAttributes { return( shift->new_hash ); } | ||||||||||
|
Subroutine
getAttributes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 39 | |||||||||||||
| 40 | # Return an empty array | ||||||||||||
| 41 | 0 | ▶ | sub getChildNodes { return( shift->new_array ); } | ||||||||||
|
Subroutine
getChildNodes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 42 | |||||||||||||
| 43 | sub isEqualNode | ||||||||||||
| 44 | { | ||||||||||||
| 45 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||
|
Subroutine
isEqualNode: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 46 | 0 | ▶ | my $e = shift( @_ ) || return( $self->error( "No html element was provided to insert." ) ); | ||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('No html element was provided to insert.'))
MC/DC0%0/1
shift @_ || (return $self->error('No html element was provided to insert.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||
| 47 | 0 | ▶ | return( $self->error( "Element provided (", overload::StrVal( $e ), ") is not an HTML::Object::Element." ) ) if( !$self->_is_a( $e => 'HTML::Object::Element' ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 0 | ▶ | return(0) if( !$self->_is_a( $e => 'HTML::Object::Number' ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 0 | return( $self->value eq $e->value ); | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | sub string_value { return( $_[0]->value ); } | ||||||||||
|
Subroutine
string_value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 53 | |||||||||||||
| 54 | sub to_boolean | ||||||||||||
| 55 | { | ||||||||||||
| 56 | 0 | ▶ | require HTML::Object::Boolean; | ||||||||||
|
Subroutine
to_boolean: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 57 | 0 | ▶ | return( shift->as_string ? HTML::Object::Boolean->True : HTML::Object::Boolean->False ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 0 | ▶ | sub to_number { return( $_[0] ); } | ||||||||||
|
Subroutine
to_number: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 61 | |||||||||||||
| 62 | sub to_literal | ||||||||||||
| 63 | { | ||||||||||||
| 64 | 0 | ▶ | require HTML::Object::Literal; | ||||||||||
|
Subroutine
to_literal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 65 | 0 | return( HTML::Object::Literal->new( shift->as_string ) ); | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 0 | ▶ | sub value { return( shift->as_string ); } | ||||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 69 | |||||||||||||
| 70 | 11 | 1; | |||||||||||
| 71 | # NOTE: POD | ||||||||||||
| 72 | __END__ | ||||||||||||
| 73 | |||||||||||||
| 74 | =encoding utf-8 | ||||||||||||
| 75 | |||||||||||||
| 76 | =head1 NAME | ||||||||||||
| 77 | |||||||||||||
| 78 | HTML::Object::Number - Simple numeric values | ||||||||||||
| 79 | |||||||||||||
| 80 | =head1 SYNOPSIS | ||||||||||||
| 81 | |||||||||||||
| 82 | use HTML::Object::Number; | ||||||||||||
| 83 | my $this = HTML::Object::Number->new || | ||||||||||||
| 84 | die( HTML::Object::Number->error, "\n" ); | ||||||||||||
| 85 | |||||||||||||
| 86 | =head1 VERSION | ||||||||||||
| 87 | |||||||||||||
| 88 | v0.2.0 | ||||||||||||
| 89 | |||||||||||||
| 90 | =head1 DESCRIPTION | ||||||||||||
| 91 | |||||||||||||
| 92 | This class holds simple numeric values. It does not support -0, +/- Infinity, or NaN, as the XPath spec says it should, but I am not hurting anyone I do not think. | ||||||||||||
| 93 | |||||||||||||
| 94 | =head1 METHODS | ||||||||||||
| 95 | |||||||||||||
| 96 | =head2 new | ||||||||||||
| 97 | |||||||||||||
| 98 | Provided with a C<number> and this creates a new L<HTML::Object::Number> object. Does some rudimentary numeric checking on the C<number> to ensure it actually is a number. | ||||||||||||
| 99 | |||||||||||||
| 100 | =head2 as_xml | ||||||||||||
| 101 | |||||||||||||
| 102 | Returns a string representation of the current value as xml. | ||||||||||||
| 103 | |||||||||||||
| 104 | =head2 evaluate | ||||||||||||
| 105 | |||||||||||||
| 106 | Returns the current object. | ||||||||||||
| 107 | |||||||||||||
| 108 | =head2 getAttributes | ||||||||||||
| 109 | |||||||||||||
| 110 | Returns an empty L<hash object|Module::Generic::Hash> | ||||||||||||
| 111 | |||||||||||||
| 112 | =head2 getChildNodes | ||||||||||||
| 113 | |||||||||||||
| 114 | Returns an empty L<array object|Module::Generic::Array> | ||||||||||||
| 115 | |||||||||||||
| 116 | =head2 isEqualNode | ||||||||||||
| 117 | |||||||||||||
| 118 | Returns a boolean value which indicates whether or not two elements are of the same type and all their defining data points match. | ||||||||||||
| 119 | |||||||||||||
| 120 | Two elements are equal when they have the same type, defining characteristics (this would be their ID, number of children, and so forth), its attributes match, and so on. The specific set of data points that must match varies depending on the types of the elements. | ||||||||||||
| 121 | |||||||||||||
| 122 | See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode> | ||||||||||||
| 123 | |||||||||||||
| 124 | =head2 string_value | ||||||||||||
| 125 | |||||||||||||
| 126 | Returns the current value. | ||||||||||||
| 127 | |||||||||||||
| 128 | =head2 to_boolean | ||||||||||||
| 129 | |||||||||||||
| 130 | Returns the current value as a L<boolean|HTML::Object::Boolean> object. | ||||||||||||
| 131 | |||||||||||||
| 132 | =head2 to_literal | ||||||||||||
| 133 | |||||||||||||
| 134 | Returns the current value as a L<literal object|HTML::Object::Literal>. | ||||||||||||
| 135 | |||||||||||||
| 136 | =head2 to_number | ||||||||||||
| 137 | |||||||||||||
| 138 | Returns the current object. | ||||||||||||
| 139 | |||||||||||||
| 140 | =head2 value | ||||||||||||
| 141 | |||||||||||||
| 142 | Also as overloaded stringification. Returns the numeric value held. | ||||||||||||
| 143 | |||||||||||||
| 144 | =head1 AUTHOR | ||||||||||||
| 145 | |||||||||||||
| 146 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||
| 147 | |||||||||||||
| 148 | =head1 SEE ALSO | ||||||||||||
| 149 | |||||||||||||
| 150 | L<HTML::Object>, L<HTML::Object::Attribute>, L<HTML::Object::Boolean>, L<HTML::Object::Closing>, L<HTML::Object::Collection>, L<HTML::Object::Comment>, L<HTML::Object::Declaration>, L<HTML::Object::Document>, L<HTML::Object::Element>, L<HTML::Object::Exception>, L<HTML::Object::Literal>, L<HTML::Object::Number>, L<HTML::Object::Root>, L<HTML::Object::Space>, L<HTML::Object::Text>, L<HTML::Object::XQuery> | ||||||||||||
| 151 | |||||||||||||
| 152 | =head1 COPYRIGHT & LICENSE | ||||||||||||
| 153 | |||||||||||||
| 154 | Copyright (c) 2021 DEGUEST Pte. Ltd. | ||||||||||||
| 155 | |||||||||||||
| 156 | All rights reserved | ||||||||||||
| 157 | |||||||||||||
| 158 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||
| 159 | |||||||||||||
| 160 | =cut | ||||||||||||