blib/lib/File/Listing.pm

filter: Statementstmt 85.4% 129 / 151 Branchbran 60.3% 64 / 106 Conditioncond 46.7% 36 / 77 MC/DCmcdc 23.5% 8 / 34 Subroutinesub 85.7% 18 / 21 Podpod 16.6% 1 / 6 totaltotal 64.8% 256 / 395 CC 81 SCAR 38.1
CC
81
Cov
69%
line
98.6
file_mode
67.3
line
14.9
CRAP 45.2
↑ Summary
1 package File::Listing;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use HTTP::Date qw(str2time);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Exporter 5.57 qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Parse directory listing
10 1 our $VERSION = '6.16'; # VERSION
11  
12 0 ▶sub Version { $File::Listing::VERSION; }
Subroutine Version: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 1 our @EXPORT = qw(parse_dir);
15  
16 sub parse_dir ($;$$$)
17 548 ▶{
Subroutine parse_dir: called CC=4 SCAR=13.9
Pod documented
18 548 my($dir, $tz, $fstype, $error) = @_;
19  
20 548 ▶ $fstype ||= 'unix';
Condition100%2/2
$fstype ||= "unix"
l!l
5462
MC/DC100%1/1
$fstype ||= "unix"
$fstype
Truth table100%2/2
A
A= $fstype
Aresult
11
00
21 548 $fstype = "File::Listing::" . lc $fstype;
22  
23 548 my @args = $_[0];
24 548 ▶ push(@args, $tz) if(@_ >= 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 2 547 1 548
25 548 ▶ push(@args, $error) if(@_ >= 4);
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 4 0 548 548
26  
27 548 $fstype->parse(@args);
28 }
29  
30  
31 0 ▶sub line { Carp::croak("Not implemented yet"); }
Subroutine line: not called CC=1 SCAR=6.9
Pod undocumented
32 0 ▶sub init { } # Dummy sub
Subroutine init: not called CC=1 SCAR=0.0
Pod undocumented
33  
34  
35 sub file_mode ($)
36 16465 ▶{
Subroutine file_mode: called CC=27 SCAR=42.1
Pod undocumented
37 16465 ▶ Carp::croak("Input to file_mode() must be a 10 character string.")
Branch: 1 branch
BranchTrueFalseTotal
unless length $_[0] == 10 0 16465 16465
38 unless length($_[0]) == 10;
39  
40 # This routine was originally borrowed from Graham Barr's
41 # Net::FTP package.
42  
43 16465 local $_ = shift;
44 16465 my $mode = 0;
45 16465 my($type);
46  
47 16465 ▶ s/^(.)// and $type = $1;
Branch: 1 branch
BranchTrueFalseTotal
s/^(.)// and $type = $1 16465 0 16465
48  
49 # When the set-group-ID bit (file mode bit 02000) is set, and the group
50 # execution bit (file mode bit 00020) is unset, and it is a regular file,
51 # some implementations of `ls' use the letter `S', others use `l' or `L'.
52 # Convert this `S'.
53  
54 16465 s/[Ll](...)$/S$1/;
55  
56 16465 ▶ while (/(.)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(.)/g) 148185 16465 164650
57 148185 $mode <<= 1;
58 148185 ▶ $mode |= 1 if $1 ne "-" &&
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "-" and $1 ne "*" and $1 ne "S" and $1 ne "T" 74073 74112 148185
Condition100%9/9
$1 ne "-" and $1 ne "*" and $1 ne "S" and $1 ne "T"
!ll&&!rl&&r
73088102474073
$1 ne "-" and $1 ne "*" and $1 ne "S"
!ll&&!rl&&r
64896819275097
$1 ne "-" and $1 ne "*"
!ll&&!rl&&r
648663083289
MC/DC100%4/4
$1 ne "-" and $1 ne "*" and $1 ne "S" and $1 ne "T"
$1 ne "-" $1 ne "*" $1 ne "S" $1 ne "T"
Truth table100%5/5
A and B and C and D
A= $1 ne "-"B= $1 ne "*"C= $1 ne "S"D= $1 ne "T"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
59 $1 ne "*" &&
60 $1 ne 'S' &&
61 $1 ne 'T';
62 }
63  
64 16465 ▶ $mode |= 0004000 if /^..s....../i;
Branch: 1 branch
BranchTrueFalseTotal
if /^..s....../i 8192 8273 16465
65 16465 ▶ $mode |= 0002000 if /^.....s.../i;
Branch: 1 branch
BranchTrueFalseTotal
if /^.....s.../i 8192 8273 16465
66 16465 ▶ $mode |= 0001000 if /^........t/i;
Branch: 1 branch
BranchTrueFalseTotal
if /^........t/i 2048 14417 16465
67  
68 # De facto standard definitions. From 'stat.h' on Solaris 9.
69  
70 16465 ▶ $type eq "p" and $mode |= 0010000 or # fifo
Branch: 1 branch
BranchTrueFalseTotal
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192 or $type eq "d" and $mode |= 16384 or $type eq "b" and $mode |= 24576 or $type eq "-" and $mode |= 32768 or $type eq "l" and $mode |= 40960 or $type eq "s" and $mode |= 49152 or $type eq "D" and $mode |= 53248 or Carp::croak("Unknown file type: $type") 16465 0 16465
Condition35%16/45
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192 or $type eq "d" and $mode |= 16384 or $type eq "b" and $mode |= 24576 or $type eq "-" and $mode |= 32768 or $type eq "l" and $mode |= 40960 or $type eq "s" and $mode |= 49152 or $type eq "D" and $mode |= 53248
l!l&&r!l&&!r
1646500
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192 or $type eq "d" and $mode |= 16384 or $type eq "b" and $mode |= 24576 or $type eq "-" and $mode |= 32768 or $type eq "l" and $mode |= 40960 or $type eq "s" and $mode |= 49152
l!l&&r!l&&!r
1646500
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192 or $type eq "d" and $mode |= 16384 or $type eq "b" and $mode |= 24576 or $type eq "-" and $mode |= 32768 or $type eq "l" and $mode |= 40960
l!l&&r!l&&!r
1646500
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192 or $type eq "d" and $mode |= 16384 or $type eq "b" and $mode |= 24576 or $type eq "-" and $mode |= 32768
l!l&&r!l&&!r
11164540
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192 or $type eq "d" and $mode |= 16384 or $type eq "b" and $mode |= 24576
l!l&&r!l&&!r
11016454
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192 or $type eq "d" and $mode |= 16384
l!l&&r!l&&!r
01116454
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192
l!l&&r!l&&!r
0016465
$type eq "p" and $mode |= 4096
!ll&&!rl&&r
1646500
$type eq "c" and $mode |= 8192
!ll&&!rl&&r
1646500
$type eq "d" and $mode |= 16384
!ll&&!rl&&r
16454011
$type eq "b" and $mode |= 24576
!ll&&!rl&&r
1645400
$type eq "-" and $mode |= 32768
!ll&&!rl&&r
0016454
$type eq "l" and $mode |= 40960
!ll&&!rl&&r
000
$type eq "s" and $mode |= 49152
!ll&&!rl&&r
000
$type eq "D" and $mode |= 53248
!ll&&!rl&&r
000
MC/DC0%0/16
$type eq "p" and $mode |= 4096 or $type eq "c" and $mode |= 8192 or $type eq "d" and $mode |= 16384 or $type eq "b" and $mode |= 24576 or $type eq "-" and $mode |= 32768 or $type eq "l" and $mode |= 40960 or $type eq "s" and $mode |= 49152 or $type eq "D" and $mode |= 53248
$type eq "p" $mode |= 4096 $type eq "c" $mode |= 8192 $type eq "d" $mode |= 16384 $type eq "b" $mode |= 24576 $type eq "-" $mode |= 32768 $type eq "l" $mode |= 40960 $type eq "s" $mode |= 49152 $type eq "D" $mode |= 53248
Truth table0%2/511
A and B or C and D or E and F or G and H or I and J or K and L or M and N or O and P
A= $type eq "p"B= $mode |= 4096C= $type eq "c"D= $mode |= 8192E= $type eq "d"F= $mode |= 16384G= $type eq "b"H= $mode |= 24576I= $type eq "-"J= $mode |= 32768K= $type eq "l"L= $mode |= 40960M= $type eq "s"N= $mode |= 49152O= $type eq "D"P= $mode |= 53248
ABCDEFGHIJKLMNOPresult
11XXXXXXXXXXXXXX1
0X11XXXXXXXXXXXX1
1011XXXXXXXXXXXX1
0X0X11XXXXXXXXXX1
0X1011XXXXXXXXXX1
100X11XXXXXXXXXX1
101011XXXXXXXXXX1
0X0X0X11XXXXXXXX1
0X0X1011XXXXXXXX1
0X100X11XXXXXXXX1
0X101011XXXXXXXX1
100X0X11XXXXXXXX1
100X1011XXXXXXXX1
10100X11XXXXXXXX1
10101011XXXXXXXX1
0X0X0X0X11XXXXXX1
0X0X0X1011XXXXXX1
0X0X100X11XXXXXX1
0X0X101011XXXXXX1
0X100X0X11XXXXXX1
0X100X1011XXXXXX1
0X10100X11XXXXXX1
0X10101011XXXXXX1
100X0X0X11XXXXXX1
100X0X1011XXXXXX1
100X100X11XXXXXX1
100X101011XXXXXX1
10100X0X11XXXXXX1
10100X1011XXXXXX1
1010100X11XXXXXX1
1010101011XXXXXX1
0X0X0X0X0X11XXXX1
0X0X0X0X1011XXXX1
0X0X0X100X11XXXX1
0X0X0X101011XXXX1
0X0X100X0X11XXXX1
0X0X100X1011XXXX1
0X0X10100X11XXXX1
0X0X10101011XXXX1
0X100X0X0X11XXXX1
0X100X0X1011XXXX1
0X100X100X11XXXX1
0X100X101011XXXX1
0X10100X0X11XXXX1
0X10100X1011XXXX1
0X1010100X11XXXX1
0X1010101011XXXX1
100X0X0X0X11XXXX1
100X0X0X1011XXXX1
100X0X100X11XXXX1
100X0X101011XXXX1
100X100X0X11XXXX1
100X100X1011XXXX1
100X10100X11XXXX1
100X10101011XXXX1
10100X0X0X11XXXX1
10100X0X1011XXXX1
10100X100X11XXXX1
10100X101011XXXX1
1010100X0X11XXXX1
1010100X1011XXXX1
101010100X11XXXX1
101010101011XXXX1
0X0X0X0X0X0X11XX1
0X0X0X0X0X1011XX1
0X0X0X0X100X11XX1
0X0X0X0X101011XX1
0X0X0X100X0X11XX1
0X0X0X100X1011XX1
0X0X0X10100X11XX1
0X0X0X10101011XX1
0X0X100X0X0X11XX1
0X0X100X0X1011XX1
0X0X100X100X11XX1
0X0X100X101011XX1
0X0X10100X0X11XX1
0X0X10100X1011XX1
0X0X1010100X11XX1
0X0X1010101011XX1
0X100X0X0X0X11XX1
0X100X0X0X1011XX1
0X100X0X100X11XX1
0X100X0X101011XX1
0X100X100X0X11XX1
0X100X100X1011XX1
0X100X10100X11XX1
0X100X10101011XX1
0X10100X0X0X11XX1
0X10100X0X1011XX1
0X10100X100X11XX1
0X10100X101011XX1
0X1010100X0X11XX1
0X1010100X1011XX1
0X101010100X11XX1
0X101010101011XX1
100X0X0X0X0X11XX1
100X0X0X0X1011XX1
100X0X0X100X11XX1
100X0X0X101011XX1
100X0X100X0X11XX1
100X0X100X1011XX1
100X0X10100X11XX1
100X0X10101011XX1
100X100X0X0X11XX1
100X100X0X1011XX1
100X100X100X11XX1
100X100X101011XX1
100X10100X0X11XX1
100X10100X1011XX1
100X1010100X11XX1
100X1010101011XX1
10100X0X0X0X11XX1
10100X0X0X1011XX1
10100X0X100X11XX1
10100X0X101011XX1
10100X100X0X11XX1
10100X100X1011XX1
10100X10100X11XX1
10100X10101011XX1
1010100X0X0X11XX1
1010100X0X1011XX1
1010100X100X11XX1
1010100X101011XX1
101010100X0X11XX1
101010100X1011XX1
10101010100X11XX1
10101010101011XX1
0X0X0X0X0X0X0X111
0X0X0X0X0X0X10111
0X0X0X0X0X100X111
0X0X0X0X0X1010111
0X0X0X0X100X0X111
0X0X0X0X100X10111
0X0X0X0X10100X111
0X0X0X0X101010111
0X0X0X100X0X0X111
0X0X0X100X0X10111
0X0X0X100X100X111
0X0X0X100X1010111
0X0X0X10100X0X111
0X0X0X10100X10111
0X0X0X1010100X111
0X0X0X10101010111
0X0X100X0X0X0X111
0X0X100X0X0X10111
0X0X100X0X100X111
0X0X100X0X1010111
0X0X100X100X0X111
0X0X100X100X10111
0X0X100X10100X111
0X0X100X101010111
0X0X10100X0X0X111
0X0X10100X0X10111
0X0X10100X100X111
0X0X10100X1010111
0X0X1010100X0X111
0X0X1010100X10111
0X0X101010100X111
0X0X1010101010111
0X100X0X0X0X0X111
0X100X0X0X0X10111
0X100X0X0X100X111
0X100X0X0X1010111
0X100X0X100X0X111
0X100X0X100X10111
0X100X0X10100X111
0X100X0X101010111
0X100X100X0X0X111
0X100X100X0X10111
0X100X100X100X111
0X100X100X1010111
0X100X10100X0X111
0X100X10100X10111
0X100X1010100X111
0X100X10101010111
0X10100X0X0X0X111
0X10100X0X0X10111
0X10100X0X100X111
0X10100X0X1010111
0X10100X100X0X111
0X10100X100X10111
0X10100X10100X111
0X10100X101010111
0X1010100X0X0X111
0X1010100X0X10111
0X1010100X100X111
0X1010100X1010111
0X101010100X0X111
0X101010100X10111
0X10101010100X111
0X101010101010111
100X0X0X0X0X0X111
100X0X0X0X0X10111
100X0X0X0X100X111
100X0X0X0X1010111
100X0X0X100X0X111
100X0X0X100X10111
100X0X0X10100X111
100X0X0X101010111
100X0X100X0X0X111
100X0X100X0X10111
100X0X100X100X111
100X0X100X1010111
100X0X10100X0X111
100X0X10100X10111
100X0X1010100X111
100X0X10101010111
100X100X0X0X0X111
100X100X0X0X10111
100X100X0X100X111
100X100X0X1010111
100X100X100X0X111
100X100X100X10111
100X100X10100X111
100X100X101010111
100X10100X0X0X111
100X10100X0X10111
100X10100X100X111
100X10100X1010111
100X1010100X0X111
100X1010100X10111
100X101010100X111
100X1010101010111
10100X0X0X0X0X111
10100X0X0X0X10111
10100X0X0X100X111
10100X0X0X1010111
10100X0X100X0X111
10100X0X100X10111
10100X0X10100X111
10100X0X101010111
10100X100X0X0X111
10100X100X0X10111
10100X100X100X111
10100X100X1010111
10100X10100X0X111
10100X10100X10111
10100X1010100X111
10100X10101010111
1010100X0X0X0X111
1010100X0X0X10111
1010100X0X100X111
1010100X0X1010111
1010100X100X0X111
1010100X100X10111
1010100X10100X111
1010100X101010111
101010100X0X0X111
101010100X0X10111
101010100X100X111
101010100X1010111
10101010100X0X111
10101010100X10111
1010101010100X111
10101010101010111
0X0X0X0X0X0X0X0X0
0X0X0X0X0X0X0X100
0X0X0X0X0X0X100X0
0X0X0X0X0X0X10100
0X0X0X0X0X100X0X0
0X0X0X0X0X100X100
0X0X0X0X0X10100X0
0X0X0X0X0X1010100
0X0X0X0X100X0X0X0
0X0X0X0X100X0X100
0X0X0X0X100X100X0
0X0X0X0X100X10100
0X0X0X0X10100X0X0
0X0X0X0X10100X100
0X0X0X0X1010100X0
0X0X0X0X101010100
0X0X0X100X0X0X0X0
0X0X0X100X0X0X100
0X0X0X100X0X100X0
0X0X0X100X0X10100
0X0X0X100X100X0X0
0X0X0X100X100X100
0X0X0X100X10100X0
0X0X0X100X1010100
0X0X0X10100X0X0X0
0X0X0X10100X0X100
0X0X0X10100X100X0
0X0X0X10100X10100
0X0X0X1010100X0X0
0X0X0X1010100X100
0X0X0X101010100X0
0X0X0X10101010100
0X0X100X0X0X0X0X0
0X0X100X0X0X0X100
0X0X100X0X0X100X0
0X0X100X0X0X10100
0X0X100X0X100X0X0
0X0X100X0X100X100
0X0X100X0X10100X0
0X0X100X0X1010100
0X0X100X100X0X0X0
0X0X100X100X0X100
0X0X100X100X100X0
0X0X100X100X10100
0X0X100X10100X0X0
0X0X100X10100X100
0X0X100X1010100X0
0X0X100X101010100
0X0X10100X0X0X0X0
0X0X10100X0X0X100
0X0X10100X0X100X0
0X0X10100X0X10100
0X0X10100X100X0X0
0X0X10100X100X100
0X0X10100X10100X0
0X0X10100X1010100
0X0X1010100X0X0X0
0X0X1010100X0X100
0X0X1010100X100X0
0X0X1010100X10100
0X0X101010100X0X0
0X0X101010100X100
0X0X10101010100X0
0X0X1010101010100
0X100X0X0X0X0X0X0
0X100X0X0X0X0X100
0X100X0X0X0X100X0
0X100X0X0X0X10100
0X100X0X0X100X0X0
0X100X0X0X100X100
0X100X0X0X10100X0
0X100X0X0X1010100
0X100X0X100X0X0X0
0X100X0X100X0X100
0X100X0X100X100X0
0X100X0X100X10100
0X100X0X10100X0X0
0X100X0X10100X100
0X100X0X1010100X0
0X100X0X101010100
0X100X100X0X0X0X0
0X100X100X0X0X100
0X100X100X0X100X0
0X100X100X0X10100
0X100X100X100X0X0
0X100X100X100X100
0X100X100X10100X0
0X100X100X1010100
0X100X10100X0X0X0
0X100X10100X0X100
0X100X10100X100X0
0X100X10100X10100
0X100X1010100X0X0
0X100X1010100X100
0X100X101010100X0
0X100X10101010100
0X10100X0X0X0X0X0
0X10100X0X0X0X100
0X10100X0X0X100X0
0X10100X0X0X10100
0X10100X0X100X0X0
0X10100X0X100X100
0X10100X0X10100X0
0X10100X0X1010100
0X10100X100X0X0X0
0X10100X100X0X100
0X10100X100X100X0
0X10100X100X10100
0X10100X10100X0X0
0X10100X10100X100
0X10100X1010100X0
0X10100X101010100
0X1010100X0X0X0X0
0X1010100X0X0X100
0X1010100X0X100X0
0X1010100X0X10100
0X1010100X100X0X0
0X1010100X100X100
0X1010100X10100X0
0X1010100X1010100
0X101010100X0X0X0
0X101010100X0X100
0X101010100X100X0
0X101010100X10100
0X10101010100X0X0
0X10101010100X100
0X1010101010100X0
0X101010101010100
100X0X0X0X0X0X0X0
100X0X0X0X0X0X100
100X0X0X0X0X100X0
100X0X0X0X0X10100
100X0X0X0X100X0X0
100X0X0X0X100X100
100X0X0X0X10100X0
100X0X0X0X1010100
100X0X0X100X0X0X0
100X0X0X100X0X100
100X0X0X100X100X0
100X0X0X100X10100
100X0X0X10100X0X0
100X0X0X10100X100
100X0X0X1010100X0
100X0X0X101010100
100X0X100X0X0X0X0
100X0X100X0X0X100
100X0X100X0X100X0
100X0X100X0X10100
100X0X100X100X0X0
100X0X100X100X100
100X0X100X10100X0
100X0X100X1010100
100X0X10100X0X0X0
100X0X10100X0X100
100X0X10100X100X0
100X0X10100X10100
100X0X1010100X0X0
100X0X1010100X100
100X0X101010100X0
100X0X10101010100
100X100X0X0X0X0X0
100X100X0X0X0X100
100X100X0X0X100X0
100X100X0X0X10100
100X100X0X100X0X0
100X100X0X100X100
100X100X0X10100X0
100X100X0X1010100
100X100X100X0X0X0
100X100X100X0X100
100X100X100X100X0
100X100X100X10100
100X100X10100X0X0
100X100X10100X100
100X100X1010100X0
100X100X101010100
100X10100X0X0X0X0
100X10100X0X0X100
100X10100X0X100X0
100X10100X0X10100
100X10100X100X0X0
100X10100X100X100
100X10100X10100X0
100X10100X1010100
100X1010100X0X0X0
100X1010100X0X100
100X1010100X100X0
100X1010100X10100
100X101010100X0X0
100X101010100X100
100X10101010100X0
100X1010101010100
10100X0X0X0X0X0X0
10100X0X0X0X0X100
10100X0X0X0X100X0
10100X0X0X0X10100
10100X0X0X100X0X0
10100X0X0X100X100
10100X0X0X10100X0
10100X0X0X1010100
10100X0X100X0X0X0
10100X0X100X0X100
10100X0X100X100X0
10100X0X100X10100
10100X0X10100X0X0
10100X0X10100X100
10100X0X1010100X0
10100X0X101010100
10100X100X0X0X0X0
10100X100X0X0X100
10100X100X0X100X0
10100X100X0X10100
10100X100X100X0X0
10100X100X100X100
10100X100X10100X0
10100X100X1010100
10100X10100X0X0X0
10100X10100X0X100
10100X10100X100X0
10100X10100X10100
10100X1010100X0X0
10100X1010100X100
10100X101010100X0
10100X10101010100
1010100X0X0X0X0X0
1010100X0X0X0X100
1010100X0X0X100X0
1010100X0X0X10100
1010100X0X100X0X0
1010100X0X100X100
1010100X0X10100X0
1010100X0X1010100
1010100X100X0X0X0
1010100X100X0X100
1010100X100X100X0
1010100X100X10100
1010100X10100X0X0
1010100X10100X100
1010100X1010100X0
1010100X101010100
101010100X0X0X0X0
101010100X0X0X100
101010100X0X100X0
101010100X0X10100
101010100X100X0X0
101010100X100X100
101010100X10100X0
101010100X1010100
10101010100X0X0X0
10101010100X0X100
10101010100X100X0
10101010100X10100
1010101010100X0X0
1010101010100X100
101010101010100X0
10101010101010100
71 $type eq "c" and $mode |= 0020000 or # character special
72 $type eq "d" and $mode |= 0040000 or # directory
73 $type eq "b" and $mode |= 0060000 or # block special
74 $type eq "-" and $mode |= 0100000 or # regular
75 $type eq "l" and $mode |= 0120000 or # symbolic link
76 $type eq "s" and $mode |= 0140000 or # socket
77 $type eq "D" and $mode |= 0150000 or # door
78 Carp::croak("Unknown file type: $type");
79  
80 16465 $mode;
81 }
82  
83  
84 sub parse
85 548 ▶{
Subroutine parse: called CC=9 SCAR=22.2
Pod undocumented
86 548 my($pkg, $dir, $tz, $error) = @_;
87  
88 # First let's try to determine what kind of dir parameter we have
89 # received. We allow both listings, reference to arrays and
90 # file handles to read from.
91  
92 548 ▶ if (ref($dir) eq 'ARRAY') {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $dir eq 'ARRAY') { } 0 548 548
elsif (ref $dir eq 'GLOB') { } 2 546 548
elsif (ref $dir) { } 0 546 546
elsif ($dir =~ /^\*\w+(::\w+)+$/) { } 0 546 546
93 # Already split up
94 }
95 elsif (ref($dir) eq 'GLOB') {
96 # A file handle
97 }
98 elsif (ref($dir)) {
99 0 Carp::croak("Illegal argument to parse_dir()");
100 }
101 elsif ($dir =~ /^\*\w+(::\w+)+$/) {
102 # This scalar looks like a file handle, so we assume it is
103 }
104 else {
105 # A normal scalar listing
106 546 $dir = [ split(/\n/, $dir) ];
107 }
108  
109 548 $pkg->init();
110  
111 548 my @files = ();
112 548 ▶ if (ref($dir) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dir eq 'ARRAY') { } 546 2 548
113 546 for (@$dir) {
114 1925 push(@files, $pkg->line($_, $tz, $error));
115 }
116 }
117 else {
118 2 local($_);
119 2 ▶ while (my $line = <$dir>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dir)) 86 2 88
120 86 chomp $line;
121 86 push(@files, $pkg->line($line, $tz, $error));
122 }
123 }
124 548 ▶ wantarray ? @files : \@files; ## no critic (Community::Wantarray)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 546 2 548
125 }
126  
127  
128  
129 package File::Listing::unix;
130  
131 1 ▶use HTTP::Date qw(str2time);
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 1 our @ISA = qw(File::Listing);
134  
135 # A place to remember current directory from last line parsed.
136 1 our $curdir;
137  
138 sub init
139 5 ▶{
Subroutine init: called CC=1 SCAR=0.0
140 5 $curdir = '';
141 }
142  
143  
144 sub line
145 135 ▶{
Subroutine line: called CC=24 SCAR=45.9
146 135 shift; # package name
147 135 local($_) = shift;
148 135 my($tz, $error) = @_;
149  
150 135 s/\015//g;
151 #study;
152  
153 135 my ($kind, $size, $date, $name);
154 135 ▶ if (($kind, $size, $date, $name) =
Branch: 5 branches
BranchTrueFalseTotal
if (() = /^([\-\*FlrwxsStTdD]{10}) # Type and permission bits .* # Graps \D(\d+) # File size \s+ # Some space (\w{3}\s+\d+\s+(?:\d{1,2}:\d{2}|\d{4})|\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}) # Date \s+ # Some more space (.*)$ # File name /x) { } 105 30 135
elsif (/^(.+):$/ and not /^[dcbsp].*\s.*\s.*:$/) { } 9 21 30
elsif (/^[Tt]otal\s+(\d+)$/ or /^\s*$/) { } 21 0 21
elsif (/not found/ or /No such file/ or /cannot find/) { } 0 0 0
elsif ($_ eq '') { } 0 0 0
155 /^([\-\*FlrwxsStTdD]{10}) # Type and permission bits
156 .* # Graps
157 \D(\d+) # File size
158 \s+ # Some space
159 (\w{3}\s+\d+\s+(?:\d{1,2}:\d{2}|\d{4})|\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}) # Date
160 \s+ # Some more space
161 (.*)$ # File name
162 /x )
163  
164 {
165 105 ▶ return if $name eq '.' || $name eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "." or $name eq ".." 24 81 105
Condition100%3/3
$name eq "." or $name eq ".."
l!l&&r!l&&!r
121281
MC/DC100%2/2
$name eq "." or $name eq ".."
$name eq "." $name eq ".."
Truth table100%3/3
A or B
A= $name eq "."B= $name eq ".."
ABresult
1X1
011
000
166 81 ▶ $name = "$curdir/$name" if length $curdir;
Branch: 1 branch
BranchTrueFalseTotal
if length $File::Listing::unix::curdir 36 45 81
167 81 my $type = '?';
168 81 ▶ if ($kind =~ /^l/ && $name =~ /(.*) -> (.*)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($kind =~ /^l/ and $name =~ /(.*) -> (.*)/) { } 0 81 81
elsif ($kind =~ /^[\-F]/) { } 70 11 81
elsif ($kind =~ /^[dD]/) { } 11 0 11
Condition33%1/3
$kind =~ /^l/ and $name =~ /(.*) -> (.*)/
!ll&&!rl&&r
8100
MC/DC0%0/2
$kind =~ /^l/ and $name =~ /(.*) -> (.*)/
$kind =~ /^l/ $name =~ /(.*) -> (.*)/
Truth table33%1/3
A and B
A= $kind =~ /^l/B= $name =~ /(.*) -> (.*)/
ABresult
0X0
100
111
169 0 $name = $1;
170 0 $type = "l $2";
171 }
172 elsif ($kind =~ /^[\-F]/) { # (hopefully) a regular file
173 70 $type = 'f';
174 }
175 elsif ($kind =~ /^[dD]/) {
176 11 $type = 'd';
177 11 $size = undef; # Don't believe the reported size
178 }
179 81 return [$name, $type, $size, str2time($date, $tz),
180 File::Listing::file_mode($kind)];
181  
182 }
183 ▶ elsif (/^(.+):$/ && !/^[dcbsp].*\s.*\s.*:$/ ) {
Condition66%2/3
/^(.+):$/ and not /^[dcbsp].*\s.*\s.*:$/
!ll&&!rl&&r
2109
MC/DC50%1/2
/^(.+):$/ and not /^[dcbsp].*\s.*\s.*:$/
/^(.+):$/ not /^[dcbsp].*\s.*\s.*:$/
Truth table66%2/3
A and not(B)
A= /^(.+):$/B= not /^[dcbsp].*\s.*\s.*:$/
ABresult
0X0
100
111
184 9 my $dir = $1;
185 9 ▶ return () if $dir eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "." 0 9 9
186 9 $curdir = $dir;
187 9 return ();
188 }
189 ▶ elsif (/^[Tt]otal\s+(\d+)$/ || /^\s*$/) {
Condition66%2/3
/^[Tt]otal\s+(\d+)$/ or /^\s*$/
l!l&&r!l&&!r
1290
MC/DC0%0/2
/^[Tt]otal\s+(\d+)$/ or /^\s*$/
/^[Tt]otal\s+(\d+)$/ /^\s*$/
Truth table66%2/3
A or B
A= /^[Tt]otal\s+(\d+)$/B= /^\s*$/
ABresult
1X1
011
000
190 21 return ();
191 }
192 ▶ elsif (/not found/ || # OSF1, HPUX, and SunOS return
Condition0%0/6
/not found/ or /No such file/ or /cannot find/
l!l&&r!l&&!r
000
/not found/ or /No such file/
l!l&&r!l&&!r
000
MC/DC0%0/3
/not found/ or /No such file/ or /cannot find/
/not found/ /No such file/ /cannot find/
Truth table0%0/4
A or B or C
A= /not found/B= /No such file/C= /cannot find/
ABCresult
1XX1
01X1
0011
0000
193 # "$file not found"
194 /No such file/ || # IRIX returns
195 # "UX:ls: ERROR: Cannot access $file: No such file or directory"
196 # Solaris returns
197 # "$file: No such file or directory"
198 /cannot find/ # Windows NT returns
199 # "The system cannot find the path specified."
200 ) {
201 0 ▶ return () unless defined $error;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 0 0 0
202 0 ▶ &$error($_) if ref($error) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $error eq "CODE" 0 0 0
203 0 ▶ warn "Error: $_\n" if $error eq 'warn';
Branch: 1 branch
BranchTrueFalseTotal
if $error eq "warn" 0 0 0
204 0 return ();
205 }
206 elsif ($_ eq '') { # AIX, and Linux return nothing
207 0 ▶ return () unless defined $error;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 0 0 0
208 0 ▶ &$error("No such file or directory") if ref($error) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $error eq "CODE" 0 0 0
209 0 ▶ warn "Warning: No such file or directory\n" if $error eq 'warn';
Branch: 1 branch
BranchTrueFalseTotal
if $error eq "warn" 0 0 0
210 0 return ();
211 }
212 else {
213 # parse failed, check if the dosftp parse understands it
214 0 File::Listing::dosftp->init();
215 0 return(File::Listing::dosftp->line($_,$tz,$error));
216 }
217  
218 }
219  
220  
221  
222 package File::Listing::dosftp;
223  
224 1 ▶use HTTP::Date qw(str2time);
Subroutine BEGIN: called CC=1 SCAR=0.0
225  
226 1 our @ISA = qw(File::Listing);
227  
228 # A place to remember current directory from last line parsed.
229 1 our $curdir;
230  
231  
232  
233 sub init
234 2 ▶{
Subroutine init: called CC=1 SCAR=0.0
235 2 $curdir = '';
236 }
237  
238  
239 sub line
240 4 ▶{
Subroutine line: called CC=9 SCAR=27.0
241 4 shift; # package name
242 4 local($_) = shift;
243 4 my($tz, $error) = @_;
244  
245 4 s/\015//g;
246  
247 4 my ($date, $size_or_dir, $name, $size);
248  
249 # usual format:
250 # 02-05-96 10:48AM 1415 src.slf
251 # 09-10-96 09:18AM <DIR> sl_util
252 # alternative dos format with four-digit year:
253 # 02-05-2022 10:48AM 1415 src.slf
254 # 09-10-2022 09:18AM <DIR> sl_util
255 4 ▶ if (($date, $size_or_dir, $name) =
Branch: 1 branch
BranchTrueFalseTotal
if (() = /^(\d\d-\d\d-\d{2,4}\s+\d\d:\d\d\wM) # Date and time info \s+ # Some space (<\w{3}>|\d+) # Dir or Size \s+ # Some more space (.+)$ # File name /x) { } 4 0 4
256 /^(\d\d-\d\d-\d{2,4}\s+\d\d:\d\d\wM) # Date and time info
257 \s+ # Some space
258 (<\w{3}>|\d+) # Dir or Size
259 \s+ # Some more space
260 (.+)$ # File name
261 /x )
262 {
263 4 ▶ return if $name eq '.' || $name eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "." or $name eq ".." 0 4 4
Condition33%1/3
$name eq "." or $name eq ".."
l!l&&r!l&&!r
004
MC/DC0%0/2
$name eq "." or $name eq ".."
$name eq "." $name eq ".."
Truth table33%1/3
A or B
A= $name eq "."B= $name eq ".."
ABresult
1X1
011
000
264 4 ▶ $name = "$curdir/$name" if length $curdir;
Branch: 1 branch
BranchTrueFalseTotal
if length $File::Listing::dosftp::curdir 0 4 4
265 4 my $type = '?';
266 4 ▶ if ($size_or_dir eq '<DIR>') {
Branch: 1 branch
BranchTrueFalseTotal
if ($size_or_dir eq '<DIR>') { } 2 2 4
267 2 $type = "d";
268 2 $size = ""; # directories have no size in the pc listing
269 }
270 else {
271 2 $type = 'f';
272 2 $size = $size_or_dir;
273 }
274 4 return [$name, $type, $size, str2time($date, $tz), undef];
275 }
276 else {
277 0 ▶ return () unless defined $error;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 0 0 0
278 0 ▶ &$error($_) if ref($error) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $error eq "CODE" 0 0 0
279 0 ▶ warn "Can't parse: $_\n" if $error eq 'warn';
Branch: 1 branch
BranchTrueFalseTotal
if $error eq "warn" 0 0 0
280 0 return ();
281 }
282  
283 }
284  
285  
286  
287 package File::Listing::vms;
288 1 our @ISA = qw(File::Listing);
289  
290 package File::Listing::netware;
291 1 our @ISA = qw(File::Listing);
292  
293  
294  
295 package File::Listing::apache;
296  
297 1 our @ISA = qw(File::Listing);
298  
299  
300 541 ▶sub init { }
Subroutine init: called CC=1 SCAR=0.0
301  
302  
303 1872 ▶sub line {
Subroutine line: called CC=10 SCAR=23.0
304 1872 shift; # package name
305 1872 local($_) = shift;
306 1872 my($tz, $error) = @_; # ignored for now...
307  
308 1872 s!</?t[rd][^>]*>! !g; # clean away various table stuff
309 1872 ▶ if (m!<A\s+HREF=\"([^?\"]+)\">.*</A>.*?(\d+)-([a-zA-Z]+|\d+)-(\d+)\s+(\d+):(\d+)\s+(?:([\d\.]+[kMG]?|-))!i) {
Branch: 2 branches
BranchTrueFalseTotal
if (m[<A\s+HREF=\"([^?\"]+)\">.*</A>.*?(\d+)-([a-zA-Z]+|\d+)-(\d+)\s+(\d+):(\d+)\s+(?:([\d\.]+[kMG]?|-))]i) { } 1608 264 1872
elsif (m[<A\s+HREF=\"([^?/\"]+/?)\">.*</A>]i) { } 23 241 264
310 1608 my($filename, $filesize) = ($1, $7);
311 1608 my($d,$m,$y, $H,$M) = ($2,$3,$4,$5,$6);
312 1608 ▶ if ($m =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m =~ /^\d+$/) { } 699 909 1608
313 699 ($d,$y) = ($y,$d) # iso date
314 }
315 else {
316 909 $m = _monthabbrev_number($m);
317 }
318  
319 1608 ▶ $filesize = 0 if $filesize eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $filesize eq "-" 933 675 1608
320 1608 ▶ if ($filesize =~ s/k$//i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($filesize =~ s/k$//i) { } 589 1019 1608
elsif ($filesize =~ s/M$//) { } 10 1009 1019
elsif ($filesize =~ s/G$//) { } 0 1009 1009
321 589 $filesize *= 1024;
322 }
323 elsif ($filesize =~ s/M$//) {
324 10 $filesize *= 1024*1024;
325 }
326 elsif ($filesize =~ s/G$//) {
327 0 $filesize *= 1024*1024*1024;
328 }
329 1608 $filesize = int $filesize;
330  
331 1608 require Time::Local;
332 1608 my $filetime = Time::Local::timelocal(0,$M,$H,$d,$m-1,_guess_year($y));
333 1608 ▶ my $filetype = ($filename =~ s|/$|| ? "d" : "f");
Branch: 1 branch
BranchTrueFalseTotal
$filename =~ s[/$][] ? : 933 675 1608
334 1608 return [$filename, $filetype, $filesize, $filetime, undef];
335 }
336  
337 # the default listing doesn't include timestamps or file sizes
338 # but we don't want to grab navigation links, so we ignore links
339 # that have a non-trailing slash / character or ?
340 elsif(m!<A\s+HREF=\"([^?/\"]+/?)\">.*</A>!i) {
341 23 my $filename = $1;
342 23 ▶ my $filetype = ($filename =~ s|/$|| ? "d" : "f");
Branch: 1 branch
BranchTrueFalseTotal
$filename =~ s[/$][] ? : 6 17 23
343 23 return [$filename, $filetype, undef, undef, undef];
344 }
345  
346 241 return ();
347 }
348  
349  
350 1608 ▶sub _guess_year {
Subroutine _guess_year: called CC=4 SCAR=20.9
351 1608 my $y = shift;
352  
353 # if the year is already four digit then we shouldn't do
354 # anything to modify it.
355 1608 ▶ if ($y >= 1900) {
Branch: 3 branches
BranchTrueFalseTotal
if ($y >= 1900) { } 1608 0 1608
elsif ($y >= 90) { } 0 0 0
elsif ($y < 100) { } 0 0 0
356 # do nothing
357  
358 # TODO: for hysterical er historical reasons we assume 9x is in the
359 # 1990s we should probably not do that, but I don't have any examples
360 # where apache provides two digit dates so I am leaving this as-is
361 # for now. Possibly the right thing is to not handle two digit years.
362 } elsif ($y >= 90) {
363 0 $y = 1900+$y;
364 }
365  
366 # TODO: likewise assuming 00-89 are 20xx is long term probably wrong.
367 elsif ($y < 100) {
368 0 $y = 2000+$y;
369 }
370 1608 $y;
371 }
372  
373  
374 909 ▶sub _monthabbrev_number {
Subroutine _monthabbrev_number: called CC=1 SCAR=0.0
375 909 my $mon = shift;
376 +{'Jan' => 1,
377 'Feb' => 2,
378 'Mar' => 3,
379 'Apr' => 4,
380 'May' => 5,
381 'Jun' => 6,
382 'Jul' => 7,
383 'Aug' => 8,
384 'Sep' => 9,
385 'Oct' => 10,
386 'Nov' => 11,
387 'Dec' => 12,
388 909 }->{$mon};
389 }
390  
391  
392 1 1;
393  
394 __END__
↑ Summary