line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::New::Path; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
1025
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
216
|
|
4
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
152
|
|
5
|
6
|
|
|
6
|
|
24
|
use Carp; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
325
|
|
6
|
6
|
|
|
6
|
|
675
|
use Path::Tiny (); |
|
6
|
|
|
|
|
11766
|
|
|
6
|
|
|
|
|
5406
|
|
7
|
|
|
|
|
|
|
|
8
|
19
|
|
|
19
|
1
|
9933
|
sub new { bless { _root => '' }, shift } |
9
|
|
|
|
|
|
|
|
10
|
412
|
|
|
412
|
|
5363
|
sub _root { shift->{_root} } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _child { |
13
|
144
|
|
|
144
|
|
187
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
144
|
50
|
|
|
|
242
|
croak "root is not defined; set it first" unless $self->_root; |
16
|
|
|
|
|
|
|
|
17
|
144
|
|
|
|
|
465
|
my $context = Module::New->context; |
18
|
144
|
|
|
|
|
461
|
my $subdir = $context->config('subdir'); |
19
|
|
|
|
|
|
|
|
20
|
144
|
100
|
|
|
|
267
|
$self->_root->child(grep {defined && length} $subdir, @_ ); |
|
288
|
|
|
|
|
1326
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub __child { |
24
|
10
|
|
|
10
|
|
14
|
my $class = shift; |
25
|
10
|
50
|
|
|
|
61
|
if (ref $_[0] eq 'Path::Tiny') { |
26
|
0
|
0
|
|
|
|
0
|
shift->child(grep {defined && length} @_); |
|
0
|
|
|
|
|
0
|
|
27
|
|
|
|
|
|
|
} else { |
28
|
10
|
50
|
|
|
|
24
|
Path::Tiny::path(grep {defined && length} @_); |
|
11
|
|
|
|
|
78
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
*file = *dir = \&_child; |
33
|
|
|
|
|
|
|
*_file = *_dir = \&__child; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub guess_root { |
36
|
10
|
|
|
10
|
1
|
3132
|
my ($self, $path) = @_; |
37
|
|
|
|
|
|
|
|
38
|
10
|
100
|
|
|
|
32
|
if ( defined $path ) { |
39
|
1
|
|
|
|
|
4
|
my $dir = $self->_dir('.', $path); |
40
|
1
|
50
|
|
|
|
24
|
$dir->mkpath unless $dir->exists; |
41
|
1
|
|
|
|
|
173
|
return $self->set_root($dir); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
9
|
|
|
|
|
15
|
my $try = 30; |
45
|
9
|
|
|
|
|
30
|
my $dir = $self->_dir('.'); |
46
|
9
|
|
66
|
|
|
255
|
while ( $try-- and $dir->parent ne $dir ) { |
47
|
42
|
100
|
|
|
|
2633
|
if ( $dir->child('lib')->exists ) { |
48
|
38
|
100
|
100
|
|
|
1624
|
if ( $dir->child('Makefile.PL')->exists |
49
|
|
|
|
|
|
|
or $dir->child('Build.PL')->exists |
50
|
|
|
|
|
|
|
) { |
51
|
8
|
|
|
|
|
272
|
return $self->set_root($dir); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
34
|
|
|
|
|
2463
|
$dir = $dir->parent; |
55
|
|
|
|
|
|
|
} |
56
|
1
|
|
|
|
|
236
|
croak "Can't guess root"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub set_root { |
60
|
31
|
|
|
31
|
1
|
1439
|
my ($self, $path) = @_; |
61
|
|
|
|
|
|
|
|
62
|
31
|
|
100
|
|
|
199
|
my $root = $self->{_root} = Path::Tiny::path($path || '.')->absolute; |
63
|
31
|
50
|
|
|
|
2162
|
croak "$root does not exist" unless $root->exists; |
64
|
|
|
|
|
|
|
|
65
|
31
|
|
|
|
|
836
|
Module::New->context->log( debug => "set root to $root" ); |
66
|
|
|
|
|
|
|
|
67
|
31
|
|
|
|
|
13560
|
chdir $root; |
68
|
|
|
|
|
|
|
|
69
|
31
|
|
|
|
|
506
|
return $root; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub create_dir { |
73
|
69
|
|
|
69
|
1
|
6506
|
my ($self, $path, $absolute) = @_; |
74
|
|
|
|
|
|
|
|
75
|
69
|
|
|
|
|
169
|
my $dir; |
76
|
69
|
50
|
|
|
|
179
|
if ( $absolute ) { |
77
|
0
|
|
|
|
|
0
|
$dir = $self->_dir($path); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
69
|
|
|
|
|
199
|
$dir = $self->dir($path); |
81
|
|
|
|
|
|
|
} |
82
|
69
|
100
|
|
|
|
2276
|
unless ( $dir->exists ) { |
83
|
27
|
|
|
|
|
1076
|
$dir->mkpath; |
84
|
27
|
|
|
|
|
5893
|
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
|
151
|
my ($self, %files) = @_; |
106
|
|
|
|
|
|
|
|
107
|
59
|
50
|
|
|
|
229
|
croak "root is not defined; set it first" unless $self->_root; |
108
|
|
|
|
|
|
|
|
109
|
59
|
|
|
|
|
270
|
my $context = Module::New->context; |
110
|
|
|
|
|
|
|
|
111
|
59
|
|
|
|
|
238
|
foreach my $path ( sort keys %files ) { |
112
|
64
|
50
|
|
|
|
379
|
next unless $path; |
113
|
|
|
|
|
|
|
|
114
|
64
|
|
|
|
|
211
|
my $file = $self->file($path); |
115
|
64
|
|
|
|
|
3066
|
$self->create_dir( $file->parent->relative( $self->_root ) ); |
116
|
|
|
|
|
|
|
|
117
|
64
|
50
|
|
|
|
2697
|
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
|
|
|
|
|
1804
|
$file->parent->mkpath; |
131
|
64
|
|
|
|
|
5828
|
$file->spew( $files{$path} ); |
132
|
64
|
|
|
|
|
24093
|
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
|
12
|
my ($self, $path) = @_; |
149
|
6
|
|
|
|
|
15
|
chdir $self->dir($path); |
150
|
6
|
|
|
|
|
221
|
Module::New->context->log( info => "changed directory to $path" ); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |