blib/lib/File/Strmode.pm

filter: Statementstmt 100% 43 / 43 Branchbran 88.2% 30 / 34 Conditioncond 60.0% 3 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 89.0% 81 / 91 CC 21 SCAR 27.1
CC
21
Cov
93%
strmode
19.2
BEGIN
3.0
BEGIN
1.0
CRAP 15.1
↑ Summary
1 package File::Strmode;
2  
3 1 our $VERSION = '0.03';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 require Exporter;
9 1 our @ISA = qw(Exporter);
10 1 our @EXPORT = qw(strmode);
11  
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.1
15 1 require Fcntl;
16 1 require constant;
17 20 eval { Fcntl->import($_); 1 } || constant->import($_, 0)
18 1 ▶ for qw(S_IFDIR S_IFCHR S_IFBLK S_IFREG S_IFLNK S_IFMT S_IRUSR
Branch: 1 branch
BranchTrueFalseTotal
eval { do { "Fcntl"->import($_); 1 } } or "constant"->import($_, 0) 20 0 20
19 S_IWUSR S_IXUSR S_ISUID S_IRGRP S_IWGRP S_IXGRP S_ISGID
20 S_IROTH S_IWOTH S_IXOTH S_ISVTX S_IFSOCK S_IFIFO);
21 }
22  
23 1 my %type = ( S_IFDIR, 'd',
24 S_IFCHR, 'c',
25 S_IFBLK, 'b',
26 S_IFREG, '-',
27 S_IFLNK, 'l',
28 S_IFSOCK, 's',
29 S_IFIFO, 'p' );
30  
31 1 delete $type{0}; # if some type constant is not defined for the
32 # running OS, it will end at this slot.
33  
34 1 my %cache;
35  
36 96 ▶sub strmode {
Subroutine strmode: called CC=19 SCAR=29.6
Pod undocumented
37 96 my $mode = shift;
38 96 ▶ return undef unless defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 0 96 96
39 96 ▶ $cache{$mode} ||= do {
Condition66%2/3
$cache{$mode} ||= do { my $str = $type{$mode & S_IFMT()} || "?"; $str .= ($mode & 256 ? "r" : "-"); $str .= ($mode & 128 ? "w" : "-"); if ($mode & 64) { $str .= ($mode & 2048 ? "s" : "x"); } else { $str .= ($mode & 2048 ? "S" : "-"); } ; $str .= ($mode & 32 ? "r" : "-"); $str .= ($mode & 16 ? "w" : "-"); if ($mode & 8) { $str .= ($mode & 1024 ? "s" : "x"); } else { $str .= ($mode & 1024 ? "S" : "-"); } ; $str .= ($mode & 4 ? "r" : "-"); $str .= ($mode & 2 ? "w" : "-"); if ($mode & 1) { $str .= ($mode & 512 ? "t" : "x"); } else { $str .= ($mode & 512 ? "T" : "-"); } ; $str .= ' '; $str }
l!l&&r!l&&!r
47490
MC/DC0%0/2
$cache{$mode} ||= do { my $str = $type{$mode & S_IFMT()} || "?"; $str .= ($mode & 256 ? "r" : "-"); $str .= ($mode & 128 ? "w" : "-"); if ($mode & 64) { $str .= ($mode & 2048 ? "s" : "x"); } else { $str .= ($mode & 2048 ? "S" : "-"); } ; $str .= ($mode & 32 ? "r" : "-"); $str .= ($mode & 16 ? "w" : "-"); if ($mode & 8) { $str .= ($mode & 1024 ? "s" : "x"); } else { $str .= ($mode & 1024 ? "S" : "-"); } ; $str .= ($mode & 4 ? "r" : "-"); $str .= ($mode & 2 ? "w" : "-"); if ($mode & 1) { $str .= ($mode & 512 ? "t" : "x"); } else { $str .= ($mode & 512 ? "T" : "-"); } ; $str .= ' '; $str }
$cache{$mode} do { my $str = $type{$mode & S_IFMT()} || "?"; $str .= ($mode & 256 ? "r" : "-"); $str .= ($mode & 128 ? "w" : "-"); if ($mode & 64) { $str .= ($mode & 2048 ? "s" : "x"); } else { $str .= ($mode & 2048 ? "S" : "-"); } ; $str .= ($mode & 32 ? "r" : "-"); $str .= ($mode & 16 ? "w" : "-"); if ($mode & 8) { $str .= ($mode & 1024 ? "s" : "x"); } else { $str .= ($mode & 1024 ? "S" : "-"); } ; $str .= ($mode & 4 ? "r" : "-"); $str .= ($mode & 2 ? "w" : "-"); if ($mode & 1) { $str .= ($mode & 512 ? "t" : "x"); } else { $str .= ($mode & 512 ? "T" : "-"); } ; $str .= ' '; $str }
Truth table66%2/3
A ||= B
A= $cache{$mode}B= do { my $str = $type{$mode & S_IFMT()} || "?"; $str .= ($mode & 256 ? "r" : "-"); $str .= ($mode & 128 ? "w" : "-"); if ($mode & 64) { $str .= ($mode & 2048 ? "s" : "x"); } else { $str .= ($mode & 2048 ? "S" : "-"); } ; $str .= ($mode & 32 ? "r" : "-"); $str .= ($mode & 16 ? "w" : "-"); if ($mode & 8) { $str .= ($mode & 1024 ? "s" : "x"); } else { $str .= ($mode & 1024 ? "S" : "-"); } ; $str .= ($mode & 4 ? "r" : "-"); $str .= ($mode & 2 ? "w" : "-"); if ($mode & 1) { $str .= ($mode & 512 ? "t" : "x"); } else { $str .= ($mode & 512 ? "T" : "-"); } ; $str .= ' '; $str }
ABresult
1X1
011
000
40 49 ▶ my $str = $type{$mode & S_IFMT} || '?';
Condition50%1/2
$type{$mode & S_IFMT()} || '?'
l!l
490
MC/DC0%0/1
$type{$mode & S_IFMT()} || '?'
$type{$mode & S_IFMT()}
Truth table50%1/2
A
A= $type{$mode & S_IFMT()}
Aresult
11
00
41 49 ▶ $str .= (($mode & S_IRUSR) ? 'r' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 256 ? : 46 3 49
42 49 ▶ $str .= (($mode & S_IWUSR) ? 'w' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 128 ? : 41 8 49
43 49 ▶ if ($mode & S_IXUSR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode & 64) { } 33 16 49
44 33 ▶ $str .= (($mode & S_ISUID) ? 's' : 'x');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 2048 ? : 5 28 33
45 }
46 else {
47 16 ▶ $str .= (($mode & S_ISUID) ? 'S' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 2048 ? : 0 16 16
48 }
49 49 ▶ $str .= (($mode & S_IRGRP) ? 'r' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 32 ? : 34 15 49
50 49 ▶ $str .= (($mode & S_IWGRP) ? 'w' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 16 ? : 15 34 49
51 49 ▶ if (($mode & S_IXGRP)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode & 8) { } 29 20 49
52 29 ▶ $str .= (($mode & S_ISGID) ? 's' : 'x');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 1024 ? : 7 22 29
53 }
54 else {
55 20 ▶ $str .= (($mode & S_ISGID) ? 'S' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 1024 ? : 0 20 20
56 }
57 49 ▶ $str .= (($mode & S_IROTH) ? 'r' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 4 ? : 23 26 49
58 49 ▶ $str .= (($mode & S_IWOTH) ? 'w' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 2 ? : 5 44 49
59 49 ▶ if ($mode & S_IXOTH) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode & 1) { } 19 30 49
60 19 ▶ $str .= (($mode & S_ISVTX) ? 't' : 'x');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 512 ? : 2 17 19
61 }
62 else {
63 30 ▶ $str .= (($mode & S_ISVTX) ? 'T' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$mode & 512 ? : 2 28 30
64 }
65 49 $str .= ' '; # will be a '+' if ACL's implemented
66 49 $str
67 };
68 }
69  
70 1 1;
71 __END__
↑ Summary