File Coverage

lib/IOMux/File/Read.pm
Criterion Covered Total %
statement 37 40 92.5
branch 5 10 50.0
condition 1 5 20.0
subroutine 9 10 90.0
pod 2 3 66.6
total 54 68 79.4


line stmt bran cond sub pod time code
1             # Copyrights 2011-2020 by [Mark Overmeer ].
2             # For other contributors see ChangeLog.
3             # See the manual pages for details on the licensing terms.
4             # Pod stripped from pm file by OODoc 2.02.
5             # This code is part of distribution IOMux. Meta-POD processed with OODoc
6             # into POD and HTML manual-pages. See README.md
7             # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8              
9             package IOMux::File::Read;
10 3     3   1682 use vars '$VERSION';
  3         5  
  3         152  
11             $VERSION = '1.01';
12              
13 3     3   16 use base 'IOMux::Handler::Read';
  3         26  
  3         820  
14              
15 3     3   18 use warnings;
  3         5  
  3         64  
16 3     3   12 use strict;
  3         5  
  3         57  
17              
18 3     3   11 use Log::Report 'iomux';
  3         5  
  3         10  
19 3     3   701 use Fcntl;
  3         6  
  3         597  
20 3     3   20 use File::Basename 'basename';
  3         4  
  3         914  
21              
22              
23             sub init($)
24 4     4 0 7 { my ($self, $args) = @_;
25              
26             my $file = $args->{file}
27 4 50       12 or error __x"no file to open specified in {pkg}", pkg => __PACKAGE__;
28              
29 4         7 my $flags = $args->{modeflags};
30 4 50 33     35 unless(ref $file || defined $flags)
31 4         8 { $flags = O_RDONLY|O_NONBLOCK;
32 4 50       10 $flags |= O_EXCL if $args->{exclusive};
33             }
34              
35 4         5 my $fh;
36 4 50       10 if(ref $file)
37 0         0 { $fh = $file;
38 0   0     0 $self->{IMFR_mode} = $args->{mode} || '<';
39             }
40             else
41 4 50       147 { sysopen $fh, $file, $flags
42             or fault __x"cannot open file {fn} for {pkg}"
43             , fn => $file, pkg => __PACKAGE__;
44 4         30 $self->{IMFR_mode} = $flags;
45             }
46 4         126 $args->{name} = '<'.(basename $file);
47 4         9 $args->{fh} = $fh;
48              
49 4         19 $self->SUPER::init($args);
50 4         14 $self;
51             }
52              
53              
54             sub open($$@)
55 2     2 1 5 { my ($class, $mode, $file, %args) = @_;
56 2         7 $class->new(file => $file, mode => $mode, %args);
57             }
58              
59             #-------------------
60              
61 0     0 1   sub mode() {shift->{IMFR_mode}}
62              
63             1;