line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Makefile::Update; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Update make files. |
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
489757
|
use strict; |
|
8
|
|
|
|
|
68
|
|
|
8
|
|
|
|
|
200
|
|
6
|
8
|
|
|
8
|
|
34
|
use warnings; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
201
|
|
7
|
8
|
|
|
8
|
|
34
|
use autodie; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
49
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
36667
|
use Exporter qw(import); |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
6425
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(read_files_list upmake); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.4'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub read_files_list |
18
|
|
|
|
|
|
|
{ |
19
|
1
|
|
|
1
|
1
|
68
|
my ($fh) = @_; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
2
|
my ($var, %vars); |
22
|
1
|
|
|
|
|
6
|
while (<$fh>) { |
23
|
14
|
|
|
|
|
18
|
chomp; |
24
|
14
|
|
|
|
|
22
|
s/#.*$//; |
25
|
14
|
|
|
|
|
24
|
s/^\s+//; |
26
|
14
|
|
|
|
|
21
|
s/\s+$//; |
27
|
14
|
100
|
|
|
|
24
|
next if !$_; |
28
|
|
|
|
|
|
|
|
29
|
9
|
100
|
|
|
|
17
|
if (/^(\w+)\s*=$/) { |
30
|
3
|
|
|
|
|
11
|
$var = $1; |
31
|
|
|
|
|
|
|
} else { |
32
|
6
|
50
|
|
|
|
8
|
die "Unexpected contents outside variable definition at line $.\n" |
33
|
|
|
|
|
|
|
unless defined $var; |
34
|
6
|
100
|
|
|
|
11
|
if (/^\$(\w+)$/) { |
35
|
2
|
|
|
|
|
4
|
my $name = $1; |
36
|
|
|
|
|
|
|
die qq{Reference to undefined variable "$name" in the } . |
37
|
|
|
|
|
|
|
qq{assignment to "$var" at line $.\n} |
38
|
2
|
50
|
|
|
|
4
|
unless exists $vars{$name}; |
39
|
2
|
|
|
|
|
3
|
my $value = $vars{$name}; |
40
|
2
|
|
|
|
|
4
|
push @{$vars{$var}}, $_ for @$value; |
|
4
|
|
|
|
|
18
|
|
41
|
|
|
|
|
|
|
} else { |
42
|
4
|
|
|
|
|
4
|
push @{$vars{$var}}, $_; |
|
4
|
|
|
|
|
13
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
5
|
return \%vars; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub upmake |
52
|
|
|
|
|
|
|
{ |
53
|
12
|
|
|
12
|
1
|
9095
|
my $file_or_options = shift; |
54
|
12
|
|
|
|
|
28
|
my ($updater, @args) = @_; |
55
|
|
|
|
|
|
|
|
56
|
12
|
|
|
|
|
23
|
my ($fname, $verbose, $quiet, $dryrun); |
57
|
12
|
100
|
|
|
|
35
|
if (ref $file_or_options eq 'HASH') { |
58
|
10
|
|
|
|
|
17
|
$fname = $file_or_options->{file}; |
59
|
10
|
|
|
|
|
13
|
$verbose = $file_or_options->{verbose}; |
60
|
10
|
|
|
|
|
13
|
$quiet = $file_or_options->{quiet}; |
61
|
10
|
|
|
|
|
13
|
$dryrun = $file_or_options->{dryrun}; |
62
|
|
|
|
|
|
|
} else { |
63
|
2
|
|
|
|
|
3
|
$fname = $file_or_options; |
64
|
2
|
|
|
|
|
4
|
$verbose = |
65
|
|
|
|
|
|
|
$quiet = |
66
|
|
|
|
|
|
|
$dryrun = 0; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
12
|
100
|
|
|
|
28
|
if ($dryrun) { |
70
|
2
|
|
|
|
|
4
|
my $old = do { |
71
|
2
|
|
|
|
|
6
|
local $/; |
72
|
2
|
|
|
|
|
6
|
open my $f, '<', $fname; |
73
|
|
|
|
|
|
|
<$f> |
74
|
2
|
|
|
|
|
223
|
}; |
75
|
2
|
|
|
|
|
6
|
my $new = ''; |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
8
|
open my $in, '<', \$old; |
78
|
2
|
|
|
|
|
794
|
open my $out, '>', \$new; |
79
|
|
|
|
|
|
|
|
80
|
2
|
100
|
|
|
|
96
|
if ($updater->($in, $out, @args)) { |
81
|
1
|
|
|
|
|
22
|
print qq{Would update "$fname"}; |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
5
|
if ($verbose) { |
84
|
0
|
0
|
|
|
|
0
|
if (eval { require Text::Diff; }) { |
|
0
|
|
|
|
|
0
|
|
85
|
0
|
|
|
|
|
0
|
print " with the following changes:\n"; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
0
|
print Text::Diff::diff(\$old, \$new, { |
88
|
|
|
|
|
|
|
FILENAME_A => $fname, |
89
|
|
|
|
|
|
|
FILENAME_B => "$fname.new" |
90
|
|
|
|
|
|
|
}); |
91
|
|
|
|
|
|
|
} else { |
92
|
0
|
|
|
|
|
0
|
print ".\n"; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
warn qq{Can't display diff of the changes, please install Text::Diff module.\n}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} else { |
97
|
1
|
|
|
|
|
9
|
print ".\n"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} else { |
100
|
1
|
|
|
|
|
44
|
print qq{Wouldn't change the file "$fname".\n}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
2
|
|
|
|
|
20
|
return 0; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
10
|
|
|
|
|
24
|
my $fname_new = "$fname.upmake.new"; # TODO make it more unique |
107
|
|
|
|
|
|
|
|
108
|
10
|
|
|
|
|
35
|
open my $in, '<', $fname; |
109
|
10
|
|
|
|
|
4478
|
open my $out, '>', $fname_new; |
110
|
|
|
|
|
|
|
|
111
|
10
|
|
|
|
|
1006
|
my $changed = $updater->($in, $out, @args); |
112
|
|
|
|
|
|
|
|
113
|
10
|
|
|
|
|
30
|
close $in; |
114
|
10
|
|
|
|
|
1949
|
close $out; |
115
|
|
|
|
|
|
|
|
116
|
10
|
100
|
|
|
|
571
|
if ($changed) { |
117
|
6
|
|
|
|
|
19
|
rename $fname_new, $fname; |
118
|
|
|
|
|
|
|
} else { |
119
|
4
|
|
|
|
|
14
|
unlink $fname_new; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
10
|
100
|
|
|
|
2314
|
if ($changed) { |
123
|
6
|
100
|
|
|
|
145
|
print qq{File "$fname" successfully updated.\n} unless $quiet; |
124
|
6
|
|
|
|
|
86
|
return 1; |
125
|
|
|
|
|
|
|
} else { |
126
|
4
|
100
|
|
|
|
59
|
print qq{No changes in the file "$fname".\n} if $verbose; |
127
|
4
|
|
|
|
|
33
|
return 0; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |