lib/MOSES/MOBY/Data/Boolean.pm untested

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