line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Storage::Format::YAML; |
2
|
|
|
|
|
|
|
# ABSTRACT: A YAML serialization role |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.52'; |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2339
|
use Moose::Role; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
32
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# When I add YAML::LibYAML |
9
|
|
|
|
|
|
|
# Tests break because tye YAML is invalid...? |
10
|
|
|
|
|
|
|
# -dcp |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
16959
|
use YAML::Any qw(Load Dump); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
36
|
|
13
|
4
|
|
|
4
|
|
842
|
use namespace::autoclean; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
33
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
requires 'pack'; |
16
|
|
|
|
|
|
|
requires 'unpack'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub thaw { |
19
|
4
|
|
|
4
|
1
|
15128
|
my ( $class, $yaml, @args ) = @_; |
20
|
4
|
|
|
|
|
24
|
$class->unpack( Load($yaml), @args ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub freeze { |
24
|
4
|
|
|
4
|
1
|
20178
|
my ( $self, @args ) = @_; |
25
|
4
|
|
|
|
|
31
|
Dump( $self->pack(@args) ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
4
|
|
638
|
no Moose::Role; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
30
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__END__ |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=pod |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=encoding UTF-8 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
MooseX::Storage::Format::YAML - A YAML serialization role |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 VERSION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
version 0.52 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
package Point; |
49
|
|
|
|
|
|
|
use Moose; |
50
|
|
|
|
|
|
|
use MooseX::Storage; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
with Storage('format' => 'YAML'); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has 'x' => (is => 'rw', isa => 'Int'); |
55
|
|
|
|
|
|
|
has 'y' => (is => 'rw', isa => 'Int'); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $p = Point->new(x => 10, y => 10); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
## methods to freeze/thaw into |
62
|
|
|
|
|
|
|
## a specified serialization format |
63
|
|
|
|
|
|
|
## (in this case YAML) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# pack the class into a YAML string |
66
|
|
|
|
|
|
|
$p->freeze(); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# ---- |
69
|
|
|
|
|
|
|
# __CLASS__: "Point" |
70
|
|
|
|
|
|
|
# x: 10 |
71
|
|
|
|
|
|
|
# y: 10 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# unpack the JSON string into a class |
74
|
|
|
|
|
|
|
my $p2 = Point->thaw(<<YAML); |
75
|
|
|
|
|
|
|
---- |
76
|
|
|
|
|
|
|
__CLASS__: "Point" |
77
|
|
|
|
|
|
|
x: 10 |
78
|
|
|
|
|
|
|
y: 10 |
79
|
|
|
|
|
|
|
YAML |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 METHODS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over 4 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item B<freeze> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item B<thaw ($yaml)> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SUPPORT |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Storage> |
94
|
|
|
|
|
|
|
(or L<bug-MooseX-Storage@rt.cpan.org|mailto:bug-MooseX-Storage@rt.cpan.org>). |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
97
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
100
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHORS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Chris Prather <chris.prather@iinteractive.com> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Stevan Little <stevan.little@iinteractive.com> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
×××× ×§××'×× (Yuval Kogman) <nothingmuch@woobling.org> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=back |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Infinity Interactive, Inc. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
125
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |