HTML-Object

 view release on metacpan or  search on metacpan

lib/HTML/Object/DOM/Element/Input.pm  view on Meta::CPAN

=head2 valueAsNumber

This returns a double, which represents the value of the element, interpreted as one of the following, in order:

=over 4

=item A time value

=item A number

=item NaN (C<undef>) if conversion is impossible

=back

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/valueAsNumber>

=head2 webkitEntries

This always returns C<undef> under perl.

Under JavaScript, this returns an Array of C<FileSystemEntry> objects that describes the currently selected files or directories.

lib/HTML/Object/DOM/Element/Media.pm  view on Meta::CPAN

    # <audio></audio>
    $obj->disableRemotePlayback = 1; # true
    # <audio disableremoteplayback=""></audio>

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/disableRemotePlayback>

=head2 duration

This returns whatever number you set it to under perl, as a L<Module::Generic::Number> object.

Normally, under JavaScript, this returns a read-only double-precision floating-point value indicating the total duration of the media in seconds. If no media data is available, the returned value is C<NaN>. If the media is of indefinite length (such ...

Example:

    my $obj = $doc->createElement('video');
    say( $obj->duration ); # NaN

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/duration>

=head2 ended

Returns a Boolean that indicates whether the media element has finished playing.

Example:

    my $obj = $doc->createElement('video');

lib/HTML/Object/DOM/Number.pm  view on Meta::CPAN

##----------------------------------------------------------------------------
package HTML::Object::DOM::Number;
BEGIN
{
    use strict;
    use warnings;
    use parent qw( Module::Generic::Number );
    use vars qw( $EPSILON $VERSION );
    use Config;
    # use Machine::Epsilon ();
    use POSIX qw( Inf NaN );
    use constant {
        MAX_SAFE_INTEGER    => (POSIX::pow(2,53) - 1),
        # MAX_VALUE           => (1.7976931348623157 * POSIX::pow(10,308)),
        MAX_VALUE           => (POSIX::pow(2, $Config::Config{use64bitint} eq 'define' ? 64 : 32)),
        MIN_SAFE_INTEGER    => (-(POSIX::pow(2,53) - 1)),
        MIN_VALUE           => POSIX::pow(2, -1074),
        # <https://perldoc.perl.org/perldata#Special-floating-point:-infinity-(Inf)-and-not-a-number-(NaN)>
        # NEGATIVE_INFINITY   => -9**9**9,
        NEGATIVE_INFINITY   => -Inf,
        POSITIVE_INFINITY   => Inf,
    };
    our $EPSILON;
    our $VERSION = 'v0.2.0';
};

use strict;
use warnings;

lib/HTML/Object/DOM/Number.pm  view on Meta::CPAN

# Note: property MIN_VALUE is a constant

# Note: property NEGATIVE_INFINITY is a constant

# Note: property POSITIVE_INFINITY is a constant

sub isFinite { return( $_[1] != Inf ); }

sub isInteger { return( shift->_is_integer( $_[0] ) ); }

sub isNaN { return( POSIX::isnan( $_[1] ) ); }

sub isSafeInteger { return( $_[0]->_is_integer( $_[1] ) && abs( $_[1] ) < MAX_SAFE_INTEGER ); }

sub parseFloat { return( shift->new( shift( @_ ) ) ); }

sub parseInt { return( shift->new( shift( @_ ) ) ); }

1;
# NOTE: POD
__END__

lib/HTML/Object/DOM/Number.pm  view on Meta::CPAN


    my $smallNumber = (-HTML::Object::DOM::Number->MAX_VALUE) * 2;

    if( $smallNumber == HTML::Object::DOM::Number->NEGATIVE_INFINITY )
    {
        $smallNumber = returnFinite();
    }

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY>

=head2 NaN

Special "Not a Number" value.

This is actually a value exported by L<POSIX>

Example:

    sub sanitise
    {
        my $x = shift( @_ );
        if( isNaN($x) )
        {
            return( HTML::Object::DOM::Number->NaN );
        }
        return($x);
    }

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN>

=head2 POSITIVE_INFINITY

Special value representing infinity. Returned on overflow.

Example:

    my $bigNumber = HTML::Object::DOM::Number->MAX_VALUE * 2;

    if( $bigNumber == HTML::Object::DOM::Number->POSITIVE_INFINITY )

lib/HTML/Object/DOM/Number.pm  view on Meta::CPAN


=head2 isFinite

Determine whether the passed value is a finite number.

Example:

    HTML::Object::DOM::Number->isFinite($value)

    HTML::Object::DOM::Number->isFinite(Infinity);  # false
    HTML::Object::DOM::Number->isFinite(NaN);       # false
    HTML::Object::DOM::Number->isFinite(-Infinity); # false

    HTML::Object::DOM::Number->isFinite(0);         # true
    HTML::Object::DOM::Number->isFinite(2e64);      # true

    HTML::Object::DOM::Number->isFinite('0');       # false, would've been true with
                                                    # global isFinite('0')
    HTML::Object::DOM::Number->isFinite(undef);     # false, would've been true with
                                                    # global isFinite(undef)

lib/HTML/Object/DOM/Number.pm  view on Meta::CPAN

    HTML::Object::DOM::Number->isInteger(value)

    HTML::Object::DOM::Number->isInteger(0);           # true
    HTML::Object::DOM::Number->isInteger(1);           # true
    HTML::Object::DOM::Number->isInteger(-100000);     # true
    HTML::Object::DOM::Number->isInteger(99999999999999999999999); # true

    HTML::Object::DOM::Number->isInteger(0.1);         # false
    HTML::Object::DOM::Number->isInteger(Math->PI);    # false

    HTML::Object::DOM::Number->isInteger(NaN);         # false
    HTML::Object::DOM::Number->isInteger(Infinity);    # false
    HTML::Object::DOM::Number->isInteger(-Infinity);   # false
    HTML::Object::DOM::Number->isInteger('10');        # false
    HTML::Object::DOM::Number->isInteger(true);        # false
    HTML::Object::DOM::Number->isInteger(false);       # false
    HTML::Object::DOM::Number->isInteger([1]);         # false

    HTML::Object::DOM::Number->isInteger(5.0);         # true
    HTML::Object::DOM::Number->isInteger(5.000000000000001);  # false
    HTML::Object::DOM::Number->isInteger(5.0000000000000001); # true

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger>

=head2 isNaN

Determine whether the passed value is C<NaN>.

Example:

    HTML::Object::DOM::Number->isNaN(value)

    HTML::Object::DOM::Number->isNaN(NaN);              # true
    HTML::Object::DOM::Number->isNaN(HTML::Object::DOM::Number->NaN); # true
    HTML::Object::DOM::Number->isNaN(0 / 0);            # true

    # e->g. these would have been true with global isNaN()
    HTML::Object::DOM::Number->isNaN('NaN');            # false
    HTML::Object::DOM::Number->isNaN(undefined);        # false
    HTML::Object::DOM::Number->isNaN({});               # false
    HTML::Object::DOM::Number->isNaN('blabla');         # false

    # These all return false
    HTML::Object::DOM::Number->isNaN(true);
    HTML::Object::DOM::Number->isNaN(undef);
    HTML::Object::DOM::Number->isNaN(37);
    HTML::Object::DOM::Number->isNaN('37');
    HTML::Object::DOM::Number->isNaN('37.37');
    HTML::Object::DOM::Number->isNaN('');
    HTML::Object::DOM::Number->isNaN(' ');

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN>

=head2 isSafeInteger

Determine whether the passed value is a safe integer (number between -(2^53 - 1) and 2^53 - 1).

Example:

    HTML::Object::DOM::Number->isSafeInteger(3);                     # true
    HTML::Object::DOM::Number->isSafeInteger(POSIX::pow(2, 53));     # false
    HTML::Object::DOM::Number->isSafeInteger(POSIX::pow(2, 53) - 1); # true
    HTML::Object::DOM::Number->isSafeInteger(NaN);                   # false
    HTML::Object::DOM::Number->isSafeInteger(Infinity);              # false
    HTML::Object::DOM::Number->isSafeInteger('3');                   # false
    HTML::Object::DOM::Number->isSafeInteger(3.1);                   # false
    HTML::Object::DOM::Number->isSafeInteger(3.0);                   # true

See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger>

=head2 parseFloat

Provided with a value and this will return a new L<HTML::Object::DOM::Number> object.

lib/HTML/Object/Number.pm  view on Meta::CPAN

    our $VERSION = 'v0.2.0';
};

use strict;
use warnings;

sub as_xml
{
    my $self = shift( @_ );
    my $n = $self->as_string;
    return( "<Number>" . ( defined( $n ) ? $n : 'NaN' ) . "</Number>\n" );
}

sub evaluate { return( $_[0] ); }

# Return an empty hash
sub getAttributes { return( shift->new_hash ); }

# Return an empty array
sub getChildNodes { return( shift->new_array ); }

lib/HTML/Object/Number.pm  view on Meta::CPAN

    use HTML::Object::Number;
    my $this = HTML::Object::Number->new || 
        die( HTML::Object::Number->error, "\n" );

=head1 VERSION

    v0.2.0

=head1 DESCRIPTION

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.

=head1 METHODS

=head2 new

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.

=head2 as_xml

Returns a string representation of the current value as xml.

lib/HTML/Object/XPath/Number.pm  view on Meta::CPAN

    else
    {
        $number =~ s/^[[:blank:]\h]*(.*)[[:blank:]\h]*$/$1/;
    }
    return( bless( \$number => ( ref( $this ) || $this ) ) );
}

sub as_string
{
    my $self = shift( @_ );
    return( defined( $$self ) ? $$self : 'NaN' );
}

sub as_xml
{
    my $self = shift( @_ );
    return( "<Number>" . ( defined( $$self ) ? $$self : 'NaN' ) . "</Number>\n" );
}

sub cmp
{
    my $self = shift( @_ );
    my( $other, $swap ) = @_;
    return( $swap ? $other <=> $$self : $$self <=> $other );
}

sub evaluate { return( $_[0] ); }

lib/HTML/Object/XPath/Number.pm  view on Meta::CPAN

    use HTML::Object::XPath::Number;
    my $num = HTML::Object::XPath::Number->new || 
        die( HTML::Object::XPath::Number->error, "\n" );

=head1 VERSION

    v0.2.0

=head1 DESCRIPTION

This module holds simple numeric values. It doesn't support -0, +/- Infinity, or NaN, as the XPath spec says it should.

=head1 METHODS

=head2 new

Provided with a C<number> and this creates a new L<HTML::Object::XPath::Number> object, with the value in C<number>. Does some
rudimentary numeric checking on C<number> to ensure it actually is a number.

=head2 as_string

Returns a string representation of the number, or C<NaN> is undefined.

=head2 as_xml

Same as L</as_string>, but in xml format.

=head2 cmp

Returns the equivalent of perl's own L<perlop/cmp> operation.

=head2 evaluate

lib/HTML/Object/XQuery.pod  view on Meta::CPAN

    $.isNumeric( "-10" );
    $.isNumeric( "0" );
    $.isNumeric( 0xFF );
    $.isNumeric( "0xFF" );
    $.isNumeric( "8e5" );
    $.isNumeric( "3.1415" );
    $.isNumeric( +10 );
    $.isNumeric( 0144 );
    # Yes, under perl, nan and Inf are considered a number. Don't believe me? Try:
    # perl -MScalar::Util=looks_like_number -lE 'say looks_like_number("nan")'
    $.isNumeric( NaN );
    $.isNumeric( Inf );
     
    # false (non-numeric)
    $.isNumeric( "-0x42" );
    $.isNumeric( "7.2acdgs" );
    $.isNumeric( "" );
    $.isNumeric( {} );
    $.isNumeric( true );
    $.isNumeric( undef );

lib/HTML/Object/XQuery.pod  view on Meta::CPAN

=item * "{test: 1}" (test does not have double quotes around it).

=item * "{'test': 1}" ('test' is using single quotes instead of double quotes).

=item * "'test'" ('test' is using single quotes instead of double quotes).

=item * ".1" (a number must start with a digit; "0.1" would be valid).

=item * "undefined" (undefined cannot be represented in a JSON string; null, however, can be).

=item * "NaN" (NaN cannot be represented in a JSON string; direct representation of Infinity is also not permitted).

=back

The JSON standard does not permit "control characters" such as a tab or newline. An example like C<< $.parseJSON( '{ "testing":"1\t2\n3" }' ) >> will result in an error, because the JSON parser converts the string's tab and newline escapes into liter...

For details on the JSON format, see https://json.org/.

For example:

    my $ref = $.parseJSON( '{ "name": "John" }' );

t/30.xquery.t  view on Meta::CPAN

{
    # true (numeric)
    ok( $.isNumeric( "-10" ), '-10' );
    ok( $.isNumeric( "0" ), '"0"' );
    ok( $.isNumeric( 0xFF ), '0xFF' );
    ok( $.isNumeric( "0xFF" ), '"0xFF"' );
    ok( $.isNumeric( "8e5" ), '8e5' );
    ok( $.isNumeric( "3.1415" ), '3.1415' );
    ok( $.isNumeric( +10 ), '+10' );
    ok( $.isNumeric( 0144 ), 'octal 0144' );
    ok( $.isNumeric( 'nan' ), 'NaN' );
    ok( $.isNumeric( 'inf' ), 'Infinity' );
     
    # false (non-numeric)
    ok( !$.isNumeric( "-0x42" ), '-0x42' );
    ok( !$.isNumeric( "7.2acdgs" ), '7.2acdgs' );
    ok( !$.isNumeric( "" ), '""' );
    ok( !$.isNumeric( {} ), '{}' );
    ok( !$.isNumeric( undef ), 'undef' );
};



( run in 0.263 second using v1.01-cache-2.11-cpan-4d50c553e7e )