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