Commit | Line | Data |
6f0912d0 |
1 | |
2 | package MooseX::Storage::Format::YAML; |
3 | use Moose::Role; |
4 | |
5 | use Best [ |
6 | [ qw[YAML::Syck YAML] ], |
7 | [ qw[Load Dump] ] |
8 | ]; |
9 | |
10 | requires 'pack'; |
11 | requires 'unpack'; |
12 | |
13 | sub thaw { |
14 | my ( $class, $json ) = @_; |
15 | $class->unpack( Load($json) ); |
16 | } |
17 | |
18 | sub freeze { |
19 | my $self = shift; |
20 | Dump( $self->pack() ); |
21 | } |
22 | |
23 | 1; |
24 | |
25 | __END__ |
26 | |
27 | =pod |
28 | |
29 | =head1 NAME |
30 | |
31 | MooseX::Storage::Format::YAML |
32 | |
33 | =head1 SYNOPSIS |
34 | |
1390c23d |
35 | package Point; |
36 | use Moose; |
37 | use MooseX::Storage; |
38 | |
39 | with Storage('format' => 'YAML'); |
40 | |
41 | has 'x' => (is => 'rw', isa => 'Int'); |
42 | has 'y' => (is => 'rw', isa => 'Int'); |
43 | |
44 | 1; |
45 | |
46 | my $p = Point->new(x => 10, y => 10); |
47 | |
48 | ## methods to freeze/thaw into |
49 | ## a specified serialization format |
50 | ## (in this case YAML) |
51 | |
52 | # pack the class into a YAML string |
53 | $p->freeze(); |
54 | |
55 | # ---- |
56 | # __CLASS__: "Point" |
57 | # x: 10 |
58 | # y: 10 |
59 | |
60 | # unpack the JSON string into a class |
61 | my $p2 = Point->thaw(<<YAML); |
62 | ---- |
63 | __CLASS__: "Point" |
64 | x: 10 |
65 | y: 10 |
66 | YAML |
67 | |
6f0912d0 |
68 | =head1 DESCRIPTION |
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 | |
90 | All complex software has bugs lurking in it, and this module is no |
91 | exception. If you find a bug please either email me, or add the bug |
92 | to cpan-RT. |
93 | |
94 | =head1 AUTHOR |
95 | |
96 | Chris Prather E<lt>chris.prather@iinteractive.comE<gt> |
97 | |
98 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
99 | |
100 | =head1 COPYRIGHT AND LICENSE |
101 | |
102 | Copyright 2007 by Infinity Interactive, Inc. |
103 | |
104 | L<http://www.iinteractive.com> |
105 | |
106 | This library is free software; you can redistribute it and/or modify |
107 | it under the same terms as Perl itself. |
108 | |
109 | =cut |
110 | |
111 | |