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