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