[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-unattended/var/se3/unattended/install/linuxaux/opt/perl/lib/site_perl/5.10.0/XML/XPath/ -> Number.pm (source)

   1  # $Id: Number.pm,v 1.14 2002/12/26 17:57:09 matt Exp $
   2  
   3  package XML::XPath::Number;
   4  use XML::XPath::Boolean;
   5  use XML::XPath::Literal;
   6  use strict;
   7  
   8  use overload
   9          '""' => \&value,
  10          '0+' => \&value,
  11          '<=>' => \&cmp;
  12  
  13  sub new {
  14      my $class = shift;
  15      my $number = shift;
  16      if ($number !~ /^\s*[+-]?(\d+(\.\d*)?|\.\d+)\s*$/) {
  17          $number = undef;
  18      }
  19      else {
  20          $number =~ s/^\s*(.*)\s*$/$1/;
  21      }
  22      bless \$number, $class;
  23  }
  24  
  25  sub as_string {
  26      my $self = shift;
  27      defined $$self ? $$self : 'NaN';
  28  }
  29  
  30  sub as_xml {
  31      my $self = shift;
  32      return "<Number>" . (defined($$self) ? $$self : 'NaN') . "</Number>\n";
  33  }
  34  
  35  sub value {
  36      my $self = shift;
  37      $$self;
  38  }
  39  
  40  sub cmp {
  41      my $self = shift;
  42      my ($other, $swap) = @_;
  43      if ($swap) {
  44          return $other <=> $$self;
  45      }
  46      return $$self <=> $other;
  47  }
  48  
  49  sub evaluate {
  50      my $self = shift;
  51      $self;
  52  }
  53  
  54  sub to_boolean {
  55      my $self = shift;
  56      return $$self ? XML::XPath::Boolean->True : XML::XPath::Boolean->False;
  57  }
  58  
  59  sub to_literal { XML::XPath::Literal->new($_[0]->as_string); }
  60  sub to_number { $_[0]; }
  61  
  62  sub string_value { return $_[0]->value }
  63  
  64  1;
  65  __END__
  66  
  67  =head1 NAME
  68  
  69  XML::XPath::Number - Simple numeric values.
  70  
  71  =head1 DESCRIPTION
  72  
  73  This class holds simple numeric values. It doesn't support -0, +/- Infinity,
  74  or NaN, as the XPath spec says it should, but I'm not hurting anyone I don't think.
  75  
  76  =head1 API
  77  
  78  =head2 new($num)
  79  
  80  Creates a new XML::XPath::Number object, with the value in $num. Does some
  81  rudimentary numeric checking on $num to ensure it actually is a number.
  82  
  83  =head2 value()
  84  
  85  Also as overloaded stringification. Returns the numeric value held.
  86  
  87  =cut


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1