File Coverage

blib/lib/AnyData2/Storage/FileSystem.pm
Criterion Covered Total %
statement 25 31 80.6
branch 1 6 16.6
condition 0 3 0.0
subroutine 8 10 80.0
pod 4 4 100.0
total 38 54 70.3


line stmt bran cond sub pod time code
1             package AnyData2::Storage::FileSystem;
2              
3 2     2   1231 use 5.008001;
  2         4  
4 2     2   6 use strict;
  2         2  
  2         39  
5 2     2   6 use warnings FATAL => 'all';
  2         2  
  2         55  
6              
7 2     2   5 use base qw(AnyData2::Storage);
  2         12  
  2         358  
8              
9 2     2   8 use Carp qw/croak/;
  2         1  
  2         68  
10 2     2   767 use IO::Dir ();
  2         20237  
  2         361  
11              
12             =head1 NAME
13              
14             AnyData2::Storage::FileSystem - AnyData2 filesystem storage ...
15              
16             =cut
17              
18             our $VERSION = '0.002';
19              
20             =head1 METHODS
21              
22             =head2 new
23              
24             constructs a storage reading entries from filesystem
25              
26             =cut
27              
28             sub new
29             {
30 1     1 1 2 my ( $class, %options ) = @_;
31 1         5 my $self = $class->SUPER::new();
32 1 50       4 $self->{dirh} = IO::Dir->new( $options{dirname} ) or die "Can't open $options{dirname}";
33 1         70 @$self{qw(dirname)} = @options{qw(dirname)};
34 1         3 $self;
35             }
36              
37             =head2 read
38              
39             my $entry = $stor->read
40              
41             Use binmode for characters as synonymous for bytes.
42              
43             =cut
44              
45             sub read
46             {
47 5     5 1 4 my $self = shift;
48 5         7 my $entry = $self->{dirh}->read;
49 5         34 $entry;
50             }
51              
52             =head2 seek
53              
54             $stor->seek(0,SEEK_SET)
55              
56             Sets the current position to the beginning of the directory (this,
57             naturally, affects read only).
58              
59             =cut
60              
61             sub seek
62             {
63 0     0 1   my ( $self, $pos, $whence ) = @_;
64 0 0 0       $pos == 0 and $whence == 0 and return $self->{dirh}->rewind;
65 0           croak "Unsupported combination of POS and WHENCE";
66             }
67              
68             =head2 meta
69              
70             Experimental
71              
72             Returns a meta storage - if any. Imaging it as an object dealing with
73             underlying filesystem for a file storage.
74              
75             =cut
76              
77             sub meta
78             {
79 0     0 1   my $self = shift;
80 0 0         $self->{meta} or $self->{meta} = AnyData2::Storage::FileSystem->new( dirname => dirname( $self->{dirname} ) );
81 0           $self->{meta};
82             }
83              
84             =head1 LICENSE AND COPYRIGHT
85              
86             Copyright 2015,2016 Jens Rehsack.
87              
88             This program is free software; you can redistribute it and/or modify it
89             under the terms of either: the GNU General Public License as published
90             by the Free Software Foundation; or the Artistic License.
91              
92             See http://dev.perl.org/licenses/ for more information.
93              
94             If your Modified Version has been derived from a Modified Version made
95             by someone other than you, you are nevertheless required to ensure that
96             your Modified Version complies with the requirements of this license.
97              
98             This license does not grant you the right to use any trademark, service
99             mark, tradename, or logo of the Copyright Holder.
100              
101             This license includes the non-exclusive, worldwide, free-of-charge
102             patent license to make, have made, use, offer to sell, sell, import and
103             otherwise transfer the Package with respect to any patent claims
104             licensable by the Copyright Holder that are necessarily infringed by the
105             Package. If you institute patent litigation (including a cross-claim or
106             counterclaim) against any party alleging that the Package constitutes
107             direct or contributory patent infringement, then this License
108             to you shall terminate on the date that such litigation is filed.
109              
110             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
111             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
112             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
113             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
114             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
115             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
116             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
117             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118              
119             =cut
120              
121             1;