line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Strmode; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
22638
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT = qw(strmode); |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
169
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
1
|
|
|
1
|
|
5
|
require Fcntl; |
16
|
1
|
|
|
|
|
5
|
require constant; |
17
|
20
|
|
|
|
|
359
|
eval { Fcntl->import($_); 1 } || constant->import($_, 0) |
|
20
|
|
|
|
|
484
|
|
18
|
1
|
|
50
|
|
|
3
|
for qw(S_IFDIR S_IFCHR S_IFBLK S_IFREG S_IFLNK S_IFMT S_IRUSR |
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
delete $type{0}; # if some type constant is not defined for the |
32
|
|
|
|
|
|
|
# running OS, it will end at this slot. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %cache; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub strmode { |
37
|
96
|
|
|
96
|
0
|
34420
|
my $mode = shift; |
38
|
96
|
50
|
|
|
|
221
|
return undef unless defined $mode; |
39
|
96
|
|
66
|
|
|
530
|
$cache{$mode} ||= do { |
40
|
49
|
|
50
|
|
|
205
|
my $str = $type{$mode & S_IFMT} || '?'; |
41
|
49
|
100
|
|
|
|
111
|
$str .= (($mode & S_IRUSR) ? 'r' : '-'); |
42
|
49
|
100
|
|
|
|
79
|
$str .= (($mode & S_IWUSR) ? 'w' : '-'); |
43
|
49
|
100
|
|
|
|
76
|
if ($mode & S_IXUSR) { |
44
|
33
|
100
|
|
|
|
54
|
$str .= (($mode & S_ISUID) ? 's' : 'x'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
16
|
50
|
|
|
|
30
|
$str .= (($mode & S_ISUID) ? 'S' : '-'); |
48
|
|
|
|
|
|
|
} |
49
|
49
|
100
|
|
|
|
77
|
$str .= (($mode & S_IRGRP) ? 'r' : '-'); |
50
|
49
|
100
|
|
|
|
77
|
$str .= (($mode & S_IWGRP) ? 'w' : '-'); |
51
|
49
|
100
|
|
|
|
74
|
if (($mode & S_IXGRP)) { |
52
|
29
|
100
|
|
|
|
51
|
$str .= (($mode & S_ISGID) ? 's' : 'x'); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
20
|
50
|
|
|
|
31
|
$str .= (($mode & S_ISGID) ? 'S' : '-'); |
56
|
|
|
|
|
|
|
} |
57
|
49
|
100
|
|
|
|
80
|
$str .= (($mode & S_IROTH) ? 'r' : '-'); |
58
|
49
|
100
|
|
|
|
67
|
$str .= (($mode & S_IWOTH) ? 'w' : '-'); |
59
|
49
|
100
|
|
|
|
77
|
if ($mode & S_IXOTH) { |
60
|
19
|
100
|
|
|
|
36
|
$str .= (($mode & S_ISVTX) ? 't' : 'x'); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
30
|
100
|
|
|
|
47
|
$str .= (($mode & S_ISVTX) ? 'T' : '-'); |
64
|
|
|
|
|
|
|
} |
65
|
49
|
|
|
|
|
54
|
$str .= ' '; # will be a '+' if ACL's implemented |
66
|
49
|
|
|
|
|
330
|
$str |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
__END__ |