Commit | Line | Data |
6f0912d0 |
1 | package MooseX::Storage::Format::YAML; |
2 | use Moose::Role; |
3 | |
ea189007 |
4 | # When I add YAML::LibYAML |
5 | # Tests break because tye YAML is invalid...? |
6 | # -dcp |
7 | |
18d8a642 |
8 | use YAML::Any qw(Load Dump); |
6f0912d0 |
9 | |
08d0f48e |
10 | our $VERSION = '0.29'; |
69b45b7d |
11 | our $AUTHORITY = 'cpan:STEVAN'; |
7b428d1f |
12 | |
6f0912d0 |
13 | requires 'pack'; |
14 | requires 'unpack'; |
15 | |
16 | sub thaw { |
ea189007 |
17 | my ( $class, $yaml, @args ) = @_; |
18 | $class->unpack( Load($yaml), @args ); |
6f0912d0 |
19 | } |
20 | |
21 | sub freeze { |
98ae09f0 |
22 | my ( $self, @args ) = @_; |
23 | Dump( $self->pack(@args) ); |
6f0912d0 |
24 | } |
25 | |
f82612bc |
26 | no Moose::Role; |
27 | |
6f0912d0 |
28 | 1; |
29 | |
30 | __END__ |
31 | |
32 | =pod |
33 | |
34 | =head1 NAME |
35 | |
4fa64e86 |
36 | MooseX::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 |
93 | All complex software has bugs lurking in it, and this module is no |
6f0912d0 |
94 | exception. If you find a bug please either email me, or add the bug |
95 | to cpan-RT. |
96 | |
97 | =head1 AUTHOR |
98 | |
99 | Chris Prather E<lt>chris.prather@iinteractive.comE<gt> |
100 | |
101 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
102 | |
103 | =head1 COPYRIGHT AND LICENSE |
104 | |
1f3074ea |
105 | Copyright 2007-2008 by Infinity Interactive, Inc. |
6f0912d0 |
106 | |
107 | L<http://www.iinteractive.com> |
108 | |
109 | This library is free software; you can redistribute it and/or modify |
110 | it under the same terms as Perl itself. |
111 | |
112 | =cut |
113 | |
114 | |