Simple/Type/Value.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 30 CC 1 SCAR 6.9
CC
1
Cov
0%
name
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Repository::Simple::Type::Value;
2  
3 use strict;
4 use warnings;
5  
6 use Readonly;
7 use Repository::Simple::Util;
8  
9 our @CARP_NOT = qw( Repository::Simple::Util );
10  
11 require Exporter;
12  
13 our @ISA = qw( Exporter );
14  
15 our $VERSION = '0.06';
16  
17 our @EXPORT_OK = qw(
18 $SCALAR_TYPE
19 $HANDLE_TYPE
20 );
21  
22 our %EXPORT_TAGS = ( type_constants => \@EXPORT_OK );
23  
24 # Type constants
25 Readonly our $SCALAR_TYPE => 'STRING';
26 Readonly our $HANDLE_TYPE => 'HANDLE';
27  
28 =head1 NAME
29  
30 Repository::Simple::Type::Value - Abstract base class for value types
31  
32 =head1 SYNOPSIS
33  
34 package Repository::Simple::Type::Value::MyValueType;
35  
36 use Repository::Simple::Type::Value qw( $STRING_TYPE );
37 use base qw( Repository::Simple::Type::Value );
38  
39 sub name {
40 return 'my:value-type';
41 }
42  
43 # Only strings starting with "Foo" are accepted
44 sub check {
45 my ($self, $value) = @_;
46 $value =~ /^Foo/
47 or die qq(Value "$value" does not start with "Foo".);
48 }
49  
50 # Since they all start with foo, deflate() strips it and inflate() adds it
51 # back in
52 sub inflate {
53 my ($self, $value) = @_;
54 $value =~ s/^/Foo/;
55 return $value;
56 }
57  
58 sub deflate {
59 my ($self, $value) = @_;
60 $value =~ s/^Foo// or die qq(Bad value "$value" stored!);
61 return $value;
62 }
63  
64 =head1 DESCRIPTION
65  
66 If you are just a casual user of L<Repository::Simple>, then the nature of this class isn't a concern. However, if you want to extend the functionality of L<Repository::Simple>, then you may be interested in this class.
67  
68 To create a value type, subclass this class and implement methods as appropriate. Below are listed the expected inputs/outputs for each method and the nature of the default implementation, if one is provided.
69  
70 =head2 REQUIRED METHODS
71  
72 =over
73  
74 =item $value_type = Repository::Simple::Type::Value-E<gt>new(@args)
75  
76 Your type should provide a well-documented constructor.
77  
78 =item $name = $value_type-E<gt>name
79  
80 This method MUST be implemented by the subclass. It should return a short string naming the class. This name should be in "ns:name" form as namespaces are an intended feature for implementation in the future.
81  
82 =cut
83  
84 sub name { die "Subclasses must implement this method." }
85  
86 =back
87  
88 =head2 OPTIONAL METHODS
89  
90 The following methods are optional. These methods allow storage engine independant features to be added to the store. However, you may need to be careful about employing them. If any of the following methods are defined for a value, the entire value will be read in from storage and passed to each. This may be undesireable if a value may storage large amounts of data.
91  
92 =over
93  
94 =item $value_type-E<gt>check($value)
95  
96 Given a scalar value, this method should throw an exception if the value is not acceptable for some reason. If the value is acceptable, the method must not throw an exception.
97  
98 If not defined, all input is considered acceptable.
99  
100 =item $inflated_value = $value_type-E<gt>inflate($deflated_value)
101  
102 Given a flat scalar value, this method may transform the value into the representation to be accessed by the end-user, and return that as a scalar (possibly a reference to a complex type).
103  
104 For example, if this type represents a L<DateTime> object, then the method will translate some string formatted date and parse it into a L<DateTime> object.
105  
106 This method will be called whenever loading the value from storage.
107  
108 =item $deflated_value = $value_type-E<gt>deflate($inflated_value)
109  
110 Given the end-user representation of this type (possibly a reference to a complex type), this method may transform the value into a scalar value for storage and return it.
111  
112 For example, if this type represents a L<DateTime> object, then the method should return a string representation of the L<DateTime> object.
113  
114 This method will be called whenever saving the value back to storage.
115  
116 =back
117  
118 =head1 AUTHOR
119  
120 Andrew Sterling Hanenkamp, E<lt>hanenkamp@cpan.orgE<gt>
121  
122 =head1 LICENSE AND COPYRIGHT
123  
124 Copyright 2006 Andrew Sterling Hanenkamp E<lt>hanenkamp@cpan.orgE<gt>. All
125 Rights Reserved.
126  
127 This module is free software; you can redistribute it and/or modify it under
128 the same terms as Perl itself. See L<perlartistic>.
129  
130 This program is distributed in the hope that it will be useful, but WITHOUT
131 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
132 FOR A PARTICULAR PURPOSE.
133  
134 =cut
135  
136 1