line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::New::Path;
|
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
1691
|
use strict;
|
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
181
|
|
4
|
6
|
|
|
6
|
|
22
|
use warnings;
|
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
135
|
|
5
|
6
|
|
|
6
|
|
20
|
use Carp;
|
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
297
|
|
6
|
6
|
|
|
6
|
|
1625
|
use Path::Tiny ();
|
|
6
|
|
|
|
|
22596
|
|
|
6
|
|
|
|
|
4263
|
|
7
|
|
|
|
|
|
|
|
8
|
19
|
|
|
19
|
1
|
8705
|
sub new { bless { _root => '' }, shift }
|
9
|
|
|
|
|
|
|
|
10
|
412
|
|
|
412
|
|
3193
|
sub _root { shift->{_root} }
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _child {
|
13
|
144
|
|
|
144
|
|
116
|
my $self = shift;
|
14
|
|
|
|
|
|
|
|
15
|
144
|
50
|
|
|
|
153
|
croak "root is not defined; set it first" unless $self->_root;
|
16
|
|
|
|
|
|
|
|
17
|
144
|
|
|
|
|
275
|
my $context = Module::New->context;
|
18
|
144
|
|
|
|
|
312
|
my $subdir = $context->config('subdir');
|
19
|
|
|
|
|
|
|
|
20
|
144
|
100
|
|
|
|
180
|
$self->_root->child(grep {defined && length} $subdir, @_ );
|
|
288
|
|
|
|
|
785
|
|
21
|
|
|
|
|
|
|
}
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub __child {
|
24
|
10
|
|
|
10
|
|
14
|
my $class = shift;
|
25
|
10
|
50
|
|
|
|
31
|
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
|
|
|
|
|
67
|
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
}
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
*file = *dir = \&_child;
|
33
|
|
|
|
|
|
|
*_file = *_dir = \&__child;
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub guess_root {
|
36
|
10
|
|
|
10
|
1
|
2516
|
my ($self, $path) = @_;
|
37
|
|
|
|
|
|
|
|
38
|
10
|
100
|
|
|
|
29
|
if ( defined $path ) {
|
39
|
1
|
|
|
|
|
5
|
my $dir = $self->_dir('.', $path);
|
40
|
1
|
50
|
|
|
|
20
|
$dir->mkpath unless $dir->exists;
|
41
|
1
|
|
|
|
|
189
|
return $self->set_root($dir);
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
|
44
|
9
|
|
|
|
|
15
|
my $try = 30;
|
45
|
9
|
|
|
|
|
28
|
my $dir = $self->_dir('.');
|
46
|
9
|
|
66
|
|
|
211
|
while ( $try-- and $dir->parent ne $dir ) {
|
47
|
42
|
100
|
|
|
|
2024
|
if ( $dir->child('lib')->exists ) {
|
48
|
38
|
100
|
100
|
|
|
1261
|
if ( $dir->child('Makefile.PL')->exists
|
49
|
|
|
|
|
|
|
or $dir->child('Build.PL')->exists
|
50
|
|
|
|
|
|
|
) {
|
51
|
8
|
|
|
|
|
257
|
return $self->set_root($dir);
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
}
|
54
|
34
|
|
|
|
|
2058
|
$dir = $dir->parent;
|
55
|
|
|
|
|
|
|
}
|
56
|
1
|
|
|
|
|
183
|
croak "Can't guess root";
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub set_root {
|
60
|
31
|
|
|
31
|
1
|
886
|
my ($self, $path) = @_;
|
61
|
|
|
|
|
|
|
|
62
|
31
|
|
100
|
|
|
150
|
my $root = $self->{_root} = Path::Tiny::path($path || '.')->absolute;
|
63
|
31
|
50
|
|
|
|
1571
|
croak "$root does not exist" unless $root->exists;
|
64
|
|
|
|
|
|
|
|
65
|
31
|
|
|
|
|
540
|
Module::New->context->log( debug => "set root to $root" );
|
66
|
|
|
|
|
|
|
|
67
|
31
|
|
|
|
|
10618
|
chdir $root;
|
68
|
|
|
|
|
|
|
|
69
|
31
|
|
|
|
|
378
|
return $root;
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub create_dir {
|
73
|
69
|
|
|
69
|
1
|
4046
|
my ($self, $path, $absolute) = @_;
|
74
|
|
|
|
|
|
|
|
75
|
69
|
|
|
|
|
62
|
my $dir;
|
76
|
69
|
50
|
|
|
|
97
|
if ( $absolute ) {
|
77
|
0
|
|
|
|
|
0
|
$dir = $self->_dir($path);
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
else {
|
80
|
69
|
|
|
|
|
113
|
$dir = $self->dir($path);
|
81
|
|
|
|
|
|
|
}
|
82
|
69
|
100
|
|
|
|
1423
|
unless ( $dir->exists ) {
|
83
|
27
|
|
|
|
|
671
|
$dir->mkpath;
|
84
|
27
|
|
|
|
|
4304
|
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
|
93
|
my ($self, %files) = @_;
|
106
|
|
|
|
|
|
|
|
107
|
59
|
50
|
|
|
|
120
|
croak "root is not defined; set it first" unless $self->_root;
|
108
|
|
|
|
|
|
|
|
109
|
59
|
|
|
|
|
185
|
my $context = Module::New->context;
|
110
|
|
|
|
|
|
|
|
111
|
59
|
|
|
|
|
156
|
foreach my $path ( sort keys %files ) {
|
112
|
64
|
50
|
|
|
|
230
|
next unless $path;
|
113
|
|
|
|
|
|
|
|
114
|
64
|
|
|
|
|
120
|
my $file = $self->file($path);
|
115
|
64
|
|
|
|
|
1703
|
$self->create_dir( $file->parent->relative( $self->_root ) );
|
116
|
|
|
|
|
|
|
|
117
|
64
|
50
|
|
|
|
1621
|
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
|
|
|
|
|
1176
|
$file->parent->mkpath;
|
131
|
64
|
|
|
|
|
3741
|
$file->spew( $files{$path} );
|
132
|
64
|
|
|
|
|
15898
|
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
|
13
|
my ($self, $path) = @_;
|
149
|
6
|
|
|
|
|
11
|
chdir $self->dir($path);
|
150
|
6
|
|
|
|
|
173
|
Module::New->context->log( info => "changed directory to $path" );
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1;
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__
|