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