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-2015 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 3     3   1715 use warnings;
  3         6  
  3         94  
6 3     3   15 use strict;
  3         5  
  3         95  
7              
8             package IOMux::File::Read;
9 3     3   13 use vars '$VERSION';
  3         6  
  3         136  
10             $VERSION = '1.00';
11              
12 3     3   13 use base 'IOMux::Handler::Read';
  3         10  
  3         822  
13              
14 3     3   16 use Log::Report 'iomux';
  3         4  
  3         15  
15 3     3   697 use Fcntl;
  3         6  
  3         997  
16 3     3   17 use File::Basename 'basename';
  3         12  
  3         980  
17              
18              
19             sub init($)
20 4     4 0 7 { my ($self, $args) = @_;
21              
22             my $file = $args->{file}
23 4 50       17 or error __x"no file to open specified in {pkg}", pkg => __PACKAGE__;
24              
25 4         14 my $flags = $args->{modeflags};
26 4 50 33     26 unless(ref $file || defined $flags)
27 4         7 { $flags = O_RDONLY|O_NONBLOCK;
28 4 50       12 $flags |= O_EXCL if $args->{exclusive};
29             }
30              
31 4         7 my $fh;
32 4 50       10 if(ref $file)
33 0         0 { $fh = $file;
34 0   0     0 $self->{IMFR_mode} = $args->{mode} || '<';
35             }
36             else
37 4 50       134 { sysopen $fh, $file, $flags
38             or fault __x"cannot open file {fn} for {pkg}"
39             , fn => $file, pkg => __PACKAGE__;
40 4         25 $self->{IMFR_mode} = $flags;
41             }
42 4         129 $args->{name} = '<'.(basename $file);
43 4         9 $args->{fh} = $fh;
44              
45 4         18 $self->SUPER::init($args);
46 4         13 $self;
47             }
48              
49              
50             sub open($$@)
51 2     2 1 5 { my ($class, $mode, $file, %args) = @_;
52 2         11 $class->new(file => $file, mode => $mode, %args);
53             }
54              
55             #-------------------
56              
57 0     0 1   sub mode() {shift->{IMFR_mode}}
58              
59             1;