| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
}
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
}
| |||||||||||||||||||||
| 40 | 49 | ▶ | my $str = $type{$mode & S_IFMT} || '?'; | ||||||||||||||||||
|
Condition50%1/2
$type{$mode & S_IFMT()} || '?'
MC/DC0%0/1
$type{$mode & S_IFMT()} || '?'
$type{$mode & S_IFMT()}
Truth table50%1/2
A
A= $type{$mode & S_IFMT()}
| |||||||||||||||||||||
| 41 | 49 | ▶ | $str .= (($mode & S_IRUSR) ? 'r' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 49 | ▶ | $str .= (($mode & S_IWUSR) ? 'w' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 49 | ▶ | if ($mode & S_IXUSR) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 33 | ▶ | $str .= (($mode & S_ISUID) ? 's' : 'x'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||
| 47 | 16 | ▶ | $str .= (($mode & S_ISUID) ? 'S' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | 49 | ▶ | $str .= (($mode & S_IRGRP) ? 'r' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 49 | ▶ | $str .= (($mode & S_IWGRP) ? 'w' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 49 | ▶ | if (($mode & S_IXGRP)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 29 | ▶ | $str .= (($mode & S_ISGID) ? 's' : 'x'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||
| 55 | 20 | ▶ | $str .= (($mode & S_ISGID) ? 'S' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | 49 | ▶ | $str .= (($mode & S_IROTH) ? 'r' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 49 | ▶ | $str .= (($mode & S_IWOTH) ? 'w' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 49 | ▶ | if ($mode & S_IXOTH) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 19 | ▶ | $str .= (($mode & S_ISVTX) ? 't' : 'x'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||
| 63 | 30 | ▶ | $str .= (($mode & S_ISVTX) ? 'T' : '-'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 49 | $str .= ' '; # will be a '+' if ACL's implemented | |||||||||||||||||||
| 66 | 49 | $str | |||||||||||||||||||
| 67 | }; | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 1 | 1; | |||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||