File Coverage

blib/lib/IO/Die/read.pm
Criterion Covered Total %
statement 11 13 84.6
branch 2 4 50.0
condition n/a
subroutine 2 2 100.0
pod 0 1 0.0
total 15 20 75.0


line stmt bran cond sub pod time code
1             package IO::Die;
2              
3 1     1   6 use strict;
  1         2  
  1         187  
4              
5             #----------------------------------------------------------------------
6             #NOTE: read() and sysread() implementations are exactly the same except
7             #for the CORE:: function call. Alas, Perl’s prototyping stuff seems to
8             #make it impossible not to duplicate code here.
9              
10             sub read {
11 1     1 0 6 my ( $NS, $fh, @length_offset ) = ( shift, shift, @_[ 1 .. $#_ ] );
12              
13             #https://github.com/pjcj/Devel--Cover/issues/125
14             #my ( $NS, $fh, $buffer_sr, @length_offset ) = ( shift, shift, \shift, @_ );
15              
16 1         3 my ( $length, $offset ) = @length_offset;
17              
18 1         4 local ( $!, $^E );
19              
20             #NOTE: Perl’s prototypes can throw errors on things like:
21             #(@length_offset > 1) ? $offset : ()
22             #...so the following writes out the two forms of read():
23              
24 1         2 my $ret;
25 1 50       4 if ( @length_offset > 1 ) {
26 0         0 $ret = CORE::read( $fh, $_[0], $length, $offset );
27             }
28             else {
29 1         10 $ret = CORE::read( $fh, $_[0], $length );
30             }
31              
32 1 50       5 if ( !defined $ret ) {
33 1         8 $NS->__THROW( 'Read', length => $length );
34             }
35              
36 0           return $ret;
37             }
38              
39             1;