Oryx::Value::Float - Values containing floating-point data


Oryx documentation Contained in the Oryx distribution.

Index


Code Index:

NAME

Top

Oryx::Value::Float - Values containing floating-point data

SYNOPSIS

Top

  package CMS::LedgerEntry;

  use base qw( Oryx::Class );

  our $schema = {
      attributes => [ {
          name => 'summary',
          type => 'String',
      }, {
          name => 'amount',
          type => 'Float',
      } ],
  };

  $x = CMS::Picture->create({
      summary => 'New PDA',
      amount  => 342.17,
  });

DESCRIPTION

Top

This value stores floating-point data. It has an optional field called "precision" that can be used to set how many decimal places should be stored in the database.

This value type is checked to see that it is in fact a decimal number and is stored with the "Float" primitive type.

SEE ALSO

Top

Oryx::Value

AUTHOR

Top

Richard Hundt <richard NO SPAM AT protea-systems.com>

COPYRIGHT AND LICENSE

Top


Oryx documentation Contained in the Oryx distribution.

package Oryx::Value::Float;
use base qw(Oryx::Value);

use Data::Types qw(is_float to_float);

sub primitive { 'Float' }

sub check_type {
    my ($self, $value) = @_;
    return is_float($value);
}

sub check_size {
    my ($self, $value) = @_;
    my $p = $self->meta->getMetaAttribute("precision");
    if (defined $p) {
	my $rx = '^\d+\.\d{0,'.$p.'}$';
	return $value =~ /$rx/;
    }
    return 1;
}

1;
__END__