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