1 # $Id: Number.pm 785 2009-07-16 14:17:46Z pajas $
3 # This is free software, you may use it and distribute it under the same terms as
6 # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
10 package XML::LibXML::Number;
11 use XML::LibXML::Boolean;
12 use XML::LibXML::Literal;
15 use vars qw ($VERSION);
16 $VERSION = "1.70"; # VERSION TEMPLATE: DO NOT CHANGE
26 if ($number !~ /^\s*(-\s*)?(\d+(\.\d*)?|\.\d+)\s*$/) {
32 bless \$number, $class;
37 defined $$self ? $$self : 'NaN';
42 return "<Number>" . (defined($$self) ? $$self : 'NaN') . "</Number>\n";
52 my ($other, $swap) = @_;
54 return $other <=> $$self;
56 return $$self <=> $other;
66 return $$self ? XML::LibXML::Boolean->True : XML::LibXML::Boolean->False;
69 sub to_literal { XML::LibXML::Literal->new($_[0]->as_string); }
70 sub to_number { $_[0]; }
72 sub string_value { return $_[0]->value }
79 XML::LibXML::Number - Simple numeric values.
83 This class holds simple numeric values. It doesn't support -0, +/- Infinity,
84 or NaN, as the XPath spec says it should, but I'm not hurting anyone I don't think.
90 Creates a new XML::LibXML::Number object, with the value in $num. Does some
91 rudimentary numeric checking on $num to ensure it actually is a number.
95 Also as overloaded stringification. Returns the numeric value held.