| 1 | #----------------------------------------------------------------- | ||
| 2 | # MOSES::MOBY::Data::Float | ||
| 3 | # Author: Edward Kawas <edward.kawas@gmail.com>, | ||
| 4 | # Martin Senger <martin.senger@gmail.com> | ||
| 5 | # For copyright and disclaimer see below. | ||
| 6 | # | ||
| 7 | # $Id: Float.pm,v 1.4 2008/04/29 19:35:57 kawas Exp $ | ||
| 8 | #----------------------------------------------------------------- | ||
| 9 | |||
| 10 | package MOSES::MOBY::Data::Float; | ||
| 11 | use base ("MOSES::MOBY::Data::Object"); | ||
| 12 | use strict; | ||
| 13 | |||
| 14 | # add versioning to this module | ||
| 15 | use vars qw /$VERSION/; | ||
| 16 | $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/; | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | MOSES::MOBY::Data::Float - A primite Moby data type for float numbers | ||
| 21 | |||
| 22 | =head1 SYNOPSIS | ||
| 23 | |||
| 24 | use MOSES::MOBY::Data::Float; | ||
| 25 | |||
| 26 | # create a Moby Float with initial value of -15.5 | ||
| 27 | my $data = MOSES::MOBY::Data::Float->new (value => -15.5); | ||
| 28 | my $data = MOSES::MOBY::Data::Float->new (-15.5); | ||
| 29 | |||
| 30 | # later change the value of this data object | ||
| 31 | $data->value (79); | ||
| 32 | print $data->value(); | ||
| 33 | |||
| 34 | =head1 DESCRIPTION | ||
| 35 | |||
| 36 | An object representing a Float, a Moby primitive data type. | ||
| 37 | |||
| 38 | =head1 AUTHORS | ||
| 39 | |||
| 40 | Edward Kawas (edward.kawas [at] gmail [dot] com) | ||
| 41 | Martin Senger (martin.senger [at] gmail [dot] com) | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | #----------------------------------------------------------------- | ||
| 46 | # A list of allowed attribute names. See MOSES::MOBY::Base for details. | ||
| 47 | #----------------------------------------------------------------- | ||
| 48 | |||
| 49 | =head1 ACCESSIBLE ATTRIBUTES | ||
| 50 | |||
| 51 | Details are in L<MOSES::MOBY::Base>. Here just a list of them (additionally | ||
| 52 | to the attributes from the parent classes) | ||
| 53 | |||
| 54 | =over | ||
| 55 | |||
| 56 | =item B<value> | ||
| 57 | |||
| 58 | A value of this datatype. Must be a floating-point number. | ||
| 59 | |||
| 60 | =back | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | { | ||
| 65 | my %_allowed = | ||
| 66 | ( | ||
| 67 | value => {type => MOSES::MOBY::Base->FLOAT}, | ||
| 68 | ); | ||
| 69 | |||
| 70 | sub _accessible { | ||
| 71 | my ($self, $attr) = @_; | ||
| 72 | exists $_allowed{$attr} or $self->SUPER::_accessible ($attr); | ||
| 73 | } | ||
| 74 | sub _attr_prop { | ||
| 75 | my ($self, $attr_name, $prop_name) = @_; | ||
| 76 | my $attr = $_allowed {$attr_name}; | ||
| 77 | return ref ($attr) ? $attr->{$prop_name} : $attr if $attr; | ||
| 78 | return $self->SUPER::_attr_prop ($attr_name, $prop_name); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | #----------------------------------------------------------------- | ||
| 83 | # init | ||
| 84 | #----------------------------------------------------------------- | ||
| 85 | sub init { | ||
| 86 | my ($self) = shift; | ||
| 87 | $self->SUPER::init(); | ||
| 88 | $self->primitive ('yes'); | ||
| 89 | } | ||
| 90 | |||
| 91 | 1; |