File Coverage

blib/lib/AnyData2/Storage/File/Blockwise.pm
Criterion Covered Total %
statement 28 33 84.8
branch 4 10 40.0
condition 1 6 16.6
subroutine 8 9 88.8
pod 3 3 100.0
total 44 61 72.1


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