File Coverage

lib/SMB/OpenFile.pm
Criterion Covered Total %
statement 24 34 70.5
branch 0 6 0.0
condition 3 14 21.4
subroutine 7 8 87.5
pod 3 3 100.0
total 37 65 56.9


line stmt bran cond sub pod time code
1             # SMB-Perl library, Copyright (C) 2014-2018 Mikhael Goikhman, migo@cpan.org
2             #
3             # This program is free software: you can redistribute it and/or modify
4             # it under the terms of the GNU General Public License as published by
5             # the Free Software Foundation, either version 3 of the License, or
6             # (at your option) any later version.
7             #
8             # This program is distributed in the hope that it will be useful,
9             # but WITHOUT ANY WARRANTY; without even the implied warranty of
10             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11             # GNU General Public License for more details.
12             #
13             # You should have received a copy of the GNU General Public License
14             # along with this program. If not, see .
15              
16             package SMB::OpenFile;
17              
18 3     3   16 use strict;
  3         5  
  3         64  
19 3     3   10 use warnings;
  3         4  
  3         56  
20              
21 3     3   10 use parent 'SMB';
  3         3  
  3         12  
22              
23 3     3   119 use Fcntl 'SEEK_SET';
  3         5  
  3         105  
24 3     3   359 use SMB::File;
  3         5  
  3         658  
25              
26             sub new ($$$$%) {
27 17     17 1 24 my $class = shift;
28 17   50     31 my $file = shift || die "No file\n";
29 17   50     27 my $handle = shift || 0;
30 17   50     31 my $action = shift || SMB::File::ACTION_NONE;
31 17         23 my %options = @_;
32              
33 17         55 my $self = $class->SUPER::new(
34             file => $file,
35             handle => $handle,
36             action => $action,
37             last_index => 0,
38             delete_on_close => 0,
39             %options,
40             );
41              
42 17         34 return $self;
43             }
44              
45             sub close ($) {
46 17     17 1 8147 my $self = shift;
47              
48 17         44 $self->file->delete_openfile($self);
49             }
50              
51             sub read ($%) {
52 0     0 1   my $self = shift;
53 0           my %params = @_; # length offset minlen remain
54              
55 0 0         my $fh = $self->{handle} or return '';
56 0 0 0       sysseek($fh, $params{offset} || 0, SEEK_SET) or return;
57              
58 0   0       my $length = $params{length} // return;
59 0   0       my $minlen = $params{minlen} || 0;
60              
61 0           my $buffer;
62 0   0       sysread($fh, $buffer, $length) // return;
63 0 0         return unless length($buffer) < $minlen;
64              
65 0           return $buffer;
66             }
67              
68             1;
69              
70             __END__