line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::ShareDir::Dist::Install; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
70210
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
5
|
2
|
|
|
2
|
|
39
|
use 5.008001; |
|
2
|
|
|
|
|
7
|
|
6
|
2
|
|
|
2
|
|
11
|
use base qw( Exporter ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
246
|
|
7
|
2
|
|
|
2
|
|
14
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
149
|
|
8
|
2
|
|
|
2
|
|
13
|
use File::Spec; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1842
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw( install install_dir install_config_get install_config_set ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Install per-dist shared files |
13
|
|
|
|
|
|
|
our $VERSION = '0.07'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub install_dir |
17
|
|
|
|
|
|
|
{ |
18
|
29
|
|
|
29
|
1
|
12791
|
my($dist_name) = @_; |
19
|
29
|
100
|
|
|
|
359
|
croak "Not a valid dist_name: undef" unless defined $dist_name; |
20
|
27
|
100
|
|
|
|
368
|
croak "Not a valid dist_name: $dist_name" unless $dist_name =~ /^[A-Za-z0-9_][A-Za-z0-9_-]*$/; |
21
|
25
|
|
|
|
|
1777
|
"blib/lib/auto/share/dist/$dist_name"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _mkpath |
26
|
|
|
|
|
|
|
{ |
27
|
5
|
|
|
5
|
|
10
|
my($dist_name) = @_; |
28
|
5
|
|
|
|
|
23
|
require File::Path; |
29
|
5
|
|
|
|
|
11
|
File::Path::mkpath(install_dir($dist_name), { verbose => 0, mode => 0755 }); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub install |
33
|
|
|
|
|
|
|
{ |
34
|
6
|
|
|
6
|
1
|
10781
|
my($source_dir, $dist_name) = @_; |
35
|
6
|
100
|
66
|
|
|
36
|
($source_dir, $dist_name) = @ARGV unless defined $source_dir || defined $dist_name; |
36
|
6
|
100
|
|
|
|
136
|
croak "No such directory: undef" unless defined $source_dir; |
37
|
5
|
100
|
|
|
|
218
|
croak "No such directory: $source_dir" unless -d $source_dir; |
38
|
4
|
|
|
|
|
16
|
my $dest_dir = install_dir $dist_name; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Can I just say... |
41
|
|
|
|
|
|
|
# File::Find has a terrible terrible terrible interface. |
42
|
2
|
|
|
|
|
6
|
my @files = do { |
43
|
2
|
|
|
|
|
18
|
require Cwd; |
44
|
2
|
|
|
|
|
8
|
require File::Find; |
45
|
2
|
|
|
|
|
24
|
my $save = Cwd::getcwd(); |
46
|
2
|
50
|
|
|
|
25
|
chdir($source_dir) || die "unable to chdir $source_dir"; |
47
|
2
|
|
|
|
|
6
|
my @list; |
48
|
|
|
|
|
|
|
File::Find::find(sub { |
49
|
8
|
100
|
|
8
|
|
440
|
return unless -f $_; |
50
|
4
|
|
|
|
|
140
|
push @list, $File::Find::name; |
51
|
2
|
|
|
|
|
175
|
}, File::Spec->curdir); |
52
|
2
|
|
|
|
|
26
|
chdir $save; |
53
|
2
|
|
|
|
|
12
|
@list; |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
13
|
require File::Basename; |
57
|
2
|
|
|
|
|
8
|
require File::Path; |
58
|
2
|
|
|
|
|
528
|
require File::Copy; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
2425
|
foreach my $file (@files) |
61
|
|
|
|
|
|
|
{ |
62
|
4
|
|
|
|
|
764
|
my $from = File::Spec->catfile($source_dir, $file); |
63
|
4
|
|
|
|
|
27
|
my $to = File::Spec->catfile($dest_dir, $file); |
64
|
4
|
|
|
|
|
147
|
my $dir = File::Basename::dirname($to); |
65
|
4
|
|
|
|
|
1219
|
File::Path::mkpath($dir, { verbose => 0, mode => 0755 }); |
66
|
4
|
50
|
|
|
|
30
|
File::Copy::cp($from, $to) || die "Copy failed $from => $to: $!"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub install_config_get |
72
|
|
|
|
|
|
|
{ |
73
|
9
|
|
|
9
|
1
|
1257
|
my($dist_name) = @_; |
74
|
9
|
|
|
|
|
24
|
my $fn = File::Spec->catfile(install_dir($dist_name), 'config.pl'); |
75
|
9
|
100
|
|
|
|
165
|
if(-e $fn) |
76
|
|
|
|
|
|
|
{ |
77
|
6
|
|
|
|
|
42
|
my $fh; |
78
|
6
|
50
|
|
|
|
224
|
open($fh, '<', $fn) || die "error reading $fn $!"; |
79
|
6
|
|
|
|
|
17
|
my $pl = do { local $/; <$fh> }; |
|
6
|
|
|
|
|
32
|
|
|
6
|
|
|
|
|
136
|
|
80
|
6
|
|
|
|
|
61
|
close $fh; |
81
|
6
|
|
|
|
|
431
|
my $config = eval $pl; |
82
|
6
|
50
|
|
|
|
25
|
die $@ if $@; |
83
|
6
|
|
|
|
|
34
|
return $config; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else |
86
|
|
|
|
|
|
|
{ |
87
|
3
|
|
|
|
|
13
|
return {}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub install_config_set; |
93
|
|
|
|
|
|
|
sub install_config_set |
94
|
|
|
|
|
|
|
{ |
95
|
8
|
|
|
8
|
1
|
2197
|
my($dist_name, $one, $two) = @_; |
96
|
8
|
100
|
66
|
|
|
37
|
($dist_name, $one, $two) = @ARGV unless defined $dist_name && defined $one; |
97
|
8
|
100
|
|
|
|
22
|
if(defined $two) |
98
|
|
|
|
|
|
|
{ |
99
|
3
|
|
|
|
|
8
|
my($key, $value) = ($one, $two); |
100
|
3
|
|
|
|
|
7
|
my $config = install_config_get $dist_name; |
101
|
3
|
|
|
|
|
11
|
$config->{$key} = $value; |
102
|
3
|
|
|
|
|
12
|
return install_config_set $dist_name, $config; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else |
105
|
|
|
|
|
|
|
{ |
106
|
5
|
|
|
|
|
10
|
my($config) = ($one); |
107
|
5
|
50
|
|
|
|
13
|
croak "config is not a hash!" unless ref $config eq 'HASH'; |
108
|
5
|
|
|
|
|
669
|
require Data::Dumper; |
109
|
5
|
|
|
|
|
6866
|
my $dd = Data::Dumper |
110
|
|
|
|
|
|
|
->new([$config],['x']) |
111
|
|
|
|
|
|
|
->Indent(1) |
112
|
|
|
|
|
|
|
->Terse(0) |
113
|
|
|
|
|
|
|
->Purity(1) |
114
|
|
|
|
|
|
|
->Sortkeys(1) |
115
|
|
|
|
|
|
|
->Dump; |
116
|
5
|
|
|
|
|
370
|
my $fh; |
117
|
5
|
|
|
|
|
21
|
_mkpath($dist_name); |
118
|
5
|
|
|
|
|
29
|
my $fn = File::Spec->catfile(install_dir($dist_name), 'config.pl'); |
119
|
5
|
50
|
|
|
|
325
|
open($fh, '>', $fn) || die "error writing $fn $!"; |
120
|
5
|
|
|
|
|
68
|
print $fh 'do { my '; |
121
|
5
|
|
|
|
|
16
|
print $fh $dd; |
122
|
5
|
|
|
|
|
9
|
print $fh '$x;}'; |
123
|
5
|
|
|
|
|
279
|
close $fh; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |