blib/lib/SPOPSx/Tool/YAML.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 39 CC 1 SCAR 6.9
CC
1
Cov
0%
ruleset_factory
2.0
convert_to_yaml
2.0
convert_to_string
2.0
CRAP 2.0
1 package SPOPSx::Tool::YAML;
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '0.03';
7  
8 use YAML qw(Load Dump);
9  
10 =head1 NAME
11  
12 SPOPSx::Tool::HashField - A SPOPS extension for the storage of complex objects
13  
14 =head1 SYNOPSIS
15  
16 %conf = (
17 table_alias => {
18 # ...
19 yaml_fields => [ qw/ arguments locals results / ],
20 # ...
21 }
22 );
23  
24 =head1 DESCRIPTION
25  
26 This allows for the storage of Perl aggregate types in a database field. This uses L<YAML> to perform the marshalling and unmarshalling. This is handy because you can use third-party tools to update the stored data with relative ease and the data is readable even in other languages that have a YAML model. The data structure can be arbritraily deep.
27  
28 =cut
29  
30 # As far as I can tell from the docs, this is technically a violation of the
31 # guidelines for building rulesets. However, this is pretty much the same thing
32 # that SPOPS::Tool::DateConvert does.
33 sub ruleset_factory {
34 my ($class, $rstab) = @_;
35 push @{ $rstab->{post_fetch_action} }, \&convert_to_yaml;
36 push @{ $rstab->{pre_save_action} }, \&convert_to_string;
37 push @{ $rstab->{post_save_action} }, \&convert_to_yaml;
38 return __PACKAGE__
39 }
40  
41 # TODO Add a thingy to walk the created data structure and attempt to require
42 # any packages objects have been blessed into.
43 sub convert_to_yaml {
44 my $self = shift;
45 my @yaml_fields = @{ $self->CONFIG->{yaml_fields} };
46 for my $yaml_field (@yaml_fields) {
47 $self->{$yaml_field} = Load($self->{$yaml_field});
48 }
49  
50 return 1;
51 }
52  
53 sub convert_to_string {
54 my $self = shift;
55 my @yaml_fields = @{ $self->CONFIG->{yaml_fields} };
56 for my $yaml_field (@yaml_fields) {
57 $self->{$yaml_field} = Dump($self->{$yaml_field});
58 }
59  
60 return 1;
61 }
62  
63 =head1 INSTALLATION
64  
65 Just the typical install tricks will do:
66  
67 perl Build.PL
68 ./Build
69 ./Build test
70 ./Build install
71  
72 or:
73  
74 perl Makefile.PL
75 make
76 make test
77 make install
78  
79 Take your pick.
80  
81 =head1 SEE ALSO
82  
83 L<SPOPS>, L<YAML>
84  
85 =head1 AUTHOR
86  
87 Andrew Sterling Hanenkamp, E<lt>hanenkamp@users.sourceforge.netE<gt>
88  
89 =head1 COPYRIGHT AND LICENSE
90  
91 Copyright 2005 Andrew Sterling Hanenkamp. All Rights Reserved.
92  
93 Contentment is distributed and licensed under the same terms as Perl itself.
94  
95 =cut
96  
97 1