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