c9bbcf972b0a77f99c10b82a7a9ba9d2ddf202d3
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Format / YAML.pm
1 package MooseX::Storage::Format::YAML;
2 use Moose::Role;
3
4 # When I add YAML::LibYAML
5 # Tests break because tye YAML is invalid...?
6 # -dcp
7
8 use Best [
9     [ qw[YAML::Syck YAML] ],
10     [ qw[Load Dump] ]
11 ];
12
13 our $VERSION   = '0.22';
14 our $AUTHORITY = 'cpan:STEVAN';
15
16 requires 'pack';
17 requires 'unpack';
18
19 sub thaw {
20     my ( $class, $yaml, @args ) = @_;
21     $class->unpack( Load($yaml), @args );
22 }
23
24 sub freeze {
25     my ( $self, @args ) = @_;
26     Dump( $self->pack(@args) );
27 }
28
29 no Moose::Role;
30
31 1;
32
33 __END__
34
35 =pod
36
37 =head1 NAME
38
39 MooseX::Storage::Format::YAML - A YAML serialization role
40
41 =head1 SYNOPSIS
42
43   package Point;
44   use Moose;
45   use MooseX::Storage;
46
47   with Storage('format' => 'YAML');
48
49   has 'x' => (is => 'rw', isa => 'Int');
50   has 'y' => (is => 'rw', isa => 'Int');
51
52   1;
53
54   my $p = Point->new(x => 10, y => 10);
55
56   ## methods to freeze/thaw into
57   ## a specified serialization format
58   ## (in this case YAML)
59
60   # pack the class into a YAML string
61   $p->freeze();
62
63   # ----
64   # __CLASS__: "Point"
65   # x: 10
66   # y: 10
67
68   # unpack the JSON string into a class
69   my $p2 = Point->thaw(<<YAML);
70   ----
71   __CLASS__: "Point"
72   x: 10
73   y: 10
74   YAML
75
76 =head1 METHODS
77
78 =over 4
79
80 =item B<freeze>
81
82 =item B<thaw ($yaml)>
83
84 =back
85
86 =head2 Introspection
87
88 =over 4
89
90 =item B<meta>
91
92 =back
93
94 =head1 BUGS
95
96 All complex software has bugs lurking in it, and this module is no
97 exception. If you find a bug please either email me, or add the bug
98 to cpan-RT.
99
100 =head1 AUTHOR
101
102 Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
103
104 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
105
106 =head1 COPYRIGHT AND LICENSE
107
108 Copyright 2007-2008 by Infinity Interactive, Inc.
109
110 L<http://www.iinteractive.com>
111
112 This library is free software; you can redistribute it and/or modify
113 it under the same terms as Perl itself.
114
115 =cut
116
117