line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::DirObject::Dir; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
91074
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
124
|
|
4
|
4
|
|
|
4
|
|
26
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
132
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1927
|
use File::stat; |
|
4
|
|
|
|
|
37625
|
|
|
4
|
|
|
|
|
22
|
|
7
|
4
|
|
|
4
|
|
284
|
use Cwd; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
277
|
|
8
|
4
|
|
|
4
|
|
1555
|
use File::DirObject::File; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
3186
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
15
|
|
|
15
|
0
|
2831
|
my ($class, $dirname) = @_; |
12
|
15
|
|
66
|
|
|
16063
|
$dirname = $dirname || cwd; |
13
|
15
|
|
|
|
|
78
|
chomp $dirname; |
14
|
|
|
|
|
|
|
|
15
|
15
|
|
|
|
|
56
|
my $first = substr $dirname, 0, 1; |
16
|
15
|
|
|
|
|
50
|
my $last = substr $dirname, -1, 1; |
17
|
|
|
|
|
|
|
|
18
|
15
|
50
|
|
|
|
80
|
if ($first ne '/') { |
19
|
0
|
|
|
|
|
0
|
$dirname = cwd . '/' . $dirname; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
15
|
100
|
|
|
|
69
|
if ($last eq '/') { |
23
|
5
|
|
|
|
|
17
|
$dirname = substr $dirname, 0, -1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
15
|
|
|
|
|
82
|
my $self = {'dirname', $dirname}; |
27
|
15
|
|
|
|
|
55
|
bless $self, $class; |
28
|
15
|
|
|
|
|
105
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub path { |
32
|
10
|
|
|
10
|
0
|
25
|
my $self = shift; |
33
|
10
|
|
|
|
|
42
|
return $self->name . '/'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub parent_dir { |
37
|
5
|
|
|
5
|
0
|
854
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
26
|
my @parts = split /\//, $self->full_path; |
40
|
5
|
|
|
|
|
51
|
return File::DirObject::Dir->new(join('/', @parts[0 .. $#parts - 1]) . '/'); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub name { |
44
|
14
|
|
|
14
|
0
|
31
|
my $self = shift; |
45
|
14
|
|
|
|
|
30
|
my @parts = split /\//, ${$self}{'dirname'}; |
|
14
|
|
|
|
|
74
|
|
46
|
14
|
|
|
|
|
86
|
return $parts[-1]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub full_path { |
50
|
72
|
|
|
72
|
0
|
157
|
my $self = shift; |
51
|
72
|
|
|
|
|
126
|
return ${$self}{'dirname'} . '/'; |
|
72
|
|
|
|
|
79710
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub items { |
55
|
4
|
|
|
4
|
0
|
16
|
my $self = shift; |
56
|
4
|
|
|
|
|
12
|
my $dir; |
57
|
|
|
|
|
|
|
|
58
|
4
|
50
|
|
|
|
36
|
opendir $dir, ${$self}{'dirname'} or die "Error reading directory."; |
|
4
|
|
|
|
|
285
|
|
59
|
4
|
|
|
|
|
193
|
return sort {$a cmp $b} readdir $dir; |
|
140
|
|
|
|
|
317
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub contains_file { |
63
|
0
|
|
|
0
|
0
|
0
|
my ($self, $name) = @_; |
64
|
0
|
|
|
|
|
0
|
my $r = 0; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
foreach ($self->files) { |
67
|
0
|
0
|
|
|
|
0
|
if ($_->name eq $name) { |
68
|
0
|
|
|
|
|
0
|
$r = 1; |
69
|
0
|
|
|
|
|
0
|
last; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
return $r; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub contains_dir { |
77
|
1
|
|
|
1
|
0
|
6
|
my ($self, $name) = @_; |
78
|
1
|
|
|
|
|
4
|
my $r = 0; |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
6
|
foreach ($self->dirs) { |
81
|
1
|
50
|
|
|
|
6
|
if ($_->name eq $name) { |
82
|
1
|
|
|
|
|
3
|
$r = 1; |
83
|
1
|
|
|
|
|
3
|
last; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
24
|
return $r; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub files { |
91
|
2
|
|
|
2
|
0
|
29
|
my $self = shift; |
92
|
2
|
|
|
|
|
8
|
my @output = (); |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
20
|
foreach ($self->items) { |
95
|
32
|
100
|
100
|
|
|
190
|
if ($_ eq "." or $_ eq "..") { next; } |
|
4
|
|
|
|
|
11
|
|
96
|
28
|
|
|
|
|
85
|
my $target = $self->full_path . $_; |
97
|
28
|
|
|
|
|
115
|
stat $target; |
98
|
|
|
|
|
|
|
|
99
|
28
|
100
|
|
|
|
5427
|
if (!-d $target) { |
100
|
20
|
|
|
|
|
108
|
push @output, File::DirObject::File->new($self, $target); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
23
|
return @output; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub dirs { |
108
|
2
|
|
|
2
|
0
|
7
|
my $self = shift; |
109
|
2
|
|
|
|
|
6
|
my @output = (); |
110
|
|
|
|
|
|
|
|
111
|
2
|
|
|
|
|
7
|
foreach ($self->items) { |
112
|
19
|
100
|
100
|
|
|
121
|
if ($_ eq "." or $_ eq "..") { next; } |
|
4
|
|
|
|
|
11
|
|
113
|
15
|
|
|
|
|
50
|
my $target = $self->full_path . $_; |
114
|
15
|
|
|
|
|
72
|
stat $target; |
115
|
|
|
|
|
|
|
|
116
|
15
|
100
|
|
|
|
3230
|
if (-d $target) { |
117
|
5
|
|
|
|
|
35
|
push @output, File::DirObject::Dir->new($target); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
|
|
39
|
return @output; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub is_cwd { |
125
|
22
|
|
|
22
|
0
|
68
|
my $self = shift; |
126
|
22
|
|
|
|
|
137
|
return (substr $self->full_path, 0, -1) eq cwd; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|