1package MooseX::Storage::Engine::IO::File;
2# ABSTRACT: The actual file storage mechanism.
3
4our $VERSION = '0.53';
5
6use Moose;
7use IO::File;
8use Carp 'confess';
9use namespace::autoclean;
10
11has 'file' => (
12    is       => 'ro',
13    isa      => 'Str',
14    required => 1,
15);
16
17sub load {
18    my ($self) = @_;
19    my $fh = IO::File->new($self->file, 'r')
20        || confess "Unable to open file (" . $self->file . ") for loading : $!";
21    return do { local $/; <$fh>; };
22}
23
24sub store {
25    my ($self, $data) = @_;
26    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    $fh->binmode(':utf8') if utf8::is_utf8($data);
31    print $fh $data;
32}
33
341;
35
36__END__
37
38=pod
39
40=encoding UTF-8
41
42=head1 NAME
43
44MooseX::Storage::Engine::IO::File - The actual file storage mechanism.
45
46=head1 VERSION
47
48version 0.53
49
50=head1 DESCRIPTION
51
52This 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
68Bugs 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
71There is also a mailing list available for users of this distribution, at
72L<http://lists.perl.org/list/moose.html>.
73
74There is also an irc channel available for users of this distribution, at
75L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
76
77=head1 AUTHORS
78
79=over 4
80
81=item *
82
83Chris Prather <chris.prather@iinteractive.com>
84
85=item *
86
87Stevan 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
97This software is copyright (c) 2007 by Infinity Interactive, Inc.
98
99This is free software; you can redistribute it and/or modify it under
100the same terms as the Perl 5 programming language system itself.
101
102=cut
103