skipping tests if you don't have Test::* installed
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Format / YAML.pm
CommitLineData
6f0912d0 1
2package MooseX::Storage::Format::YAML;
3use Moose::Role;
4
5use Best [
6 [ qw[YAML::Syck YAML] ],
7 [ qw[Load Dump] ]
8];
9
98ae09f0 10our $VERSION = '0.02';
7b428d1f 11
6f0912d0 12requires 'pack';
13requires 'unpack';
14
15sub thaw {
98ae09f0 16 my ( $class, $json, @args ) = @_;
17 $class->unpack( Load($json), @args );
6f0912d0 18}
19
20sub freeze {
98ae09f0 21 my ( $self, @args ) = @_;
22 Dump( $self->pack(@args) );
6f0912d0 23}
24
251;
26
27__END__
28
29=pod
30
31=head1 NAME
32
33MooseX::Storage::Format::YAML
34
35=head1 SYNOPSIS
36
1390c23d 37 package Point;
38 use Moose;
39 use MooseX::Storage;
40
41 with Storage('format' => 'YAML');
42
43 has 'x' => (is => 'rw', isa => 'Int');
44 has 'y' => (is => 'rw', isa => 'Int');
45
46 1;
47
48 my $p = Point->new(x => 10, y => 10);
49
50 ## methods to freeze/thaw into
51 ## a specified serialization format
52 ## (in this case YAML)
53
54 # pack the class into a YAML string
55 $p->freeze();
56
57 # ----
58 # __CLASS__: "Point"
59 # x: 10
60 # y: 10
61
62 # unpack the JSON string into a class
63 my $p2 = Point->thaw(<<YAML);
64 ----
65 __CLASS__: "Point"
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
90All complex software has bugs lurking in it, and this module is no
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
102Copyright 2007 by Infinity Interactive, Inc.
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