/
update_copyright.pl
62 lines (48 loc) · 1.4 KB
/
update_copyright.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! perl
# Copyright (C) 2008, Parrot Foundation.
use strict;
use warnings;
use Fatal qw( open close );
=head1 NAME
F<tools/dev/update_copyright.pl>
=head1 DESCRIPTION
Given a list of files as command line arguments, update the copyright
notice to go from the earliest year noted to the current year.
Edits the files in place. You should update the copyright on a modified
file before you commit it back to the repository.
=cut
use lib 'lib';
use Parrot::Test;
# Accept a little fuzz in the original copyright notice..
my $copyright_re = qr/
Copyright \s+ \(C\) \s+
(\d\d\d\d)\s*(?:-\s*\d\d\d\d)? \s* ,? \s*
The \s+ Perl \s+ Foundation\.?
/xi;
my $year = (localtime())[5]+1900;
# loop over all the files specified on the command line
foreach my $file (@ARGV) {
my $contents = Parrot::Test::slurp_file( $file );
if ( $contents =~ $copyright_re) {
my $old_year = $1;
if ($old_year eq $year) {
warn "$file already up to date.\n";
next;
}
else {
$contents =~ s/$copyright_re/Copyright (C) $old_year-$year, Parrot Foundation./;
open my $ofh, '>', $file;
print {$ofh} $contents;
close $ofh;
}
}
else {
warn "$file doesn't have a valid copyright line.\n";
}
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: