line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::New::Path;
|
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
784
|
use strict;
|
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
153
|
|
4
|
6
|
|
|
6
|
|
18
|
use warnings;
|
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
103
|
|
5
|
6
|
|
|
6
|
|
18
|
use Carp;
|
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
246
|
|
6
|
6
|
|
|
6
|
|
656
|
use Path::Tiny ();
|
|
6
|
|
|
|
|
9791
|
|
|
6
|
|
|
|
|
4119
|
|
7
|
|
|
|
|
|
|
|
8
|
19
|
|
|
19
|
1
|
7953
|
sub new { bless { _root => '' }, shift }
|
9
|
|
|
|
|
|
|
|
10
|
412
|
|
|
412
|
|
3398
|
sub _root { shift->{_root} }
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _child {
|
13
|
144
|
|
|
144
|
|
134
|
my $self = shift;
|
14
|
|
|
|
|
|
|
|
15
|
144
|
50
|
|
|
|
219
|
croak "root is not defined; set it first" unless $self->_root;
|
16
|
|
|
|
|
|
|
|
17
|
144
|
|
|
|
|
309
|
my $context = Module::New->context;
|
18
|
144
|
|
|
|
|
308
|
my $subdir = $context->config('subdir');
|
19
|
|
|
|
|
|
|
|
20
|
144
|
100
|
|
|
|
180
|
$self->_root->child(grep {defined && length} $subdir, @_ );
|
|
288
|
|
|
|
|
846
|
|
21
|
|
|
|
|
|
|
}
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub __child {
|
24
|
10
|
|
|
10
|
|
12
|
my $class = shift;
|
25
|
10
|
50
|
|
|
|
25
|
if (ref $_[0] eq 'Path::Tiny') {
|
26
|
0
|
0
|
|
|
|
0
|
shift->child(grep {defined && length} @_);
|
|
0
|
|
|
|
|
0
|
|
27
|
|
|
|
|
|
|
} else {
|
28
|
10
|
50
|
|
|
|
20
|
Path::Tiny::path(grep {defined && length} @_);
|
|
11
|
|
|
|
|
59
|
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
}
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
*file = *dir = \&_child;
|
33
|
|
|
|
|
|
|
*_file = *_dir = \&__child;
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub guess_root {
|
36
|
10
|
|
|
10
|
1
|
2296
|
my ($self, $path) = @_;
|
37
|
|
|
|
|
|
|
|
38
|
10
|
100
|
|
|
|
27
|
if ( defined $path ) {
|
39
|
1
|
|
|
|
|
4
|
my $dir = $self->_dir('.', $path);
|
40
|
1
|
50
|
|
|
|
18
|
$dir->mkpath unless $dir->exists;
|
41
|
1
|
|
|
|
|
144
|
return $self->set_root($dir);
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
|
44
|
9
|
|
|
|
|
14
|
my $try = 30;
|
45
|
9
|
|
|
|
|
25
|
my $dir = $self->_dir('.');
|
46
|
9
|
|
66
|
|
|
197
|
while ( $try-- and $dir->parent ne $dir ) {
|
47
|
42
|
100
|
|
|
|
1901
|
if ( $dir->child('lib')->exists ) {
|
48
|
38
|
100
|
100
|
|
|
1243
|
if ( $dir->child('Makefile.PL')->exists
|
49
|
|
|
|
|
|
|
or $dir->child('Build.PL')->exists
|
50
|
|
|
|
|
|
|
) {
|
51
|
8
|
|
|
|
|
239
|
return $self->set_root($dir);
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
}
|
54
|
34
|
|
|
|
|
1903
|
$dir = $dir->parent;
|
55
|
|
|
|
|
|
|
}
|
56
|
1
|
|
|
|
|
192
|
croak "Can't guess root";
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub set_root {
|
60
|
31
|
|
|
31
|
1
|
928
|
my ($self, $path) = @_;
|
61
|
|
|
|
|
|
|
|
62
|
31
|
|
100
|
|
|
155
|
my $root = $self->{_root} = Path::Tiny::path($path || '.')->absolute;
|
63
|
31
|
50
|
|
|
|
1572
|
croak "$root does not exist" unless $root->exists;
|
64
|
|
|
|
|
|
|
|
65
|
31
|
|
|
|
|
591
|
Module::New->context->log( debug => "set root to $root" );
|
66
|
|
|
|
|
|
|
|
67
|
31
|
|
|
|
|
9909
|
chdir $root;
|
68
|
|
|
|
|
|
|
|
69
|
31
|
|
|
|
|
413
|
return $root;
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub create_dir {
|
73
|
69
|
|
|
69
|
1
|
4285
|
my ($self, $path, $absolute) = @_;
|
74
|
|
|
|
|
|
|
|
75
|
69
|
|
|
|
|
57
|
my $dir;
|
76
|
69
|
50
|
|
|
|
95
|
if ( $absolute ) {
|
77
|
0
|
|
|
|
|
0
|
$dir = $self->_dir($path);
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
else {
|
80
|
69
|
|
|
|
|
114
|
$dir = $self->dir($path);
|
81
|
|
|
|
|
|
|
}
|
82
|
69
|
100
|
|
|
|
1828
|
unless ( $dir->exists ) {
|
83
|
27
|
|
|
|
|
638
|
$dir->mkpath;
|
84
|
27
|
|
|
|
|
4341
|
Module::New->context->log( info => "created $path" );
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub remove_dir {
|
89
|
0
|
|
|
0
|
1
|
0
|
my ($self, $path, $absolute) = @_;
|
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
my $dir;
|
92
|
0
|
0
|
|
|
|
0
|
if ( $absolute ) {
|
93
|
0
|
|
|
|
|
0
|
$dir = $self->_dir($path);
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
else {
|
96
|
0
|
|
|
|
|
0
|
$dir = $self->dir($path);
|
97
|
|
|
|
|
|
|
}
|
98
|
0
|
0
|
|
|
|
0
|
if ( $dir->exists ) {
|
99
|
0
|
|
|
|
|
0
|
$dir->remove_tree;
|
100
|
0
|
|
|
|
|
0
|
Module::New->context->log( info => "removed $path" );
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub create_file {
|
105
|
59
|
|
|
59
|
1
|
92
|
my ($self, %files) = @_;
|
106
|
|
|
|
|
|
|
|
107
|
59
|
50
|
|
|
|
107
|
croak "root is not defined; set it first" unless $self->_root;
|
108
|
|
|
|
|
|
|
|
109
|
59
|
|
|
|
|
179
|
my $context = Module::New->context;
|
110
|
|
|
|
|
|
|
|
111
|
59
|
|
|
|
|
169
|
foreach my $path ( sort keys %files ) {
|
112
|
64
|
50
|
|
|
|
256
|
next unless $path;
|
113
|
|
|
|
|
|
|
|
114
|
64
|
|
|
|
|
110
|
my $file = $self->file($path);
|
115
|
64
|
|
|
|
|
1698
|
$self->create_dir( $file->parent->relative( $self->_root ) );
|
116
|
|
|
|
|
|
|
|
117
|
64
|
50
|
|
|
|
1575
|
if ( $file->exists ) {
|
118
|
0
|
0
|
|
|
|
0
|
if ( $context->config('grace') ) {
|
|
|
0
|
|
|
|
|
|
119
|
0
|
|
|
|
|
0
|
$file->rename("$file.bak");
|
120
|
0
|
|
|
|
|
0
|
Module::New->context->log( info => "renamed $path to $path.bak" );
|
121
|
|
|
|
|
|
|
}
|
122
|
|
|
|
|
|
|
elsif ( $context->config('force') ) {
|
123
|
|
|
|
|
|
|
# just skip and do nothing
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
else {
|
126
|
0
|
0
|
|
|
|
0
|
next if $file->slurp eq $files{$path};
|
127
|
0
|
|
|
|
|
0
|
Carp::confess "$path already exists";
|
128
|
|
|
|
|
|
|
}
|
129
|
|
|
|
|
|
|
}
|
130
|
64
|
|
|
|
|
1202
|
$file->parent->mkpath;
|
131
|
64
|
|
|
|
|
4028
|
$file->spew( $files{$path} );
|
132
|
64
|
|
|
|
|
15874
|
Module::New->context->log( info => "created $path" );
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
}
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub remove_file {
|
137
|
0
|
|
|
0
|
1
|
0
|
my ($self, @paths) = @_;
|
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
0
|
croak "root is not defined; set it first" unless $self->_root;
|
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
0
|
foreach my $path ( @paths ) {
|
142
|
0
|
|
|
|
|
0
|
$self->file($path)->remove;
|
143
|
0
|
|
|
|
|
0
|
Module::New->context->log( info => "removed $path" );
|
144
|
|
|
|
|
|
|
}
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub change_dir {
|
148
|
6
|
|
|
6
|
1
|
15
|
my ($self, $path) = @_;
|
149
|
6
|
|
|
|
|
12
|
chdir $self->dir($path);
|
150
|
6
|
|
|
|
|
213
|
Module::New->context->log( info => "changed directory to $path" );
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1;
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__
|