line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Util::DirTreeBuilder; |
3
|
10
|
|
|
10
|
|
57
|
use strict; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
322
|
|
4
|
10
|
|
|
10
|
|
50
|
use warnings qw(FATAL all NONFATAL misc); |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
433
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
58
|
use base qw(YATT::Class::Configurable File::Spec); |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
5692
|
|
7
|
10
|
|
|
10
|
|
59
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
10
|
|
|
|
|
421
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(tmpbuilder); |
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
5218
|
use YATT::Fields qw(^cf_DIR cf_TESTNO cf_AUTO_REMOVE); |
|
10
|
|
|
|
|
28
|
|
|
10
|
|
|
|
|
71
|
|
11
|
10
|
|
|
10
|
|
58
|
use overload '&{}' => 'as_sub'; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
124
|
|
12
|
10
|
|
|
10
|
|
8856
|
use File::Remove qw(remove); |
|
10
|
|
|
|
|
21455
|
|
|
10
|
|
|
|
|
643
|
|
13
|
10
|
|
|
10
|
|
63
|
use Carp; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
7760
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub tmpbuilder { |
16
|
3
|
|
|
3
|
0
|
742
|
my ($tmpdir) = @_; |
17
|
3
|
100
|
|
|
|
112
|
unless (-d $tmpdir) { |
18
|
2
|
50
|
|
|
|
237
|
mkdir $tmpdir or die "Can't mkdir $tmpdir: $!"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
MY->new(DIR => $tmpdir, TESTNO => 0 |
21
|
3
|
|
|
|
|
45
|
, AUTO_REMOVE => !$ENV{DEBUG_TMP}); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub DESTROY { |
25
|
3
|
|
|
3
|
|
2429
|
my MY $self = shift; |
26
|
3
|
50
|
|
|
|
38
|
remove \1, $self->{cf_DIR} if $self->{cf_AUTO_REMOVE}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub as_sub { |
30
|
20
|
|
|
20
|
0
|
4229
|
my MY $self = shift; |
31
|
20
|
|
|
|
|
218
|
my $basedir = $self->{cf_DIR} . '/t' . ++$self->{cf_TESTNO}; |
32
|
20
|
50
|
|
|
|
963
|
unless (-d $basedir) { |
33
|
20
|
50
|
|
|
|
168489
|
mkdir $basedir or die "Can't mkdir $basedir! $!"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
sub { |
36
|
181
|
|
|
181
|
|
660
|
$self->build($basedir, @_); |
37
|
181
|
50
|
|
|
|
571
|
if (wantarray) { |
38
|
|
|
|
|
|
|
($basedir, sub { |
39
|
0
|
|
|
|
|
0
|
$self->build($basedir, [FILE => @_]) |
40
|
0
|
|
|
|
|
0
|
}); |
41
|
|
|
|
|
|
|
} else { |
42
|
181
|
|
|
|
|
596
|
$basedir; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
20
|
|
|
|
|
194
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub build { |
48
|
411
|
|
|
411
|
0
|
940
|
my ($self, $basedir, @action) = @_; |
49
|
411
|
|
|
|
|
853
|
foreach my $action (@action) { |
50
|
413
|
50
|
|
|
|
1273
|
next unless ref $action eq 'ARRAY'; |
51
|
413
|
50
|
|
|
|
2307
|
my $sub = $self->can("build_" . $action->[0]) |
52
|
|
|
|
|
|
|
or die "Invalid builder spec: $action->[0]"; |
53
|
413
|
|
|
|
|
1007
|
$sub->($self, $basedir, @{$action}[1 .. $#$action]); |
|
413
|
|
|
|
|
1176
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub build_DIR { |
58
|
230
|
|
|
230
|
0
|
543
|
my ($self, $basedir, $name, @action) = @_; |
59
|
230
|
|
|
|
|
489
|
my $dir = "$basedir/$name"; |
60
|
230
|
100
|
|
|
|
4679
|
unless (-d $dir) { |
61
|
44
|
50
|
|
|
|
1960090
|
mkdir($dir) or die "Can't mkdir $dir: $!"; |
62
|
|
|
|
|
|
|
} |
63
|
230
|
|
|
|
|
707
|
$self->build($dir, @action); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub build_FILE { |
67
|
183
|
|
|
183
|
0
|
482
|
my ($self, $basedir, $name, @body) = @_; |
68
|
183
|
|
|
|
|
404
|
my $fn = "$basedir/$name"; |
69
|
183
|
50
|
|
|
|
15064
|
open(my $out, '>', $fn), "file $fn" or die "Can't create $fn: $!"; |
70
|
183
|
|
|
|
|
9153
|
print $out @body; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub path2desc { |
74
|
159
|
|
|
159
|
0
|
341
|
my ($self, $path, $content) = @_; |
75
|
159
|
|
|
|
|
1166
|
$self->path2desc_1([$self->splitdir($path), $content]); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub path2desc_1 { |
79
|
357
|
|
|
357
|
0
|
575
|
my ($self, $desc) = @_; |
80
|
357
|
100
|
|
|
|
794
|
if (@$desc > 2) { |
81
|
198
|
|
|
|
|
502
|
[DIR => shift @$desc |
82
|
|
|
|
|
|
|
, $self->path2desc_1($desc)]; |
83
|
|
|
|
|
|
|
} else { |
84
|
159
|
|
|
|
|
353
|
unshift @$desc, 'FILE'; |
85
|
159
|
|
|
|
|
819
|
$desc; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |