Merge branch 'master' into engine_traits
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Format / YAML.pm
CommitLineData
6f0912d0 1
2package MooseX::Storage::Format::YAML;
3use Moose::Role;
4
ea189007 5# When I add YAML::LibYAML
6# Tests break because tye YAML is invalid...?
7# -dcp
8
6f0912d0 9use Best [
10 [ qw[YAML::Syck YAML] ],
11 [ qw[Load Dump] ]
12];
13
5ca52230 14our $VERSION = '0.18';
69b45b7d 15our $AUTHORITY = 'cpan:STEVAN';
7b428d1f 16
6f0912d0 17requires 'pack';
18requires 'unpack';
19
20sub thaw {
ea189007 21 my ( $class, $yaml, @args ) = @_;
22 $class->unpack( Load($yaml), @args );
6f0912d0 23}
24
25sub freeze {
98ae09f0 26 my ( $self, @args ) = @_;
27 Dump( $self->pack(@args) );
6f0912d0 28}
29
301;
31
32__END__
33
34=pod
35
36=head1 NAME
37
4fa64e86 38MooseX::Storage::Format::YAML - A YAML serialization role
6f0912d0 39
40=head1 SYNOPSIS
41
1390c23d 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
6f0912d0 74
75=head1 METHODS
76
77=over 4
78
79=item B<freeze>
80
1390c23d 81=item B<thaw ($yaml)>
6f0912d0 82
83=back
84
85=head2 Introspection
86
87=over 4
88
89=item B<meta>
90
91=back
92
93=head1 BUGS
94
95All complex software has bugs lurking in it, and this module is no
96exception. If you find a bug please either email me, or add the bug
97to cpan-RT.
98
99=head1 AUTHOR
100
101Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
102
103Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
104
105=head1 COPYRIGHT AND LICENSE
106
1f3074ea 107Copyright 2007-2008 by Infinity Interactive, Inc.
6f0912d0 108
109L<http://www.iinteractive.com>
110
111This library is free software; you can redistribute it and/or modify
112it under the same terms as Perl itself.
113
114=cut
115
116