blib/lib/POSIX/1003/FdIO.pm

filter: Statementstmt 61.8% 34 / 55 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.0% 6 / 20 Podpod 100% 13 / 13 totaltotal 51.9% 53 / 102 CC 8 SCAR 24.2
CC
8
Cov
49%
fdopen
42.0
readfd
6.0
writefd
6.0
CRAP 11.2
« blib/lib/POSIX/1003/Sysconf.pm ↑ Summary blib/lib/POSIX/1003/Confstr.pm »
1 # Copyrights 2011-2013 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.01.
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package POSIX::1003::FdIO;
9 4 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 $VERSION = '0.98';
11  
12 4 ▶use base 'POSIX::1003::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Blocks resp from unistd.h, limits.h, and stdio.h
15 1 my (@constants, @seek, @mode);
16 1 my @functions = qw/closefd creatfd dupfd dup2fd openfd pipefd
17 readfd seekfd writefd tellfd truncfd fdopen/;
18  
19 1 our %EXPORT_TAGS =
20 ( constants => \@constants
21 , functions => \@functions
22 , seek => \@seek
23 , mode => \@mode
24 , tables => [ qw/%seek %mode/ ]
25 );
26  
27 1 my $fdio;
28 1 our (%fdio, %seek, %mode);
29  
30 BEGIN {
31 1 ▶ $fdio = fdio_table;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 push @constants, keys %$fdio;
33  
34 # initialize the :seek export tag
35 1 push @seek, grep /^SEEK_/, keys %$fdio;
36 1 my %seek_subset;
37 1 @seek_subset{@seek} = @{$fdio}{@seek};
38 1 tie %seek, 'POSIX::1003::ReadOnlyTable', \%seek_subset;
39  
40 # initialize the :mode export tag
41 1 push @mode, grep /^O_/, keys %$fdio;
42 1 my %mode_subset;
43 1 @mode_subset{@mode} = @{$fdio}{@mode};
44 1 tie %mode, 'POSIX::1003::ReadOnlyTable', \%mode_subset;
45 }
46  
47  
48 0 ▶sub seekfd($$$) { goto &POSIX::lseek }
Subroutine seekfd: not called CC=1 SCAR=6.9
Pod documented
49 0 ▶sub openfd($$;$) { goto &POSIX::open }
Subroutine openfd: not called CC=1 SCAR=6.9
Pod documented
50 0 ▶sub closefd($) { goto &POSIX::close }
Subroutine closefd: not called CC=1 SCAR=6.9
Pod documented
51 0 ▶sub readfd($$;$) { push @_, SSIZE_MAX() if @_==2; goto &POSIX::read }
Subroutine readfd: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 0 0 0
52 0 ▶sub writefd($$;$) { push @_, length $_[1] if @_==2; goto &POSIX::write }
Subroutine writefd: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 0 0 0
53 0 ▶sub pipefd() { goto &POSIX::pipe }
Subroutine pipefd: not called CC=1 SCAR=6.9
Pod documented
54 0 ▶sub dupfd($) { goto &POSIX::dup }
Subroutine dupfd: not called CC=1 SCAR=6.9
Pod documented
55 0 ▶sub dup2fd($$) { goto &POSIX::dup2 }
Subroutine dup2fd: not called CC=1 SCAR=6.9
Pod documented
56 0 ▶sub statfd($) { goto &POSIX::fstat }
Subroutine statfd: not called CC=1 SCAR=6.9
Pod documented
57 0 ▶sub creatfd($$) { openfd $_[0], O_WRONLY()|O_CREAT()|O_TRUNC(), $_[1] }
Subroutine creatfd: not called CC=1 SCAR=6.9
Pod documented
58  
59  
60 # This is implemented via CORE::open, because we need an Perl FH, not a
61 # FILE *.
62  
63 sub fdopen($$)
64 0 ▶{ my ($fd, $mode) = @_;
Subroutine fdopen: not called CC=6 SCAR=37.4
Pod documented
65
66 0 ▶ $mode =~ m/^([rwa]\+?|\<|\>|\>>)$/
Branch: 1 branch
BranchTrueFalseTotal
$mode =~ /^([rwa]\+?|\<|\>|\>>)$/ or die "illegal fdopen() mode '${mode}'\n" 0 0 0
67 or die "illegal fdopen() mode '$mode'\n";
68  
69 0 ▶ my $m = $1 eq 'r' ? '<' : $1 eq 'w' ? '>' : $1 eq 'a' ? '>>' : $1;
Branch: 3 branches
BranchTrueFalseTotal
$1 eq 'r' ? : 0 0 0
$1 eq 'w' ? : 0 0 0
$1 eq 'a' ? : 0 0 0
70  
71 0 ▶ die "fdopen() mode '$mode' (both read and write) is not supported\n"
Branch: 1 branch
BranchTrueFalseTotal
if substr($m, -1) eq "+" 0 0 0
72 if substr($m,-1) eq '+';
73  
74 0 open my($fh), "$m&=", $fd;
75 0 $fh;
76 }
77  
78  
79 #------------------
80  
81 0 ▶sub tellfd($) {seekfd $_[0], 0, SEEK_CUR() }
Subroutine tellfd: not called CC=1 SCAR=6.9
Pod documented
82 0 ▶sub rewindfd() {seekfd $_[0], 0, SEEK_SET() }
Subroutine rewindfd: not called CC=1 SCAR=6.9
Pod documented
83  
84  
85 sub _create_constant($)
86 2 ▶{ my ($class, $name) = @_;
Subroutine _create_constant: called CC=1 SCAR=0.2
87 2 my $val = $fdio->{$name};
88 2 ▶ sub() {$val};
Subroutine __ANON__: not called CC=1 SCAR=1.2
89 }
90  
91 1 1;
« blib/lib/POSIX/1003/Sysconf.pm ↑ Summary blib/lib/POSIX/1003/Confstr.pm »