File Coverage

blib/lib/FFI/C/PosixFile.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package FFI::C::PosixFile;
2              
3 1     1   225982 use strict;
  1         7  
  1         28  
4 1     1   5 use warnings;
  1         2  
  1         32  
5 1     1   5 use Carp qw( croak );
  1         1  
  1         56  
6 1     1   6 use base qw( FFI::C::File );
  1         2  
  1         459  
7              
8             # ABSTRACT: Perl interface to C File pointer with POSIX extensions
9             our $VERSION = '0.14'; # VERSION
10              
11              
12             our $ffi = $FFI::C::File::ffi;
13              
14             if($ffi->find_symbol('fdopen') && $ffi->find_symbol('fileno'))
15             {
16              
17             $ffi->attach( fdopen => [ 'int', 'string' ] => 'opaque' => sub {
18             my($xsub, $class, $fd, $mode) = @_;
19             if(my $ptr = $xsub->($fd, $mode))
20             {
21             return bless \$ptr, $class;
22             }
23             else
24             {
25             croak "Error opening fd $fd with mode $mode: $!";
26             }
27             });
28              
29              
30             $ffi->attach( fileno => [ 'FILE' ] => 'int' );
31              
32             }
33             else
34             {
35             require Sub::Install;
36             foreach my $ctor (qw( fopen freopen new fdopen tmpfile ))
37             {
38             Sub::Install::install_sub({
39             code => sub { croak "FFI::C::PosixFile not supported on this platform"; },
40             into => __PACKAGE__,
41             as => $ctor,
42             });
43             }
44             }
45              
46             1;
47              
48             __END__