| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::TreeCreate; |
|
2
|
|
|
|
|
|
|
$File::TreeCreate::VERSION = '0.0.1'; |
|
3
|
1
|
|
|
1
|
|
71398
|
use autodie; |
|
|
1
|
|
|
|
|
16174
|
|
|
|
1
|
|
|
|
|
5
|
|
|
4
|
1
|
|
|
1
|
|
6796
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
18
|
|
|
5
|
1
|
|
|
1
|
|
15
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use File::Spec (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
946
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new |
|
11
|
|
|
|
|
|
|
{ |
|
12
|
2
|
|
|
2
|
1
|
623
|
my $class = shift; |
|
13
|
2
|
|
|
|
|
5
|
my $self = {}; |
|
14
|
2
|
|
|
|
|
5
|
bless $self, $class; |
|
15
|
2
|
|
|
|
|
7
|
$self->_init(@_); |
|
16
|
2
|
|
|
|
|
6
|
return $self; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _init |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
2
|
|
|
2
|
|
3
|
return; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub get_path |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
29
|
|
|
29
|
1
|
604
|
my $self = shift; |
|
27
|
29
|
|
|
|
|
55
|
my $path = shift; |
|
28
|
|
|
|
|
|
|
|
|
29
|
29
|
|
|
|
|
43
|
my @components; |
|
30
|
|
|
|
|
|
|
|
|
31
|
29
|
100
|
|
|
|
181
|
if ( $path =~ s{^\./}{} ) |
|
32
|
|
|
|
|
|
|
{ |
|
33
|
28
|
|
|
|
|
129
|
push @components, File::Spec->curdir(); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
29
|
|
|
|
|
71
|
my $is_dir = ( $path =~ s{/$}{} ); |
|
37
|
29
|
|
|
|
|
89
|
push @components, split( /\//, $path ); |
|
38
|
29
|
100
|
|
|
|
71
|
if ($is_dir) |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
3
|
|
|
|
|
38
|
return File::Spec->catdir(@components); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
else |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
26
|
|
|
|
|
2391
|
return File::Spec->catfile(@components); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub exist |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
2
|
|
|
2
|
1
|
17
|
my $self = shift; |
|
51
|
2
|
|
|
|
|
8
|
return ( -e $self->get_path(@_) ); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub is_file |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
|
57
|
3
|
|
|
|
|
9
|
return ( -f $self->get_path(@_) ); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub is_dir |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
4
|
|
|
4
|
1
|
9
|
my $self = shift; |
|
63
|
4
|
|
|
|
|
10
|
return ( -d $self->get_path(@_) ); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub cat |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
|
69
|
2
|
50
|
|
|
|
7
|
open my $in, "<", $self->get_path(@_) |
|
70
|
|
|
|
|
|
|
or Carp::confess("cat failed!"); |
|
71
|
2
|
|
|
|
|
2842
|
my $data; |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
2
|
|
|
|
|
3
|
local $/; |
|
|
2
|
|
|
|
|
8
|
|
|
74
|
2
|
|
|
|
|
56
|
$data = <$in>; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
2
|
|
|
|
|
17
|
close($in); |
|
77
|
2
|
|
|
|
|
1043
|
return $data; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub ls |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
5
|
|
|
5
|
1
|
56
|
my $self = shift; |
|
83
|
5
|
50
|
|
|
|
14
|
opendir my $dir, $self->get_path(@_) |
|
84
|
|
|
|
|
|
|
or Carp::confess("opendir failed!"); |
|
85
|
|
|
|
|
|
|
my @files = |
|
86
|
5
|
|
|
|
|
1116
|
sort { $a cmp $b } File::Spec->no_upwards( readdir($dir) ); |
|
|
8
|
|
|
|
|
20
|
|
|
87
|
5
|
|
|
|
|
25
|
closedir($dir); |
|
88
|
5
|
|
|
|
|
819
|
return \@files; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub create_tree |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
1
|
|
|
1
|
1
|
23
|
my ( $self, $unix_init_path, $tree ) = @_; |
|
94
|
1
|
|
|
|
|
3
|
my $real_init_path = $self->get_path($unix_init_path); |
|
95
|
1
|
|
|
|
|
4
|
return $self->_real_create_tree( $real_init_path, $tree ); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _real_create_tree |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
5
|
|
|
5
|
|
14
|
my ( $self, $init_path, $tree ) = @_; |
|
101
|
5
|
|
|
|
|
10
|
my $name = $tree->{'name'}; |
|
102
|
5
|
100
|
|
|
|
26
|
if ( $name =~ s{/$}{} ) |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
4
|
|
|
|
|
38
|
my $dir_name = File::Spec->catfile( $init_path, $name ); |
|
105
|
4
|
|
|
|
|
18
|
mkdir($dir_name); |
|
106
|
4
|
100
|
|
|
|
1438
|
if ( exists( $tree->{'subs'} ) ) |
|
107
|
|
|
|
|
|
|
{ |
|
108
|
2
|
|
|
|
|
5
|
foreach my $sub ( @{ $tree->{'subs'} } ) |
|
|
2
|
|
|
|
|
6
|
|
|
109
|
|
|
|
|
|
|
{ |
|
110
|
4
|
|
|
|
|
16
|
$self->_real_create_tree( $dir_name, $sub ); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
else |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
1
|
|
|
|
|
14
|
open my $out, ">", File::Spec->catfile( $init_path, $name ); |
|
117
|
1
|
|
|
|
|
27
|
print {$out} |
|
118
|
1
|
50
|
|
|
|
138
|
+( exists( $tree->{'contents'} ) ? $tree->{'contents'} : "" ); |
|
119
|
1
|
|
|
|
|
7
|
close($out); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
5
|
|
|
|
|
109
|
return; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |