Commit | Line | Data |
---|---|---|
e64b7302 | 1 | package MooseX::Storage::IO::AtomicFile; |
2 | use Moose::Role; | |
3 | ||
4 | use MooseX::Storage::Engine::IO::AtomicFile; | |
5 | ||
6 | with 'MooseX::Storage::IO::File'; | |
7 | ||
8 | sub store { | |
bf33d7c7 | 9 | my ( $self, $filename, @args ) = @_; |
10 | MooseX::Storage::Engine::IO::AtomicFile->new( file => $filename )->store( $self->freeze(@args) ); | |
e64b7302 | 11 | } |
12 | ||
f82612bc | 13 | no Moose::Role; |
14 | ||
e64b7302 | 15 | 1; |
16 | ||
17 | __END__ | |
18 | ||
19 | =pod | |
20 | ||
21 | =head1 NAME | |
22 | ||
4fa64e86 | 23 | MooseX::Storage::IO::AtomicFile - An Atomic File I/O role |
e64b7302 | 24 | |
25 | =head1 SYNOPSIS | |
26 | ||
b477f392 | 27 | package Point; |
28 | use Moose; | |
29 | use MooseX::Storage; | |
ec725183 | 30 | |
b477f392 | 31 | with Storage('format' => 'JSON', 'io' => 'AtomicFile'); |
ec725183 | 32 | |
b477f392 | 33 | has 'x' => (is => 'rw', isa => 'Int'); |
34 | has 'y' => (is => 'rw', isa => 'Int'); | |
ec725183 | 35 | |
b477f392 | 36 | 1; |
ec725183 | 37 | |
b477f392 | 38 | my $p = Point->new(x => 10, y => 10); |
ec725183 | 39 | |
40 | ## methods to load/store a class | |
b477f392 | 41 | ## on the file system |
ec725183 | 42 | |
b477f392 | 43 | $p->store('my_point.json'); |
ec725183 | 44 | |
b477f392 | 45 | my $p2 = Point->load('my_point.json'); |
e64b7302 | 46 | |
47 | =head1 METHODS | |
48 | ||
49 | =over 4 | |
50 | ||
51 | =item B<load ($filename)> | |
52 | ||
53 | =item B<store ($filename)> | |
54 | ||
55 | =back | |
56 | ||
57 | =head2 Introspection | |
58 | ||
59 | =over 4 | |
60 | ||
61 | =item B<meta> | |
62 | ||
63 | =back | |
64 | ||
65 | =head1 BUGS | |
66 | ||
ec725183 | 67 | All complex software has bugs lurking in it, and this module is no |
e64b7302 | 68 | exception. If you find a bug please either email me, or add the bug |
69 | to cpan-RT. | |
70 | ||
71 | =head1 AUTHOR | |
72 | ||
73 | Chris Prather E<lt>chris.prather@iinteractive.comE<gt> | |
74 | ||
75 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> | |
76 | ||
77 | =head1 COPYRIGHT AND LICENSE | |
78 | ||
1f3074ea | 79 | Copyright 2007-2008 by Infinity Interactive, Inc. |
e64b7302 | 80 | |
81 | L<http://www.iinteractive.com> | |
82 | ||
83 | This library is free software; you can redistribute it and/or modify | |
84 | it under the same terms as Perl itself. | |
85 | ||
86 | =cut | |
87 | ||
88 |