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