line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Util::DirTreeBuilder; |
3
|
10
|
|
|
10
|
|
36
|
use strict; |
|
10
|
|
|
|
|
12
|
|
|
10
|
|
|
|
|
297
|
|
4
|
10
|
|
|
10
|
|
32
|
use warnings FATAL => qw(all); |
|
10
|
|
|
|
|
13
|
|
|
10
|
|
|
|
|
286
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
32
|
use base qw(YATT::Class::Configurable File::Spec); |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
2874
|
|
7
|
10
|
|
|
10
|
|
44
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
10
|
|
|
|
|
266
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(tmpbuilder); |
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
2624
|
use YATT::Fields qw(^cf_DIR cf_TESTNO cf_AUTO_REMOVE); |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
46
|
|
11
|
10
|
|
|
10
|
|
40
|
use overload '&{}' => 'as_sub'; |
|
10
|
|
|
|
|
10
|
|
|
10
|
|
|
|
|
87
|
|
12
|
10
|
|
|
10
|
|
4354
|
use File::Remove qw(remove); |
|
10
|
|
|
|
|
13108
|
|
|
10
|
|
|
|
|
481
|
|
13
|
10
|
|
|
10
|
|
41
|
use Carp; |
|
10
|
|
|
|
|
11
|
|
|
10
|
|
|
|
|
4393
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub tmpbuilder { |
16
|
3
|
|
|
3
|
0
|
488
|
my ($tmpdir) = @_; |
17
|
3
|
100
|
|
|
|
50
|
unless (-d $tmpdir) { |
18
|
2
|
50
|
|
|
|
184
|
mkdir $tmpdir or die "Can't mkdir $tmpdir: $!"; |
19
|
|
|
|
|
|
|
} |
20
|
3
|
|
|
|
|
40
|
MY->new(DIR => $tmpdir, TESTNO => 0 |
21
|
|
|
|
|
|
|
, AUTO_REMOVE => !$ENV{DEBUG_TMP}); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub DESTROY { |
25
|
3
|
|
|
3
|
|
1628
|
my MY $self = shift; |
26
|
3
|
50
|
|
|
|
28
|
remove \1, $self->{cf_DIR} if $self->{cf_AUTO_REMOVE}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub as_sub { |
30
|
20
|
|
|
20
|
0
|
1523
|
my MY $self = shift; |
31
|
20
|
|
|
|
|
226
|
my $basedir = $self->{cf_DIR} . '/t' . ++$self->{cf_TESTNO}; |
32
|
20
|
50
|
|
|
|
729
|
unless (-d $basedir) { |
33
|
20
|
50
|
|
|
|
1519
|
mkdir $basedir or die "Can't mkdir $basedir! $!"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
sub { |
36
|
181
|
|
|
181
|
|
432
|
$self->build($basedir, @_); |
37
|
181
|
50
|
|
|
|
327
|
if (wantarray) { |
38
|
|
|
|
|
|
|
($basedir, sub { |
39
|
0
|
|
|
|
|
0
|
$self->build($basedir, [FILE => @_]) |
40
|
0
|
|
|
|
|
0
|
}); |
41
|
|
|
|
|
|
|
} else { |
42
|
181
|
|
|
|
|
336
|
$basedir; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
20
|
|
|
|
|
136
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub build { |
48
|
411
|
|
|
411
|
0
|
466
|
my ($self, $basedir, @action) = @_; |
49
|
411
|
|
|
|
|
435
|
foreach my $action (@action) { |
50
|
413
|
50
|
|
|
|
653
|
next unless ref $action eq 'ARRAY'; |
51
|
413
|
50
|
|
|
|
1367
|
my $sub = $self->can("build_" . $action->[0]) |
52
|
|
|
|
|
|
|
or die "Invalid builder spec: $action->[0]"; |
53
|
413
|
|
|
|
|
574
|
$sub->($self, $basedir, @{$action}[1 .. $#$action]); |
|
413
|
|
|
|
|
572
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub build_DIR { |
58
|
230
|
|
|
230
|
0
|
265
|
my ($self, $basedir, $name, @action) = @_; |
59
|
230
|
|
|
|
|
300
|
my $dir = "$basedir/$name"; |
60
|
230
|
100
|
|
|
|
2530
|
unless (-d $dir) { |
61
|
44
|
50
|
|
|
|
1435
|
mkdir($dir) or die "Can't mkdir $dir: $!"; |
62
|
|
|
|
|
|
|
} |
63
|
230
|
|
|
|
|
417
|
$self->build($dir, @action); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub build_FILE { |
67
|
183
|
|
|
183
|
0
|
230
|
my ($self, $basedir, $name, @body) = @_; |
68
|
183
|
|
|
|
|
226
|
my $fn = "$basedir/$name"; |
69
|
183
|
50
|
|
|
|
8728
|
open(my $out, '>', $fn), "file $fn" or die "Can't create $fn: $!"; |
70
|
183
|
|
|
|
|
5423
|
print $out @body; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub path2desc { |
74
|
159
|
|
|
159
|
0
|
162
|
my ($self, $path, $content) = @_; |
75
|
159
|
|
|
|
|
640
|
$self->path2desc_1([$self->splitdir($path), $content]); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub path2desc_1 { |
79
|
357
|
|
|
357
|
0
|
267
|
my ($self, $desc) = @_; |
80
|
357
|
100
|
|
|
|
449
|
if (@$desc > 2) { |
81
|
198
|
|
|
|
|
270
|
[DIR => shift @$desc |
82
|
|
|
|
|
|
|
, $self->path2desc_1($desc)]; |
83
|
|
|
|
|
|
|
} else { |
84
|
159
|
|
|
|
|
203
|
unshift @$desc, 'FILE'; |
85
|
159
|
|
|
|
|
372
|
$desc; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |