| 1 | package FileHandle::Fmode; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Fcntl qw(O_ACCMODE O_RDONLY O_WRONLY O_RDWR O_APPEND F_GETFL); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use constant IS_WIN32 => $^O =~ /mswin32/i ? 1 : 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use constant LIBC_IS_UCRT => $Config{libc} =~ /\-lucrt$|ucrt\.lib$/i ? 1 : 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | require Exporter; | |||||||||||||||||||||||||||
| 10 | 2 | require DynaLoader; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | *is_FH = \&is_arg_ok; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = '0.15'; | |||||||||||||||||||||||||||
| 15 | #$VERSION = eval $VERSION; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | @FileHandle::Fmode::ISA = qw(Exporter DynaLoader); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | @FileHandle::Fmode::EXPORT_OK = qw(is_R is_W is_RO is_WO is_RW is_arg_ok is_A is_FH); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | %FileHandle::Fmode::EXPORT_TAGS = (all => [qw | |||||||||||||||||||||||||||
| 22 | (is_R is_W is_RO is_WO is_RW is_arg_ok is_A is_FH)]); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | FileHandle::Fmode->DynaLoader::bootstrap($VERSION); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 80 | ▶ | sub is_arg_ok { | ||||||||||||||||||||||||||
|
Subroutine
is_arg_ok: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 80 | my $fileno = eval{fileno($_[0])}; | |||||||||||||||||||||||||||
| 28 | 80 | ▶ | if($@) {return 0} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 78 | ▶ | if(defined($fileno)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 76 | ▶ | if($fileno == -1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if($] < 5.007) {return 0} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 20 | return 1; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 56 | return 1; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 2 | return 0; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 88 | ▶ | sub is_RO { | ||||||||||||||||||||||||||
|
Subroutine
is_RO: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 88 | my $fileno = fileno($_[0]); | |||||||||||||||||||||||||||
| 41 | 84 | ▶ | if(!defined( $fileno)) {die "Not an open filehandle"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 80 | ▶ | if( $fileno == -1 || (IS_WIN32 && LIBC_IS_UCRT)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$fileno == -1 or 0
MC/DC100%1/1
$fileno == -1 or 0
$fileno == -1
Truth table100%2/2
A
A= $fileno == -1
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if($] < 5.007) {die "Illegal fileno() return"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 24 | ▶ | if(perliol_readable($_[0]) && !perliol_writable($_[0])) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
perliol_readable($_[0]) and not perliol_writable($_[0])
MC/DC100%2/2
perliol_readable($_[0]) and not perliol_writable($_[0])
perliol_readable($_[0])
not perliol_writable($_[0])
Truth table100%3/3
A and not(B)
A= perliol_readable($_[0])B= not perliol_writable($_[0])
| |||||||||||||||||||||||||||||
| 45 | 20 | return 0; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 56 | if(IS_WIN32 && !LIBC_IS_UCRT) { | |||||||||||||||||||||||||||
| 48 | if(win32_fmode($_[0]) & 1) {return 1} | ||||||||||||||||||||||||||||
| 49 | return 0; | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 56 | my $fmode = fcntl($_[0], F_GETFL, my $slush = 0); | |||||||||||||||||||||||||||
| 52 | 56 | ▶ | if(defined($fmode) && ($fmode & O_ACCMODE) == O_RDONLY) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $fmode and ($fmode & 3) == 0
MC/DC50%1/2
defined $fmode and ($fmode & 3) == 0
defined $fmode
($fmode & 3) == 0
Truth table66%2/3
A and B
A= defined $fmodeB= ($fmode & 3) == 0
| |||||||||||||||||||||||||||||
| 53 | 40 | return 0; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 88 | ▶ | sub is_WO { | ||||||||||||||||||||||||||
|
Subroutine
is_WO: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 88 | my $fileno = fileno($_[0]); | |||||||||||||||||||||||||||
| 58 | 84 | ▶ | if(!defined( $fileno)) {die "Not an open filehandle"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 80 | ▶ | if( $fileno == -1 || (IS_WIN32 && LIBC_IS_UCRT)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$fileno == -1 or 0
MC/DC100%1/1
$fileno == -1 or 0
$fileno == -1
Truth table100%2/2
A
A= $fileno == -1
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if($] < 5.007) {die "Illegal fileno() return"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 24 | ▶ | if(!perliol_readable($_[0]) && perliol_writable($_[0])) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not perliol_readable($_[0]) and perliol_writable($_[0])
MC/DC50%1/2
not perliol_readable($_[0]) and perliol_writable($_[0])
not perliol_readable($_[0])
perliol_writable($_[0])
Truth table66%2/3
not(A) and B
A= not perliol_readable($_[0])B= perliol_writable($_[0])
| |||||||||||||||||||||||||||||
| 62 | 16 | return 0; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 56 | if(IS_WIN32 && !LIBC_IS_UCRT) { | |||||||||||||||||||||||||||
| 65 | if(win32_fmode($_[0]) & 2) {return 1} | ||||||||||||||||||||||||||||
| 66 | return 0; | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 56 | my $fmode = fcntl($_[0], F_GETFL, my $slush = 0); | |||||||||||||||||||||||||||
| 69 | 56 | ▶ | if(defined($fmode) && ($fmode & O_ACCMODE) == O_WRONLY) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $fmode and ($fmode & 3) == 1
MC/DC50%1/2
defined $fmode and ($fmode & 3) == 1
defined $fmode
($fmode & 3) == 1
Truth table66%2/3
A and B
A= defined $fmodeB= ($fmode & 3) == 1
| |||||||||||||||||||||||||||||
| 70 | 40 | return 0; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 44 | ▶ | sub is_W { | ||||||||||||||||||||||||||
|
Subroutine
is_W: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 44 | ▶ | if(is_WO($_[0]) || is_RW($_[0])) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_WO($_[0]) or is_RW($_[0])
MC/DC100%2/2
is_WO($_[0]) or is_RW($_[0])
is_WO($_[0])
is_RW($_[0])
Truth table100%3/3
A or B
A= is_WO($_[0])B= is_RW($_[0])
| |||||||||||||||||||||||||||||
| 75 | 10 | return 0; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 44 | ▶ | sub is_R { | ||||||||||||||||||||||||||
|
Subroutine
is_R: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 44 | ▶ | if(is_RO($_[0]) || is_RW($_[0])) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_RO($_[0]) or is_RW($_[0])
MC/DC100%2/2
is_RO($_[0]) or is_RW($_[0])
is_RO($_[0])
is_RW($_[0])
Truth table100%3/3
A or B
A= is_RO($_[0])B= is_RW($_[0])
| |||||||||||||||||||||||||||||
| 80 | 12 | return 0; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 102 | ▶ | sub is_RW { | ||||||||||||||||||||||||||
|
Subroutine
is_RW: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 102 | my $fileno = fileno($_[0]); | |||||||||||||||||||||||||||
| 85 | 100 | ▶ | if(!defined( $fileno)) {die "Not an open filehandle"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 98 | ▶ | if( $fileno == -1 || (IS_WIN32 && LIBC_IS_UCRT)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$fileno == -1 or 0
MC/DC100%1/1
$fileno == -1 or 0
$fileno == -1
Truth table100%2/2
A
A= $fileno == -1
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if($] < 5.007) {die "Illegal fileno() return"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 30 | ▶ | if(perliol_readable($_[0]) && perliol_writable($_[0])) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
perliol_readable($_[0]) and perliol_writable($_[0])
MC/DC100%2/2
perliol_readable($_[0]) and perliol_writable($_[0])
perliol_readable($_[0])
perliol_writable($_[0])
Truth table100%3/3
A and B
A= perliol_readable($_[0])B= perliol_writable($_[0])
| |||||||||||||||||||||||||||||
| 89 | 12 | return 0; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 68 | if(IS_WIN32 && !LIBC_IS_UCRT) { | |||||||||||||||||||||||||||
| 92 | if(win32_fmode($_[0]) & 128) {return 1} | ||||||||||||||||||||||||||||
| 93 | return 0; | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 68 | my $fmode = fcntl($_[0], F_GETFL, my $slush = 0); | |||||||||||||||||||||||||||
| 96 | 68 | ▶ | if(defined($fmode) && ($fmode & O_ACCMODE) == O_RDWR) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $fmode and ($fmode & 3) == 2
MC/DC50%1/2
defined $fmode and ($fmode & 3) == 2
defined $fmode
($fmode & 3) == 2
Truth table66%2/3
A and B
A= defined $fmodeB= ($fmode & 3) == 2
| |||||||||||||||||||||||||||||
| 97 | 32 | return 0; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 44 | ▶ | sub is_A { | ||||||||||||||||||||||||||
|
Subroutine
is_A: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | 44 | my $fileno = fileno($_[0]); | |||||||||||||||||||||||||||
| 102 | 42 | ▶ | if(!defined( $fileno)) {die "Not an open filehandle"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 40 | ▶ | if( $fileno == -1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if($] < 5.007) {die "Illegal fileno() return"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 12 | return is_appendable($_[0]); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 28 | if(IS_WIN32) { | |||||||||||||||||||||||||||
| 108 | if($] < 5.006001) {die "is_A not currently implemented on Win32 for pre-5.6.1 perl"} | ||||||||||||||||||||||||||||
| 109 | return is_appendable($_[0]); | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 28 | my $fmode = fcntl($_[0], F_GETFL, my $slush = 0); | |||||||||||||||||||||||||||
| 112 | 28 | ▶ | if($fmode & O_APPEND) {return 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 20 | return 0; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | 1; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||