File Coverage

blib/lib/MooseX/Storage/Engine/IO/File.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition 2 6 33.3
subroutine 6 6 100.0
pod 2 2 100.0
total 33 37 89.1


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