File Coverage

blib/lib/MooseX/Storage/Engine/IO/AtomicFile.pm
Criterion Covered Total %
statement 17 17 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 1 1 100.0
total 27 30 90.0


line stmt bran cond sub pod time code
1             package MooseX::Storage::Engine::IO::AtomicFile;
2             # ABSTRACT: The actual atomic file storage mechanism.
3              
4             our $VERSION = '0.52';
5              
6 3     3   11 use Moose;
  3         5  
  3         17  
7 3     3   12436 use IO::AtomicFile;
  3         5  
  3         136  
8 3     3   11 use Carp 'confess';
  3         3  
  3         119  
9 3     3   12 use namespace::autoclean;
  3         4  
  3         24  
10              
11             extends 'MooseX::Storage::Engine::IO::File';
12              
13             sub store {
14 4     4 1 8 my ($self, $data) = @_;
15 4   33     146 my $fh = IO::AtomicFile->new($self->file, 'w')
16             || confess "Unable to open file (" . $self->file . ") for storing : $!";
17              
18             # TODO ugh! this is surely wrong and should be fixed.
19 4 100       923 $fh->binmode(':utf8') if utf8::is_utf8($data);
20 4         60 print $fh $data;
21 4 50       18 $fh->close()
22             || confess "Could not write atomic file (" . $self->file . ") because: $!";
23             }
24              
25             1;
26              
27             __END__
28              
29             =pod
30              
31             =encoding UTF-8
32              
33             =head1 NAME
34              
35             MooseX::Storage::Engine::IO::AtomicFile - The actual atomic file storage mechanism.
36              
37             =head1 VERSION
38              
39             version 0.52
40              
41             =head1 DESCRIPTION
42              
43             This provides the actual means to store data to a file atomically.
44              
45             =head1 METHODS
46              
47             =over 4
48              
49             =item B<file>
50              
51             =item B<load>
52              
53             =item B<store ($data)>
54              
55             =back
56              
57             =head1 SUPPORT
58              
59             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Storage>
60             (or L<bug-MooseX-Storage@rt.cpan.org|mailto:bug-MooseX-Storage@rt.cpan.org>).
61              
62             There is also a mailing list available for users of this distribution, at
63             L<http://lists.perl.org/list/moose.html>.
64              
65             There is also an irc channel available for users of this distribution, at
66             L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
67              
68             =head1 AUTHORS
69              
70             =over 4
71              
72             =item *
73              
74             Chris Prather <chris.prather@iinteractive.com>
75              
76             =item *
77              
78             Stevan Little <stevan.little@iinteractive.com>
79              
80             =item *
81              
82             יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
83              
84             =back
85              
86             =head1 COPYRIGHT AND LICENSE
87              
88             This software is copyright (c) 2007 by Infinity Interactive, Inc.
89              
90             This is free software; you can redistribute it and/or modify it under
91             the same terms as the Perl 5 programming language system itself.
92              
93             =cut