The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Persistent::DataType::Number - A Floating Point and Integer Class

SYNOPSIS

  use Persistent::DataType::Number;
  use English;

  eval {  ### in case an exception is thrown ###

    ### allocate a number ###
    my $number = new Persistent::DataType::Number($value,
                                                  $precision,
                                                  $scale);

    ### get/set value of number ###
    $value = $number->value($new_value);

    ### get/set precision of the number ###
    $precision = $number->precision($new_precision);

    ### get/set scale of number ###
    $scale = $number->scale($new_scale);

    ### returns '<=>' for numbers ###
    my $cmp_op = $number->get_compare_op();
  };

  if ($EVAL_ERROR) {  ### catch those exceptions! ###
    print "An error occurred: $EVAL_ERROR\n";
  }

ABSTRACT

This is a floating point and integer class used by the Persistent framework of classes to implement the attributes of objects. This class provides methods for accessing the value, precision, scale, and comparison operator of a number.

This class is usually not invoked directly, at least not when used with the Persistent framework of classes. However, the constructor arguments of this class are usually of interest when defining the attributes of a Persistent object since the add_attribute method of the Persistent classes instantiates this class directly. Also, the arguments to the value method are of interest when dealing with the accessor methods of the Persistent classes since the accessor methods pass their arguments to the value method and return the string value from the value method.

This class is part of the Persistent base package which is available from:

  http://www.bigsnow.org/persistent
  ftp://ftp.bigsnow.org/pub/persistent

DESCRIPTION

Before we get started describing the methods in detail, it should be noted that all error handling in this class is done with exceptions. So you should wrap an eval block around all of your code. Please see the Persistent documentation for more information on exception handling in Perl.

METHODS

Constructor -- Creates the Number Object

  eval {
    my $number = new Persistent::DataType::Number($value,
                                                  $precision,
                                                  $scale);
  };
  croak "Exception caught: $@" if $@;

Initializes a number object. This method throws Perl execeptions so use it with an eval block.

Parameters:

$value

Actual value of the number; this may be a floating point or integer. This argument is optional and may be set to undef.

$precision

The number of digits in the number not including the decimal point or the sign. This argument is optional and will be initialized to the precision of the $value argument as a default.

$scale

The number of digits after the decimal point. This argument is optional and will be initialized to the scale of the $value argument as a default.

value -- Accesses the Value of the Number

  eval {
    ### set the value ###
    $number->value($value);

    ### get the value ###
    $value = $number->value();
  };
  croak "Exception caught: $@" if $@;

Sets the value of the number and/or returns the value. This method throws Perl execeptions so use it with an eval block.

Parameters:

$value

Actual value of the number; this may be a floating point or integer. This argument is optional and may be set to undef.

get_compare_op -- Returns the Comparison Operator

  $cmp_op = $number->get_compare_op();

Returns the comparison operator for the Number class which is '<=>'. This method does not throw execeptions.

Parameters:

None

precision -- Accesses the Precision of the Number

  eval {
    ### set the precision ###
    $number->precision($new_precision);

    ### get the precision ###
    $precision = $number->precision();
  };
  croak "Exception caught: $@" if $@;

Sets the precision of the number and/or returns it. This method throws Perl execeptions so use it with an eval block.

Parameters:

$precision

The number of digits in the number not including the decimal point or the sign. The precision must be >= 0. If it is undef or the empty string (''), then it is set to 0.

scale -- Accesses the Scale of the Number

  eval {
    ### set the scale ###
    $number->scale($new_scale);

    ### get the scale ###
    $scale = $number->scale();
  };
  croak "Exception caught: $@" if $@;

Sets the scale of the number and/or returns it. This method throws Perl execeptions so use it with an eval block.

Parameters:

$scale

The number of digits after the decimal point. The scale must be >= 0. If it is undef or the empty string (''), then it is set to 0.

SEE ALSO

Persistent, Persistent::DataType::Char, Persistent::DataType::DateTime, Persistent::DataType::String, Persistent::DataType::VarChar

BUGS

This software is definitely a work in progress. So if you find any bugs please email them to me with a subject of 'Persistent Bug' at:

  winters@bigsnow.org

And you know, include the regular stuff, OS, Perl version, snippet of code, etc.

AUTHORS

  David Winters <winters@bigsnow.org>

COPYRIGHT

Copyright (c) 1998-2000 David Winters. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.