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