foo
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Engine / IO / AtomicFile.pm
CommitLineData
12145c6e 1
2package MooseX::Storage::Engine::IO::AtomicFile;
3use Moose;
4
5use IO::AtomicFile;
6
7has 'file' => (
8 is => 'ro',
9 isa => 'Str',
10 required => 1,
11);
12
13sub load {
14 my ($self) = @_;
6f0912d0 15 # NOTE:sv
12145c6e 16 # AtomicFile gives us no real
17 # benefit when reading, so why
18 # bother
19 # - SL
20 my $fh = IO::File->new($self->file, 'r');
21 return do { local $/; <$fh>; };
22}
23
24sub store {
25 my ($self, $data) = @_;
26 my $fh = IO::AtomicFile->new($self->file, 'w');
27 print $fh $data;
28 $fh->close()
29 || confess "Could not write atomic file (" . $self->file . ") because: $!";
30}
31
321;
33
34__END__
35
36=pod
37
38=head1 NAME
39
40MooseX::Storage::Engine::IO::File
41
42=head1 SYNOPSIS
43
44=head1 DESCRIPTION
45
46=head1 METHODS
47
48=over 4
49
50=item B<file>
51
52=item B<load>
53
54=item B<store ($data)>
55
56=back
57
58=head2 Introspection
59
60=over 4
61
62=item B<meta>
63
64=back
65
66=head1 BUGS
67
68All complex software has bugs lurking in it, and this module is no
69exception. If you find a bug please either email me, or add the bug
70to cpan-RT.
71
72=head1 AUTHOR
73
74Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
75
76Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
77
78=head1 COPYRIGHT AND LICENSE
79
80Copyright 2007 by Infinity Interactive, Inc.
81
82L<http://www.iinteractive.com>
83
84This library is free software; you can redistribute it and/or modify
85it under the same terms as Perl itself.
86
87=cut