line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Util::DirTreeBuilder; |
3
|
10
|
|
|
10
|
|
50
|
use strict; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
298
|
|
4
|
10
|
|
|
10
|
|
51
|
use warnings qw(FATAL all NONFATAL misc); |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
405
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
49
|
use base qw(YATT::Class::Configurable File::Spec); |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
5296
|
|
7
|
10
|
|
|
10
|
|
56
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
10
|
|
|
|
|
403
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(tmpbuilder); |
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
4733
|
use YATT::Fields qw(^cf_DIR cf_TESTNO cf_AUTO_REMOVE); |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
67
|
|
11
|
10
|
|
|
10
|
|
52
|
use overload '&{}' => 'as_sub'; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
110
|
|
12
|
10
|
|
|
10
|
|
8068
|
use File::Remove qw(remove); |
|
10
|
|
|
|
|
20063
|
|
|
10
|
|
|
|
|
631
|
|
13
|
10
|
|
|
10
|
|
58
|
use Carp; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
7327
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub tmpbuilder { |
16
|
3
|
|
|
3
|
0
|
763
|
my ($tmpdir) = @_; |
17
|
3
|
100
|
|
|
|
104
|
unless (-d $tmpdir) { |
18
|
2
|
50
|
|
|
|
233
|
mkdir $tmpdir or die "Can't mkdir $tmpdir: $!"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
MY->new(DIR => $tmpdir, TESTNO => 0 |
21
|
3
|
|
|
|
|
51
|
, AUTO_REMOVE => !$ENV{DEBUG_TMP}); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub DESTROY { |
25
|
3
|
|
|
3
|
|
2746
|
my MY $self = shift; |
26
|
3
|
50
|
|
|
|
40
|
remove \1, $self->{cf_DIR} if $self->{cf_AUTO_REMOVE}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub as_sub { |
30
|
20
|
|
|
20
|
0
|
4123
|
my MY $self = shift; |
31
|
20
|
|
|
|
|
227
|
my $basedir = $self->{cf_DIR} . '/t' . ++$self->{cf_TESTNO}; |
32
|
20
|
50
|
|
|
|
930
|
unless (-d $basedir) { |
33
|
20
|
50
|
|
|
|
6510840
|
mkdir $basedir or die "Can't mkdir $basedir! $!"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
sub { |
36
|
181
|
|
|
181
|
|
633
|
$self->build($basedir, @_); |
37
|
181
|
50
|
|
|
|
541
|
if (wantarray) { |
38
|
|
|
|
|
|
|
($basedir, sub { |
39
|
0
|
|
|
|
|
0
|
$self->build($basedir, [FILE => @_]) |
40
|
0
|
|
|
|
|
0
|
}); |
41
|
|
|
|
|
|
|
} else { |
42
|
181
|
|
|
|
|
548
|
$basedir; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
20
|
|
|
|
|
225
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub build { |
48
|
411
|
|
|
411
|
0
|
1063
|
my ($self, $basedir, @action) = @_; |
49
|
411
|
|
|
|
|
850
|
foreach my $action (@action) { |
50
|
413
|
50
|
|
|
|
1758
|
next unless ref $action eq 'ARRAY'; |
51
|
413
|
50
|
|
|
|
2329
|
my $sub = $self->can("build_" . $action->[0]) |
52
|
|
|
|
|
|
|
or die "Invalid builder spec: $action->[0]"; |
53
|
413
|
|
|
|
|
995
|
$sub->($self, $basedir, @{$action}[1 .. $#$action]); |
|
413
|
|
|
|
|
1207
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub build_DIR { |
58
|
230
|
|
|
230
|
0
|
565
|
my ($self, $basedir, $name, @action) = @_; |
59
|
230
|
|
|
|
|
551
|
my $dir = "$basedir/$name"; |
60
|
230
|
100
|
|
|
|
5027
|
unless (-d $dir) { |
61
|
44
|
50
|
|
|
|
4191
|
mkdir($dir) or die "Can't mkdir $dir: $!"; |
62
|
|
|
|
|
|
|
} |
63
|
230
|
|
|
|
|
721
|
$self->build($dir, @action); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub build_FILE { |
67
|
183
|
|
|
183
|
0
|
446
|
my ($self, $basedir, $name, @body) = @_; |
68
|
183
|
|
|
|
|
401
|
my $fn = "$basedir/$name"; |
69
|
183
|
50
|
|
|
|
15401
|
open(my $out, '>', $fn), "file $fn" or die "Can't create $fn: $!"; |
70
|
183
|
|
|
|
|
9999
|
print $out @body; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub path2desc { |
74
|
159
|
|
|
159
|
0
|
337
|
my ($self, $path, $content) = @_; |
75
|
159
|
|
|
|
|
1138
|
$self->path2desc_1([$self->splitdir($path), $content]); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub path2desc_1 { |
79
|
357
|
|
|
357
|
0
|
566
|
my ($self, $desc) = @_; |
80
|
357
|
100
|
|
|
|
780
|
if (@$desc > 2) { |
81
|
198
|
|
|
|
|
505
|
[DIR => shift @$desc |
82
|
|
|
|
|
|
|
, $self->path2desc_1($desc)]; |
83
|
|
|
|
|
|
|
} else { |
84
|
159
|
|
|
|
|
364
|
unshift @$desc, 'FILE'; |
85
|
159
|
|
|
|
|
789
|
$desc; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |