| 1 | package Makefile::Update; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Update make files. | ||||||||||
| 4 | |||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 4 | ▶ | use Exporter qw(import); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | our @EXPORT = qw(read_files_list upmake); | |||||||||
| 12 | |||||||||||
| 13 | 4 | our $VERSION = '0.2'; # VERSION | |||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | sub read_files_list | ||||||||||
| 18 | { | ||||||||||
| 19 | 1 | ▶ | my ($fh) = @_; | ||||||||
|
Subroutine
read_files_list: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 20 | |||||||||||
| 21 | 1 | my ($var, %vars); | |||||||||
| 22 | 1 | ▶ | while (<$fh>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 10 | chomp; | |||||||||
| 24 | 10 | s/#.*$//; | |||||||||
| 25 | 10 | s/^\s+//; | |||||||||
| 26 | 10 | s/\s+$//; | |||||||||
| 27 | 10 | ▶ | next if !$_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | |||||||||||
| 29 | 6 | ▶ | if (/^(\w+)\s*=$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 2 | $var = $1; | |||||||||
| 31 | } else { | ||||||||||
| 32 | 4 | ▶ | die "Unexpected contents outside variable definition at line $.\n" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | unless defined $var; | ||||||||||
| 34 | 4 | push @{$vars{$var}}, $_; | |||||||||
| 35 | } | ||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 1 | return \%vars; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | sub upmake | ||||||||||
| 43 | { | ||||||||||
| 44 | 0 | ▶ | my ($fname, $updater, @args) = @_; | ||||||||
|
Subroutine
upmake: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 45 | |||||||||||
| 46 | 0 | my $fname_new = "$fname.upmake.new"; # TODO make it more unique | |||||||||
| 47 | |||||||||||
| 48 | 0 | open my $in, '<', $fname; | |||||||||
| 49 | 0 | open my $out, '>', $fname_new; | |||||||||
| 50 | |||||||||||
| 51 | 0 | my $changed = $updater->($in, $out, @args); | |||||||||
| 52 | |||||||||||
| 53 | 0 | close $in; | |||||||||
| 54 | 0 | close $out; | |||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | if ($changed) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | rename $fname_new, $fname; | |||||||||
| 58 | } else { | ||||||||||
| 59 | 0 | unlink $fname_new; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | $changed | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 4 | 1; | |||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||