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