| 1 | #----------------------------------------------------------------- | ||
| 2 | # MOSES::MOBY::Data::Integer | ||
| 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: Integer.pm,v 1.4 2008/04/29 19:35:57 kawas Exp $ | ||
| 8 | #----------------------------------------------------------------- | ||
| 9 | |||
| 10 | package MOSES::MOBY::Data::Integer; | ||
| 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::Integer - A primite Moby data type for integers | ||
| 21 | |||
| 22 | =head1 SYNOPSIS | ||
| 23 | |||
| 24 | use MOSES::MOBY::Data::Integer; | ||
| 25 | |||
| 26 | # create a Moby Integer with initial value of -15 | ||
| 27 | my $data = MOSES::MOBY::Data::Integer->new (value => -15); | ||
| 28 | |||
| 29 | # set/get the value of this data object | ||
| 30 | $data->value (79); | ||
| 31 | print $data->value(); | ||
| 32 | |||
| 33 | =head1 DESCRIPTION | ||
| 34 | |||
| 35 | An object representing an Integer, a Moby primitive data type. | ||
| 36 | |||
| 37 | =head1 AUTHORS | ||
| 38 | |||
| 39 | Edward Kawas (edward.kawas [at] gmail [dot] com) | ||
| 40 | Martin Senger (martin.senger [at] gmail [dot] com) | ||
| 41 | |||
| 42 | =cut | ||
| 43 | |||
| 44 | #----------------------------------------------------------------- | ||
| 45 | # A list of allowed attribute names. See MOSES::MOBY::Base for details. | ||
| 46 | #----------------------------------------------------------------- | ||
| 47 | |||
| 48 | =head1 ACCESSIBLE ATTRIBUTES | ||
| 49 | |||
| 50 | Details are in L<MOSES::MOBY::Base>. Here just a list of them (additionally | ||
| 51 | to the attributes from the parent classes) | ||
| 52 | |||
| 53 | =over | ||
| 54 | |||
| 55 | =item B<value> | ||
| 56 | |||
| 57 | A value of this datatype. Must be an integer. | ||
| 58 | |||
| 59 | =back | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | { | ||
| 64 | my %_allowed = | ||
| 65 | ( | ||
| 66 | value => {type => MOSES::MOBY::Base->INTEGER}, | ||
| 67 | ); | ||
| 68 | |||
| 69 | sub _accessible { | ||
| 70 | my ($self, $attr) = @_; | ||
| 71 | exists $_allowed{$attr} or $self->SUPER::_accessible ($attr); | ||
| 72 | } | ||
| 73 | sub _attr_prop { | ||
| 74 | my ($self, $attr_name, $prop_name) = @_; | ||
| 75 | my $attr = $_allowed {$attr_name}; | ||
| 76 | return ref ($attr) ? $attr->{$prop_name} : $attr if $attr; | ||
| 77 | return $self->SUPER::_attr_prop ($attr_name, $prop_name); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | #----------------------------------------------------------------- | ||
| 82 | # init | ||
| 83 | #----------------------------------------------------------------- | ||
| 84 | sub init { | ||
| 85 | my ($self) = shift; | ||
| 86 | $self->SUPER::init(); | ||
| 87 | $self->primitive ('yes'); | ||
| 88 | } | ||
| 89 | |||
| 90 | 1; | ||
| 91 | __END__ |