Simple/Type/Property.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 78 CC 3 SCAR 14.2
CC
3
Cov
0%
new
12.0
name
2.0
auto_created
2.0
CRAP 4.1
1 package Repository::Simple::Type::Property;
2  
3 use strict;
4 use warnings;
5  
6 use Carp;
7  
8 our $VERSION = '0.06';
9  
10 use Repository::Simple::Type::Value::Scalar;
11 use Repository::Simple::Util;
12 use Scalar::Util qw( weaken );
13  
14 our @CARP_NOT = qw( Repository::Simple::Util );
15  
16 =head1 NAME
17  
18 Repository::Simple::Type::Property - Types for repository properties
19  
20 =head1 SYNOPSIS
21  
22 See L<Repository::Simple::Type::Node/"SYNOPSIS">.
23  
24 =head1 DESCRIPTION
25  
26 Property types are used to determine information about what kind of information is acceptable for a property and how it may be updated. This class provides a flexible way of describing the possible values, a method for marshalling and unmarshalling those values to and from a scalar for storage, and other metadata about possible values.
27  
28 =head2 METHODS
29  
30 =over
31  
32 =item $type = Repository::Simple::Type::Property-E<gt>new(%args)
33  
34 Creates a new property type with the given arguments, C<%args>.
35  
36 The following arguments are used:
37  
38 =over
39  
40 =item engine (required)
41  
42 This is a reference to the storage engine owning this property type.
43  
44 =item name (required)
45  
46 This is a short identifying name for the type. This should be a fully qualified name, e.g., "ns:name".
47  
48 =item auto_created
49  
50 This property should be set to true if the creation of a node containing a property of this type triggers the creation of a property of this type.
51  
52 By default, this value is false.
53  
54 =item updatable
55  
56 This property should be set to true if the value stored in the property cannot be changed.
57  
58 By default, this value is false.
59  
60 =item removable
61  
62 When this property is set to a true value, this property may not be set to C<undef> or deleted.
63  
64 By default, this value is false.
65  
66 =item value_type
67  
68 This property should be set to an instance of L<Repository::Simple::Type::Value> for the type of value that is stored in it.
69  
70 By default, this is set to an instance of L<Repository::Simple::Type::Value::Scalar>.
71  
72 =back
73  
74 =cut
75  
76 sub new {
77 my $class = shift;
78 my %args = @_;
79  
80 if (!defined $args{engine}) {
81 croak 'The "engine" argument must be given.';
82 }
83  
84 weaken $args{engine};
85  
86 if (!defined $args{name}) {
87 croak 'The "name" argument must be given.';
88 }
89  
90 $args{auto_created} ||= 0;
91 $args{updatable} ||= 0;
92 $args{removable} ||= 0;
93 $args{value_type} ||= Repository::Simple::Type::Value::Scalar->new;
94  
95 return bless \%args, $class;
96 }
97  
98 =item $name = $type-E<gt>name
99  
100 This method returns the name of the type.
101  
102 =cut
103  
104 sub name {
105 my $self = shift;
106 return $self->{name};
107 }
108  
109 =item $auto_created = $type-E<gt>auto_created
110  
111 Returns a true value if the property is automatically created with the parent.
112  
113 =cut
114  
115 sub auto_created {
116 my $self = shift;
117 return $self->{auto_created};
118 }
119  
120 =item $updatable = $type-E<gt>updatable
121  
122 Returns a true value if the value may be changed.
123  
124 =cut
125  
126 sub updatable {
127 my $self = shift;
128 return $self->{updatable};
129 }
130  
131 =item $removable = $type-E<gt>removable
132  
133 Returns a true value if the value may be removed from it's parent node.
134  
135 =cut
136  
137 sub removable {
138 my $self = shift;
139 return $self->{removable};
140 }
141  
142 =item $value_type = $type-E<gt>value_type
143  
144 Returns the value type of the properties value.
145  
146 =cut
147  
148 sub value_type {
149 my $self = shift;
150 return $self->{value_type};
151 }
152  
153 =back
154  
155 =head1 AUTHOR
156  
157 Andrew Sterling Hanenkamp, E<lt>hanenkamp@cpan.orgE<gt>
158  
159 =head1 LICENSE AND COPYRIGHT
160  
161 Copyright 2005 Andrew Sterling Hanenkamp E<lt>hanenkamp@cpan.orgE<gt>. All
162 Rights Reserved.
163  
164 This module is free software; you can redistribute it and/or modify it under
165 the same terms as Perl itself. See L<perlartistic>.
166  
167 This program is distributed in the hope that it will be useful, but WITHOUT
168 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
169 FOR A PARTICULAR PURPOSE.
170  
171 =cut
172  
173 1